From 20989bbc4f57e6a45f5221d3af73f3878dae6bc6 Mon Sep 17 00:00:00 2001 From: ulif <uli@gnufix.de> Date: Mon, 9 Nov 2015 15:38:57 +0100 Subject: [PATCH] Add test and real implementation for valid_locations. Right now we consider a file ".diceware" in the users home as only valid place for a diceware config file. --- diceware/config.py | 7 ++++++- tests/test_config.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/diceware/config.py b/diceware/config.py index 5240858..691905c 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 9b29cfa..bb7b7db 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") + ] -- GitLab