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_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_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_invalid_data(self): conf = Config() conf.add_section("foo") conf.set("foo", "bla", "xx;,,;\n\n\naa") self.assertTrue(conf.getboolean("foo", "bla", True)) self.assertEqual(conf.getint("foo", "bla", 42), 42) self.assertEqual(conf.getfloat("foo", "bla", 1.5), 1.5) self.assertEqual(conf.getstringlist("foo", "bla", ["baz"]), ["baz"])
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_invalid_data(self): conf = Config() conf.add_section("foo") conf.set("foo", "bla", "xx;,,;\n\n\naa") self.assertTrue(conf.getboolean("foo", "bla", True)) self.assertEqual(conf.getint("foo", "bla", 42), 42) self.assertEqual(conf.getfloat("foo", "bla", 1.5), 1.5) self.assertEqual(conf.getstringlist("foo", "bla", ["baz"]), ["baz"])
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)