X-Git-Url: https://git.novaco.in/?p=electrum-nvc.git;a=blobdiff_plain;f=lib%2Ftests%2Ftest_simple_config.py;h=f288b7f894eb7410fc632a56b7e9c64d0adc5fec;hp=cee5211885d0c896e5c4393348bd9c06ae6637f1;hb=ad3640d7a4bc4627694df3c277cd83972256c543;hpb=221fa5848f0348bd02586c86a50feb9916c7cea2 diff --git a/lib/tests/test_simple_config.py b/lib/tests/test_simple_config.py index cee5211..f288b7f 100644 --- a/lib/tests/test_simple_config.py +++ b/lib/tests/test_simple_config.py @@ -1,10 +1,11 @@ import sys +import os import unittest import tempfile import shutil from StringIO import StringIO -from lib.simple_config import SimpleConfig +from lib.simple_config import SimpleConfig, read_system_config class Test_SimpleConfig(unittest.TestCase): @@ -132,3 +133,41 @@ 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")) + + +class TestSystemConfig(unittest.TestCase): + + sample_conf = """ +[client] +gap_limit = 5 + +[something_else] +everything = 42 +""" + + def setUp(self): + super(TestSystemConfig, self).setUp() + self.thefile = tempfile.mkstemp(suffix=".electrum.test.conf")[1] + + def tearDown(self): + os.remove(self.thefile) + + def test_read_system_config_file_does_not_exist(self): + somefile = "/foo/I/do/not/exist/electrum.conf" + result = read_system_config(somefile) + self.assertEqual({}, result) + + def test_read_system_config_file_returns_file_options(self): + with open(self.thefile, "w") as f: + f.write(self.sample_conf) + + result = read_system_config(self.thefile) + self.assertEqual({"gap_limit": "5"}, result) + + def test_read_system_config_file_no_sections(self): + + with open(self.thefile, "w") as f: + f.write("gap_limit = 5") # The file has no sections at all + + result = read_system_config(self.thefile) + self.assertEqual({}, result)