class ConfigUnitTestLoadIni(unittest.TestCase): def setUp(self): self.config = Config("fixtures/config1.ini") def test_init_parse(self): "It parses the given .ini file using a ConfigParser" self.assertEqual(self.config._parser.__class__, ConfigParser) def test_parser_read(self): "The parser reads the file correctly" ini_value = self.config._parser.get("Global", "db_name") self.assertEqual("mysql", ini_value) def test_get_value(self): "It loads the values of the config file as properties." self.assertEqual("mysql", self.config.Global.db_name) def test_get_value_ci(self): "Values are available through case insensitive names" self.assertEqual("mysql", self.config.Global.DB_NAME) def test_get_global(self): "It loads the [Global] variables into the object namespace." self.assertEqual(self.config.db_name, "mysql") def test_boolean_inference(self): "It inferes yes/no and true/false strings as boolean values." self.assertEqual(True, self.config.SectionA.boolean_true) self.assertEqual(True, self.config.SectionA.boolean_true2) self.assertEqual(True, self.config.SectionA.boolean_true3) self.assertEqual(False, self.config.SectionA.boolean_false) self.assertEqual(False, self.config.SectionA.boolean_false2) self.assertEqual(False, self.config.SectionA.boolean_false3) def test_number_inference(self): "It automatically casts integers and floats to their respective types" self.assertEqual(42, self.config.SectionA.fourty_two) self.assertEqual(42.0, self.config.SectionA.fourty_two_zero) def test_is_self(self): "It tells whether a variable is set or not" self.assertEqual(True, self.config.is_set("db_name")) self.assertEqual(False, self.config.is_set("pony"))
def test_modified_set_as_global_var(self): """Reproduce BUG: the `modified` attribute gets set as a config var.""" config = Config("fixtures/config1.ini") config.var = "value" self.assertFalse(config.is_set("modified"))
def test_autosave_set_as_global_var(self): """Reproduce BUG: the `_autosave` attribute get set as a global config va.""" config = Config("fixtures/config1.ini") config.autosave("autosaved.ini") self.assertFalse(config.is_set("_autosave"))
def test_modified_set_as_global_var(self): config = Config("fixtures/config1.ini") config.var = "value" self.assertFalse(config.is_set("modified"))