diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-02-09 13:54:09 -0600 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-02-09 13:54:09 -0600 |
| commit | 5fa867ba5a2e0927e9b87a8228989357924623d2 (patch) | |
| tree | 76f298bf573a7d8839562e910874688c992029b7 /tests | |
| parent | Add requests to tox (diff) | |
| download | config-file-5fa867ba5a2e0927e9b87a8228989357924623d2.zip | |
Allow a default value for the get() method
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_config_file.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tests/test_config_file.py b/tests/test_config_file.py index f57bd69..24b948b 100644 --- a/tests/test_config_file.py +++ b/tests/test_config_file.py @@ -76,12 +76,13 @@ def test_that_config_file_can_save(tmpdir, file_contents, file_name): @pytest.mark.parametrize( - "section_key, value, parse_type, file_name, file_contents", + "section_key, value, parse_type, default, file_name, file_contents", [ ( "calendar.sunday_index", 0, True, + False, "config.ini", "[calendar]\nsunday_index = 0\n\n", ), @@ -89,6 +90,7 @@ def test_that_config_file_can_save(tmpdir, file_contents, file_name): "calendar.sunday_index", "0", False, + False, "config.ini", "[calendar]\nsunday_index = 0\n\n", ), @@ -96,18 +98,27 @@ def test_that_config_file_can_save(tmpdir, file_contents, file_name): "calendar.sunday_index", 0, False, + False, "config.json", json.dumps({"calendar": {"sunday_index": 0}}), ), + ( + "calendar.missing", + "my default value", + False, + "my default value", + "config.json", + json.dumps({"calendar": 5}), + ), ], ) def test_that_config_file_can_get( - tmpdir, section_key, value, parse_type, file_name, file_contents + tmpdir, section_key, value, parse_type, file_name, file_contents, default ): config_path = tmpdir / file_name config_path.write_text(file_contents, encoding="utf-8") config = ConfigFile(str(config_path)) - assert config.get(section_key, parse_type=parse_type) == value + assert config.get(section_key, parse_type=parse_type, default=default) == value @pytest.mark.parametrize( |