diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_config.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index c0a9ac4..6fa8619 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -76,6 +76,35 @@ class TestConfig(unittest.TestCase): config.load(path) self.assertNotIsInstance(caught.exception, config.NotConfigured) + def test_an_empty_cases_value_falls_back_to_the_default(self): + # Empty is the same as absent, per this module's own rule: writing + # Path("") would put evidence in whatever directory the command + # happened to run from. + path = self._write( + '[general]\ntrusted_relays = ["192.0.2.0/24"]\ncases = ""\n' + ) + self.assertEqual(config.load(path).cases, config.DEFAULT_CASES) + + def test_a_whitespace_cases_value_falls_back_to_the_default(self): + path = self._write( + '[general]\ntrusted_relays = ["192.0.2.0/24"]\ncases = " "\n' + ) + self.assertEqual(config.load(path).cases, config.DEFAULT_CASES) + + def test_a_string_trusted_relays_is_rejected_clearly(self): + # Easy to write by hand without the brackets. Iterating the string + # validates single characters and reports an error naming nothing + # the user can find in their file. + path = self._write('[general]\ntrusted_relays = "192.0.2.0/24"\n') + with self.assertRaises(ValueError) as caught: + config.load(path) + self.assertIn("must be a list", str(caught.exception)) + + def test_a_relay_entry_that_is_not_a_string_is_rejected_clearly(self): + path = self._write("[general]\ntrusted_relays = [42]\n") + with self.assertRaises(ValueError): + config.load(path) + def test_the_config_path_follows_xdg_config_home(self): with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/tmp/xdg-probe"}): self.assertEqual( |
