From 5eeae69425b8b12381309c88c20f3508d628557f Mon Sep 17 00:00:00 2001 From: Chris Glass Date: Wed, 25 Jun 2014 18:04:37 +0200 Subject: [PATCH] Added more tests for edge cases. --- lib/simple_config.py | 1 - lib/tests/test_simple_config.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/simple_config.py b/lib/simple_config.py index c90a737..b4455bb 100644 --- a/lib/simple_config.py +++ b/lib/simple_config.py @@ -83,7 +83,6 @@ class SimpleConfig(object): set_config(self) # Make a singleton instance of 'self' def init_path(self): - # Read electrum path in the command line configuration self.path = self.current_options.get('electrum_path') diff --git a/lib/tests/test_simple_config.py b/lib/tests/test_simple_config.py index 8704838..cee5211 100644 --- a/lib/tests/test_simple_config.py +++ b/lib/tests/test_simple_config.py @@ -57,9 +57,22 @@ class Test_SimpleConfig(unittest.TestCase): self.assertEqual(self.options.get("electrum_path"), config.get("electrum_path")) + def test_simple_config_system_config_ignored_if_portable(self): + """If electrum is started with the "portable" flag, system + configuration is completely ignored.""" + another_path = tempfile.mkdtemp() + fake_read_system = lambda : {"electrum_path": self.electrum_dir} + fake_read_user = lambda _: {"electrum_path": another_path} + read_user_dir = lambda : self.user_dir + config = SimpleConfig(options={"portable": True}, + read_system_config_function=fake_read_system, + read_user_config_function=fake_read_user, + read_user_dir_function=read_user_dir) + self.assertEqual(another_path, config.get("electrum_path")) + def test_simple_config_user_config_is_used_if_others_arent_specified(self): - """Options passed by command line override all other configuration - sources""" + """If no system-wide configuration and no command-line options are + specified, the user configuration is used instead.""" fake_read_system = lambda : {} fake_read_user = lambda _: {"electrum_path": self.electrum_dir} read_user_dir = lambda : self.user_dir @@ -105,3 +118,17 @@ class Test_SimpleConfig(unittest.TestCase): read_user_dir_function=read_user_dir) config.set_key("electrum_path", another_path) self.assertEqual(another_path, config.get("electrum_path")) + + def test_can_set_options_from_system_config_if_portable(self): + """If the "portable" flag is set, the user can overwrite system + configuration options.""" + another_path = tempfile.mkdtemp() + fake_read_system = lambda : {"electrum_path": self.electrum_dir} + fake_read_user = lambda _: {} + read_user_dir = lambda : self.user_dir + config = SimpleConfig(options={"portable": True}, + read_system_config_function=fake_read_system, + read_user_config_function=fake_read_user, + read_user_dir_function=read_user_dir) + config.set_key("electrum_path", another_path) + self.assertEqual(another_path, config.get("electrum_path")) -- 1.7.1