def test_walk_nodes(self): files = [ "blog/index.html", "blog/post.html", "index.html", "style.css", ] dirs = ["blog"] with TemporaryDirectory() as deploy, TemporaryDirectory() as content: settings = Config({"deploy_path": deploy, "content_path": content}) for d in dirs: pathlib.Path(content, d).mkdir() for f in files: pathlib.Path(content, f).touch() gen(settings) for item in files + dirs: with self.subTest("%s exists in %s" % (item, deploy)): self.assertTrue(pathlib.Path(deploy, item).exists())
def test_no_load(self): settings = Config() self.assertEqual(len(settings), 0)
def test_load_AssertionError(self): # raise an AssertionError if it's not a dict or file-like object with self.assertRaises(AssertionError): Config(12)
def test_load_str(self): settings = Config(YAML_DATA) self.assertEqual(len(settings), 2) self.assertEqual(settings["sitename"], "bob") self.assertEqual(settings["thingy"], ["one", "two", "three"])
def test_repr(self): settings = Config({}) # just a smoke test to make sure it doesn't blow up self.assertTrue(isinstance(repr(settings), str)) self.assertTrue(repr(settings))
def test_get_name_for_node_config(self): node = mock.Mock() node.full_path = "this-file.html" config = Config({}, parent=mock.Mock(), node=node) self.assertEqual(config.get_name(), node.full_path)
def test_get_name_for_root_config(self): config = Config({}) self.assertEqual(config.get_name(), SITE_YAML_PATH)
def test_len_with_parent(self): parent = Config({"test": True}) settings = Config(YAML_DATA, parent=parent, node=mock.Mock()) self.assertEqual(len(settings), 3) self.assertEqual(len(parent), 1)
def test_len(self): settings = Config(YAML_DATA) self.assertEqual(len(settings), 2)
def test_contains(self): settings = Config(YAML_DATA) self.assertIn("sitename", settings) self.assertIn("thingy", settings) self.assertNotIn("test", settings)
def test_items(self): settings = Config(YAML_DATA) self.assertCountEqual(list(settings.items()), [("sitename", "bob"), ("thingy", ["one", "two", "three"])])
def test_values(self): settings = Config(YAML_DATA) self.assertCountEqual(list(settings.values()), ["bob", ["one", "two", "three"]])
def test_iter(self): settings = Config(YAML_DATA) self.assertCountEqual(list(settings), ["sitename", "thingy"])