Skip to content
Snippets Groups Projects
Commit cc8a4828 authored by ulif's avatar ulif
Browse files

Enable interpolations of booleans in config files.

We have to check for boolean before int, because int is also
a valid boolean.
parent e10e3efb
No related branches found
No related tags found
No related merge requests found
......@@ -73,7 +73,10 @@ def get_config_dict(path_list=None):
conf = dict(parser.items('diceware'))
for key, val in OPTIONS_DEFAULTS.items():
new_val = conf.get(key, val)
if isinstance(val, int):
if isinstance(val, bool):
if not isinstance(new_val, bool):
new_val = parser.getboolean("diceware", key)
elif isinstance(val, int):
new_val = int(new_val)
result[key] = new_val
return result
......
......@@ -67,3 +67,11 @@ class TestConfigModule(object):
conf_dict = get_config_dict()
assert "num" in conf_dict.keys()
assert conf_dict["num"] == 3
def test_get_config_dict_bool(self, home_dir):
# booleabn values are interpolated correctly
config_file = home_dir / ".diceware.ini"
config_file.write("\n".join(["[diceware]", "caps = Off", ""]))
conf_dict = get_config_dict()
assert "caps" in conf_dict.keys()
assert conf_dict["caps"] is False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment