def get_config_version_mismatch(self) -> bool: """ TODO: Docu """ cfg1 = Config("config/easywall.sample.ini") cfg2 = Config("config/easywall.ini") for section in cfg1.get_sections(): if section not in cfg2.get_sections(): return True for key in cfg1.get_keys(section): if key not in cfg2.get_keys(section): return True return False
def get_config_version_mismatch(self, cfgtype: str) -> bool: """TODO: Doku.""" if cfgtype == "core": cfg1 = Config("config/easywall.sample.ini") cfg2 = Config("config/easywall.ini") elif cfgtype == "web": cfg1 = Config("config/web.sample.ini") cfg2 = Config("config/web.ini") for section in cfg1.get_sections(): if section not in cfg2.get_sections(): return True for key in cfg1.get_keys(section): if key not in cfg2.get_keys(section): return True return False
class TestConfig(unittest.TestCase): """ this class contains all test functions for the config module """ def setUp(self): content = """[TEST] teststring = string testboolean = true testint = 1 testfloat = 1.1 """ create_file_if_not_exists("test.ini") write_into_file("test.ini", content) self.config = Config("test.ini") def tearDown(self): delete_file_if_exists("test.ini") def test_get_value_error(self): self.assertEqual(self.config.get_value("TEST", "notexistent"), "") def test_get_value_bool(self): self.assertEqual(self.config.get_value("TEST", "testboolean"), True) def test_get_value_int(self): self.assertEqual(self.config.get_value("TEST", "testint"), 1) def test_get_value_float(self): self.assertEqual(self.config.get_value("TEST", "testfloat"), float(1.1)) def test_get_sections(self): self.assertIn("TEST", self.config.get_sections()) def test_set_value_success(self): self.assertEqual(self.config.set_value("TEST", "teststring", "erfolg"), True) def test_set_value_fail_section(self): self.assertEqual(self.config.set_value("TEST2", "asd", "asd"), False)
class TestConfig(unittest.TestCase): """ TODO: Doku """ def setUp(self) -> None: content = """[TEST] teststring = string testboolean = true testint = 1 testfloat = 1.1 """ create_file_if_not_exists("test.ini") write_into_file("test.ini", content) self.config = Config("test.ini") def tearDown(self) -> None: delete_file_if_exists("test.ini") def test_constructor_file_not_found(self) -> None: """ TODO: Doku """ with self.assertRaises(FileNotFoundError): Config("test2.ini") def test_constructor_file_not_read(self) -> None: """ TODO: Doku """ create_file_if_not_exists("test.ini") content = """[DEFAULT] goodcontent = test badcontent """ write_into_file("test.ini", content) with self.assertRaises(ParsingError): Config("test.ini") def test_get_value_error(self) -> None: """ TODO: Doku """ self.assertEqual(self.config.get_value("TEST", "notexistent"), "") def test_get_value_bool(self) -> None: """ TODO: Doku """ self.assertEqual(self.config.get_value("TEST", "testboolean"), True) def test_get_value_int(self) -> None: """ TODO: Doku """ self.assertEqual(self.config.get_value("TEST", "testint"), 1) def test_get_value_float(self) -> None: """ TODO: Doku """ self.assertEqual(self.config.get_value( "TEST", "testfloat"), float(1.1)) def test_get_sections(self) -> None: """ TODO: Doku """ self.assertIn("TEST", self.config.get_sections()) def test_set_value_success(self) -> None: """ TODO: Doku """ self.assertEqual(self.config.set_value( "TEST", "teststring", "erfolg"), True) def test_set_value_fail_section(self) -> None: """ TODO: Doku """ self.assertEqual(self.config.set_value("TEST2", "asd", "asd"), False)