summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJulian Mehne <julian.mehne@posteo.de>2018-01-21 19:08:19 +0100
committerJulian Mehne <julian.mehne@posteo.de>2018-01-21 20:10:09 +0100
commit0935ccfd5c8cd00dd7b55a06133c6b5cf6368668 (patch)
treef6278deddadc2813a226f818eeb3c61f154a0daf /tests
parent6f1a8b687dde23458b141c36f3044cf10fa008af (diff)
Fix empty XDG_* environment variables.
Use fallback, if an enviroment variable is unset *or* empty. Bug: - XDG_CONFIG_HOME='' alot Problem: Does not find the configuration file (among others), because os.environ.get('XDG_CONFIG_HOME', '~/.config') returns '', instead of '~/.config'.
Diffstat (limited to 'tests')
-rw-r--r--tests/helper_test.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/helper_test.py b/tests/helper_test.py
index c2927725..02105a29 100644
--- a/tests/helper_test.py
+++ b/tests/helper_test.py
@@ -464,3 +464,29 @@ class TestCallCmdAsync(unittest.TestCase):
yield helper.call_cmd_async(['_____better_not_exist'])
self.assertEqual(cm.exception.exitCode, 1)
self.assertTrue(cm.exception.stderr)
+
+
+class TestGetEnv(unittest.TestCase):
+ env_name = 'XDG_CONFIG_HOME'
+ default = '~/.config'
+
+ def test_env_not_set(self):
+ with mock.patch.dict('os.environ'):
+ if self.env_name in os.environ:
+ del os.environ[self.env_name]
+ self.assertEqual(helper.get_env(self.env_name, self.default),
+ self.default)
+
+ def test_env_empty(self):
+ with mock.patch.dict('os.environ'):
+ os.environ[self.env_name] = ''
+ self.assertEqual(helper.get_env(self.env_name, self.default),
+ self.default)
+
+ def test_env_not_empty(self):
+ custom_path = '/my/personal/config/home'
+
+ with mock.patch.dict('os.environ'):
+ os.environ[self.env_name] = custom_path
+ self.assertEqual(helper.get_env(self.env_name, self.default),
+ custom_path)