def test_setdefault_defaulting(self): conf = Config() conf.add_section("foo") self.failUnlessEqual(None, conf.get("foo", "bar", None)) conf.setdefault("foo", "bar", "xxx") self.failUnlessEqual("xxx", conf.get("foo", "bar"))
def test_setdefault_defaulting(self): conf = Config() conf.add_section("foo") self.failUnlessEqual(None, conf.get("foo", "bar", None)) conf.setdefault("foo", "bar", "xxx") self.failUnlessEqual("xxx", conf.get("foo", "bar"))
def test_setlist(self): conf = Config() conf.add_section("foo") conf.setlist("foo", "bar", [" a", ",", "c"]) self.assertEqual(conf.getlist("foo", "bar"), [" a", ",", "c"]) self.assertEqual(conf.get("foo", "bar"), " a,\\,,c") conf.setlist("foo", "bar", [" a", ",", "c"], sep=":") self.assertEqual(conf.get("foo", "bar"), " a:,:c")
def test_reset(self): conf = Config() conf.defaults.add_section("player") conf.defaults.set("player", "backend", "blah") conf.set("player", "backend", "foo") self.assertEqual(conf.get("player", "backend"), "foo") conf.reset("player", "backend") self.assertEqual(conf.get("player", "backend"), "blah")
def test_reset(self): conf = Config() conf.defaults.add_section("player") conf.defaults.set("player", "backend", "blah") conf.set("player", "backend", "foo") self.assertEqual(conf.get("player", "backend"), "foo") conf.reset("player", "backend") self.assertEqual(conf.get("player", "backend"), "blah")
def test_setlist(self): conf = Config() conf.add_section("foo") conf.setlist("foo", "bar", [" a", ",", "c"]) self.assertEqual(conf.getlist("foo", "bar"), [" a", ",", "c"]) self.assertEqual(conf.get("foo", "bar"), " a,\\,,c") conf.setlist("foo", "bar", [" a", ",", "c"], sep=":") self.assertEqual(conf.get("foo", "bar"), " a:,:c")
def test_initial_after_set(self): conf = Config() conf.add_section("player") conf.set("player", "backend", "orig") conf.defaults.set("player", "backend", "initial") self.assertEqual(conf.get("player", "backend"), "orig") self.assertEqual(conf.defaults.get("player", "backend"), "initial") conf.reset("player", "backend") self.assertEqual(conf.get("player", "backend"), "initial")
def test_initial_after_set(self): conf = Config() conf.add_section("player") conf.set("player", "backend", "orig") conf.defaults.set("player", "backend", "initial") self.assertEqual(conf.get("player", "backend"), "orig") self.assertEqual(conf.defaults.get("player", "backend"), "initial") conf.reset("player", "backend") self.assertEqual(conf.get("player", "backend"), "initial")
def test_stringlist_mixed(self): conf = Config() conf.add_section("foo") self.failIf(conf.get("foo", "bar", None)) conf.setstringlist("foo", "bar", ["one", 2]) self.failUnlessEqual(conf.getstringlist("foo", "bar"), ["one", "2"])
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_get_fallback_default(self): conf = Config() conf.defaults.add_section("get") self.assertRaises(Error, conf.get, "get", "bar") conf.defaults.set("get", "bar", 1) self.assertEqual(conf.get("get", "bar"), "1") conf.defaults.add_section("getboolean") self.assertRaises(Error, conf.getboolean, "getboolean", "bar") conf.defaults.set("getboolean", "bar", True) self.assertEqual(conf.getboolean("getboolean", "bar"), True) conf.defaults.add_section("getfloat") self.assertRaises(Error, conf.getfloat, "getfloat", "bar") conf.defaults.set("getfloat", "bar", 1.0) self.assertEqual(conf.getfloat("getfloat", "bar"), 1.0) conf.defaults.add_section("getint") self.assertRaises(Error, conf.getint, "getint", "bar") conf.defaults.set("getint", "bar", 42) self.assertEqual(conf.getint("getint", "bar"), 42) conf.defaults.add_section("getlist") self.assertRaises(Error, conf.getlist, "getlist", "bar") conf.defaults.setlist("getlist", "bar", [1, 2, 3]) self.assertEqual(conf.getlist("getlist", "bar"), ["1", "2", "3"])
def test_stringlist_mixed(self): conf = Config() conf.add_section("foo") self.failIf(conf.get("foo", "bar", None)) conf.setstringlist("foo", "bar", ["one", 2]) self.failUnlessEqual(conf.getstringlist("foo", "bar"), ["one", "2"])
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_get_fallback_default(self): conf = Config() conf.defaults.add_section("get") self.assertRaises(Error, conf.get, "get", "bar") conf.defaults.set("get", "bar", 1) self.assertEqual(conf.get("get", "bar"), "1") conf.defaults.add_section("getboolean") self.assertRaises(Error, conf.getboolean, "getboolean", "bar") conf.defaults.set("getboolean", "bar", True) self.assertEqual(conf.getboolean("getboolean", "bar"), True) conf.defaults.add_section("getfloat") self.assertRaises(Error, conf.getfloat, "getfloat", "bar") conf.defaults.set("getfloat", "bar", 1.0) self.assertEqual(conf.getfloat("getfloat", "bar"), 1.0) conf.defaults.add_section("getint") self.assertRaises(Error, conf.getint, "getint", "bar") conf.defaults.set("getint", "bar", 42) self.assertEqual(conf.getint("getint", "bar"), 42) conf.defaults.add_section("getlist") self.assertRaises(Error, conf.getlist, "getlist", "bar") conf.defaults.setlist("getlist", "bar", [1, 2, 3]) self.assertEqual(conf.getlist("getlist", "bar"), ["1", "2", "3"])
def test_stringlist_quoting(self): conf = Config() conf.add_section("foo") self.failIf(conf.get("foo", "bar", None)) vals = ["foo's gold", "bar, \"best\" 'ever'", u"le goût d'œufs à Noël"] conf.setstringlist("foo", "bar", vals) self.failUnlessEqual(conf.getstringlist("foo", "bar"), vals)
def test_stringlist_simple(self): conf = Config() conf.add_section("foo") self.failIf(conf.get("foo", "bar", None)) vals = ["one", "two", "three"] conf.setstringlist("foo", "bar", vals) self.failUnlessEqual(conf.getstringlist("foo", "bar"), vals)
def test_get_default(self): conf = Config() conf.add_section("foo") self.failUnlessEqual(conf.getboolean("foo", "nothing", True), True) self.failUnlessEqual(conf.getint("foo", "nothing", 42), 42) self.failUnlessEqual(conf.getfloat("foo", "nothing", 42.42), 42.42) self.failUnlessEqual(conf.get("foo", "nothing", "foo"), "foo")
def test_get_default(self): conf = Config() conf.add_section("foo") self.failUnlessEqual(conf.getboolean("foo", "nothing", True), True) self.failUnlessEqual(conf.getint("foo", "nothing", 42), 42) self.failUnlessEqual(conf.getfloat("foo", "nothing", 42.42), 42.42) self.failUnlessEqual(conf.get("foo", "nothing", "foo"), "foo")
def test_stringlist_simple(self): conf = Config() conf.add_section("foo") self.failIf(conf.get("foo", "bar", None)) vals = ["one", "two", "three"] conf.setstringlist("foo", "bar", vals) self.failUnlessEqual(conf.getstringlist("foo", "bar"), vals)
def test_stringlist_quoting(self): conf = Config() conf.add_section("foo") self.failIf(conf.get("foo", "bar", None)) vals = ["foo's gold", "bar, \"best\" 'ever'", u"le goût d'œufs à Noël"] conf.setstringlist("foo", "bar", vals) self.failUnlessEqual(conf.getstringlist("foo", "bar"), vals)
def test_get(self): conf = Config() conf.add_section("foo") conf.set("foo", "int", "1") conf.set("foo", "float", "1.25") conf.set("foo", "str", "foobar") conf.set("foo", "bool", "True") self.failUnlessEqual(conf.getint("foo", "int"), 1) self.failUnlessEqual(conf.getfloat("foo", "float"), 1.25) self.failUnlessEqual(conf.get("foo", "str"), "foobar") self.failUnlessEqual(conf.getboolean("foo", "bool"), True)
def test_get(self): conf = Config() conf.add_section("foo") conf.set("foo", "int", "1") conf.set("foo", "float", "1.25") conf.set("foo", "str", "foobar") conf.set("foo", "bool", "True") self.failUnlessEqual(conf.getint("foo", "int"), 1) self.failUnlessEqual(conf.getfloat("foo", "float"), 1.25) self.failUnlessEqual(conf.get("foo", "str"), "foobar") self.failUnlessEqual(conf.getboolean("foo", "bool"), True)
def test_reset_no_section(self): conf = Config() conf.defaults.add_section("player") conf.defaults.set("player", "backend", "blah") conf.reset("player", "backend") assert conf.get("player", "backend") == "blah"
def test_set(self): conf = Config() conf.add_section("foo") conf.set("foo", "bar", 1) self.failUnlessEqual(conf.get("foo", "bar"), "1") self.failUnlessEqual(conf.getint("foo", "bar"), 1)
def test_reset_no_section(self): conf = Config() conf.defaults.add_section("player") conf.defaults.set("player", "backend", "blah") conf.reset("player", "backend") assert conf.get("player", "backend") == "blah"
def test_set(self): conf = Config() conf.add_section("foo") conf.set("foo", "bar", 1) self.failUnlessEqual(conf.get("foo", "bar"), "1") self.failUnlessEqual(conf.getint("foo", "bar"), 1)