def test_excluded_view(self): from statics.tree import TreeView tree = createTestTree() view = TreeView(tree, exclude=["/a/aa", "/c"]) self.assertEqual(view.location, "/") self.assertTrue("a" in view) self.assertTrue("b" in view) self.assertTrue(not "c" in view) self.assertTrue(not "c" in view.keys()) def getitem_c(): return view["c"] self.assertRaises(KeyError, getitem_c) view_a = view["a"] self.assertTrue(not "aa" in view_a) self.assertTrue("ab" in view_a) self.assertTrue(not "aa" in view_a.keys()) def getitem_a_aa(): return view_a["aa"] self.assertRaises(KeyError, getitem_a_aa) self.assertTrue(not "aa" in view_a.parent["a"])
def build(site, root, locations=None): """ Build `site`.""" if locations is None: locations = site.locations # pragma: nocover if not "/" in [l for l, c, s in locations]: raise ValueError("No script found for root (/) location.") builded = [] for location, script_config, script_name in ordered_locations(locations): view = TreeView(root, exclude=[l for l, n, c in locations if not l == location]) item = view.locate(location) script = query_script(script_name) if script is None: raise ValueError("No script registered for name '%s'" % script_name) builded.append((location, script(site, script_config, item))) root_element = builded.pop()[1] for location, element in reversed(builded): root_element.setlocation(location, element) return root_element