def test_config_requires(self): c = Component() self.assertEquals(c.config_requires("example", "hello"), "hello", "config_requires returns value if not None") self.assertRaises( Exception, c.config_requires, "example", None, "config_requires raises an Exception if value is None")
def test_title(self): c = Component() self.assertEquals(c.title, "component", "Component.title has a default") c._title = "TestComponent" self.assertEquals(c.title, "TestComponent", "Component.title can be set")
def test_config_bool (self): c = Component() self.assertTrue(c.config_bool("true"), "config_bool accepts true") self.assertTrue(c.config_bool("True"), "config_bool accepts True") self.assertTrue(c.config_bool("yes"), "config_bool accepts yes") self.assertTrue(c.config_bool("YES"), "config_bool accepts YES") self.assertFalse(c.config_bool("false"), "config_bool accepts false") self.assertFalse(c.config_bool("no"), "config_bool accepts no")
def test_config_list(self): c = Component() self.assertEquals(c.config_list("a,b,c"), ["a", "b", "c"], "config_list parses str") self.assertEquals(c.config_list(["a", "b"]), ["a", "b"], "config_list copies list") self.assertEquals(c.config_list("a"), ["a"], "config_list creates len-1 list")
def test_write (self): log = Logger("debug", self.tmp.name, "%(levelname)s [%(component)s]: %(message)s", False) c = Component() c._title = "Testing" log.write(c, "debug", "this is a debug message: %d", 1) log.write(c, "info", "this is a info message: %d", 2) log.write(c, "warning", "this is a warning message: %d", 3) log.write(c, "error", "this is a error message: %d", 4) log.write(c, "critical", "this is a critical message: %d", 5) self.tmp.flush() self.tmp.seek(0) output = self.tmp.read() self.assertEquals(output, expected_output.lstrip(), "got expected output")
def test_write(self): log = Logger("debug", self.tmp.name, "%(levelname)s [%(component)s]: %(message)s", False) c = Component() c._title = "Testing" log.write(c, "debug", "this is a debug message: %d", 1) log.write(c, "info", "this is a info message: %d", 2) log.write(c, "warning", "this is a warning message: %d", 3) log.write(c, "error", "this is a error message: %d", 4) log.write(c, "critical", "this is a critical message: %d", 5) self.tmp.flush() self.tmp.seek(0) output = self.tmp.read() self.assertEquals(output, expected_output.lstrip(), "got expected output")
def test_config_bool(self): c = Component() self.assertTrue(c.config_bool("true"), "config_bool accepts true") self.assertTrue(c.config_bool("True"), "config_bool accepts True") self.assertTrue(c.config_bool("yes"), "config_bool accepts yes") self.assertTrue(c.config_bool("YES"), "config_bool accepts YES") self.assertFalse(c.config_bool("false"), "config_bool accepts false") self.assertFalse(c.config_bool("no"), "config_bool accepts no")
def test_config_requires(self): c = Component() self.assertEquals(c.config_requires("example", "hello"), "hello", "config_requires returns value if not None") self.assertRaises(Exception, c.config_requires, "example", None, "config_requires raises an Exception if value is None")
def test_config_list (self): c = Component() self.assertEquals(c.config_list("a,b,c"),["a","b","c"], "config_list parses str") self.assertEquals(c.config_list(["a","b"]),["a","b"], "config_list copies list") self.assertEquals(c.config_list("a"),["a"], "config_list creates len-1 list")
def test_router(self): c = Component() self.assertEquals(c.router, None, "no router set yet") c._router = "(router)" self.assertEquals(c.router, "(router)", "router can be set")
def test_name(self): c = Component() self.assertEquals(c.name, "Component", "Component.name has a default") c.name = "TestComponent" self.assertEquals(c.name, "TestComponent", "Component.name can be set")