aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_config_file.py
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-02-09 20:47:13 -0600
committerEugene Triguba <eugenetriguba@gmail.com>2020-02-09 20:47:13 -0600
commit74048486b37cda4dc9a252ed1415b6e136f65186 (patch)
tree705815f5dbb7f89cb1435e748b6407beac299dcc /tests/test_config_file.py
parentMerge branch 'master' of github.com:eugenetriguba/config_file (diff)
downloadconfig-file-74048486b37cda4dc9a252ed1415b6e136f65186.zip
Add default + return_type param to get(), turn off automatic parsing
Diffstat (limited to 'tests/test_config_file.py')
-rw-r--r--tests/test_config_file.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/tests/test_config_file.py b/tests/test_config_file.py
index 24b948b..f083538 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, default, file_name, file_contents",
+ "section_key, value, parse_type, return_type, default, file_name, file_contents",
[
(
"calendar.sunday_index",
0,
True,
+ None,
False,
"config.ini",
"[calendar]\nsunday_index = 0\n\n",
@@ -90,6 +91,7 @@ def test_that_config_file_can_save(tmpdir, file_contents, file_name):
"calendar.sunday_index",
"0",
False,
+ None,
False,
"config.ini",
"[calendar]\nsunday_index = 0\n\n",
@@ -98,6 +100,7 @@ def test_that_config_file_can_save(tmpdir, file_contents, file_name):
"calendar.sunday_index",
0,
False,
+ None,
False,
"config.json",
json.dumps({"calendar": {"sunday_index": 0}}),
@@ -106,19 +109,41 @@ def test_that_config_file_can_save(tmpdir, file_contents, file_name):
"calendar.missing",
"my default value",
False,
+ None,
"my default value",
"config.json",
json.dumps({"calendar": 5}),
),
+ (
+ "calendar.sunday_index",
+ 0,
+ False,
+ int,
+ False,
+ "config.ini",
+ "[calendar]\nsunday_index = 0\n\n",
+ ),
],
)
def test_that_config_file_can_get(
- tmpdir, section_key, value, parse_type, file_name, file_contents, default
+ tmpdir,
+ section_key,
+ value,
+ return_type,
+ 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, default=default) == value
+
+ ret_val = config.get(section_key, parse_types=parse_type, default=default)
+ if return_type is not None:
+ assert return_type(ret_val) == value
+ else:
+ assert ret_val == value
@pytest.mark.parametrize(
@@ -183,7 +208,7 @@ def test_that_custom_parser_can_be_used(tmpdir):
def __init__(self, file_contents):
super().__init__(file_contents)
- def get(self, key, parse_type=True):
+ def get(self, key, parse_types=True):
return key
def set(self, key, value):