diff --git a/diceware/config.py b/diceware/config.py index 5240858c3308754b1ab75971d0a48ba11c8d60c9..691905ccdfa25b924431be6d5ceafa9ecd0957f8 100644 --- a/diceware/config.py +++ b/diceware/config.py @@ -23,6 +23,7 @@ try: import configparser # Python 3.x except ImportError: # pragma: no cover import ConfigParser as configparser # Python 2.x +import os OPTIONS_DEFAULTS = dict( @@ -38,7 +39,11 @@ OPTIONS_DEFAULTS = dict( def valid_locations(): """The list of valid paths we look up for config files. """ - pass + user_home = os.path.expanduser("~") + result = [] + if user_home != "~": + result = [os.path.join(user_home, ".diceware"), ] + return result class DicewareConfigParser(configparser.SafeConfigParser): diff --git a/tests/test_config.py b/tests/test_config.py index 9b29cfa7ec91b505e760d4a52c85e6d57ce04085..bb7b7dbf9fc2e8328908aa052eec3200cb19c464 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,4 +1,4 @@ -from diceware.config import OPTIONS_DEFAULTS +from diceware.config import OPTIONS_DEFAULTS, valid_locations class TestConfigModule(object): @@ -7,3 +7,12 @@ class TestConfigModule(object): def test_defaults(self): # there is a set of defaults for options available assert OPTIONS_DEFAULTS is not None + + def test_valid_locations(self, tmpdir, monkeypatch): + # we look for config files in user home and local dir + new_home = tmpdir / "home" + new_home.ensure_dir() + monkeypatch.setenv("HOME", str(new_home)) + assert valid_locations() == [ + str(new_home / ".diceware") + ]