From 5fa867ba5a2e0927e9b87a8228989357924623d2 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 9 Feb 2020 13:54:09 -0600 Subject: Allow a default value for the get() method --- tests/test_config_file.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'tests') 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( -- cgit v1.2.3