def test_versioning(self): with temp_filename() as filename: conf = Config(version=41) conf.add_section("foo") conf.set("foo", "bar", "quux") conf.write(filename) self.assertRaises(Error, conf.get_version) # old was 41, we have 42, so upgrade def func(config, old, new): if old < 42: config.set("foo", "bar", "nope") conf = Config(version=42) conf.register_upgrade_function(func) conf.read(filename) self.assertEqual(conf.get_version(), 41) self.assertEqual(conf.get("foo", "bar"), "nope") # write doesn't change version conf.write(filename) self.assertEqual(conf.get_version(), 41) # but if we load again, it does conf.read(filename) self.assertEqual(conf.get_version(), 42)
def test_versioning(self): with temp_filename() as filename: conf = Config(version=41) conf.add_section("foo") conf.set("foo", "bar", "quux") conf.write(filename) self.assertRaises(Error, conf.get_version) # old was 41, we have 42, so upgrade def func(config, old, new): if old < 42: config.set("foo", "bar", "nope") conf = Config(version=42) conf.register_upgrade_function(func) conf.read(filename) self.assertEqual(conf.get_version(), 41) self.assertEqual(conf.get("foo", "bar"), "nope") # write doesn't change version conf.write(filename) self.assertEqual(conf.get_version(), 41) # but if we load again, it does conf.read(filename) self.assertEqual(conf.get_version(), 42)
def test_versioning_upgrade_func(self): called = [] with temp_filename() as filename: conf = Config(version=0) def func(*args): called.append(args) conf.register_upgrade_function(func) self.assertRaises(Error, conf.get_version) conf.read(filename) self.assertEqual(conf.get_version(), -1) conf.register_upgrade_function(func) self.assertEqual([(conf, -1, 0), (conf, -1, 0)], called)
def test_versioning_upgrade_func(self): called = [] with temp_filename() as filename: conf = Config(version=0) def func(*args): called.append(args) conf.register_upgrade_function(func) self.assertRaises(Error, conf.get_version) conf.read(filename) self.assertEqual(conf.get_version(), -1) conf.register_upgrade_function(func) self.assertEqual([(conf, -1, 0), (conf, -1, 0)], called)