Skip to content
Snippets Groups Projects
Commit 5ca58b56 authored by dwcoder's avatar dwcoder
Browse files

Fix issue 23

This commit fixes #23

Add the `string.strip()` function to the `get_config_dict()`, to remove
inverted commas around string values in the diceware.ini file.
The strip removes both `"` and `'`.
Add unit test to ensure the line:

    delimiter=" "

in the diceware.ini file is being parsed correctly as a space.
parent f8f12a00
No related branches found
No related tags found
No related merge requests found
...@@ -82,5 +82,5 @@ def get_config_dict(path_list=None): ...@@ -82,5 +82,5 @@ def get_config_dict(path_list=None):
elif isinstance(val, int): elif isinstance(val, int):
result[key] = parser.getint("diceware", key) result[key] = parser.getint("diceware", key)
else: else:
result[key] = parser.get("diceware", key) result[key] = parser.get("diceware", key).strip("\"'")
return result return result
...@@ -101,6 +101,22 @@ class TestConfigModule(object): ...@@ -101,6 +101,22 @@ class TestConfigModule(object):
conf_dict = get_config_dict() conf_dict = get_config_dict()
assert conf_dict["delimiter"] == "" assert conf_dict["delimiter"] == ""
def test_get_config_dict_string_space(self, home_dir):
# We test for the following three cases of whitespace delimiter
# delimiter=" "
# delimiter=' '
# delimiter=" " (two spaces)
config_file = home_dir / ".diceware.ini"
config_file.write("\n".join(["[diceware]", "delimiter=\" \""]))
conf_dict = get_config_dict()
assert conf_dict["delimiter"] == " "
config_file.write("\n".join(["[diceware]", "delimiter=' '"]))
conf_dict = get_config_dict()
assert conf_dict["delimiter"] == " "
config_file.write("\n".join(["[diceware]", "delimiter=\" \""]))
conf_dict = get_config_dict()
assert conf_dict["delimiter"] == " "
class TestSampleIni(object): class TestSampleIni(object):
# test local sample ini file # test local sample ini file
......
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