def test_no_root_with_cycle_in_graph_rules(self): """ There are no match in the given component list. RuleSet: #ta->#tb->#ta Components: c#tc Expecting: c#tc. """ rules = set() rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="Ra", action="Action for a", types=["ta@cat"], depsfinder=tools.getMockDepsFinderCmd(["foo#bar@cat"]), dependson=["Rb"])) rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["tb@cat"], depsfinder=tools.getMockDepsFinderCmd(["foo#bar@cat"]), dependson=["Ra"])) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("c#tc@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 1, "Map: %s" % components) self.assertTrue("c#tc@cat" in components) self.assertTrue(depgraph.dag is not None) self.assertEquals(len(depgraph.dag.nodes()), 1) self.assertTrue(depgraph.dag.has_node("c#tc@cat"))
def test_a_nop_b(self): """ Check that action NONE are understood correctly. RuleSet: #root, #dep (filter = ALL), a#root -> b#dep (a.action=NONE) Expecting: a#root -> b#dep But a#root has no attribute in the xml graph. """ rules = set() rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="Root", types=["root@cat"], action=NONE, depsfinder=tools.getMockDepsFinderCmd(["b#dep@cat"]), dependson=['Dep'])) rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="Dep", types=["dep@cat"], action="Dep Action")) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("a#root@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 2) self.assertTrue("a#root@cat" in components) self.assertTrue("b#dep@cat" in components) self.assertTrue(depgraph.dag is not None) self.assertTrue(depgraph.dag.has_node("a#root@cat")) self.assertTrue(depgraph.dag.has_node("b#dep@cat")) self.assertFalse("Root" in components["a#root@cat"].actions, components) self.assertTrue("Dep" in components["b#dep@cat"].actions) attributes = depgraph.dag.node_attributes("a#root@cat") self.assertEquals(len(attributes), 0) attributes = depgraph.dag.node_attributes("b#dep@cat") self.assertEquals(len(attributes), 1)
def test_filtered_none_components_deps(self): """ Check that dependencies are not in the graph when they are filtered out. RuleSet: #root -> #deps (filter = NONE) Components: a#root Component a provides a depfinder that returns b#deps Expecting: a#root, b#deps (b#deps has no action, it has been filtered out) """ rules = set() rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="R-root", action="Root Action", types=["root@cat"], depsfinder=tools.getMockDepsFinderCmd(["b#deps@cat"]), dependson=["R-Deps"])) rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="R-Deps", action="Deps Action", types=["deps@cat"], filter=NONE)) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("a#root@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 2) self.assertTrue(depgraph.dag is not None) self.assertTrue("a#root@cat" in components) self.assertTrue("R-root" in components["a#root@cat"].actions) self.assertEquals("Root Action", components["a#root@cat"].actions["R-root"]) self.assertTrue("b#deps@cat" in components) self.assertTrue(depgraph.dag.has_node("a#root@cat")) self.assertTrue(depgraph.dag.has_node("b#deps@cat")) self.assertTrue("Deps Action" not in components["b#deps@cat"].actions)
def test_multiple_actions_cycle(self): """ Check that a given component can contain multiple actions. RuleSet: R1:#ta, R2:#ta->R1 Components: a#ta (R1 depsfinder returns itself: a#ta) Expecting: a#ta with 2 actions and a cycle. """ rules = set() rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="R1", action="Action for a", types=["ta@cat"])) rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="R2", action="Action for a", types=["ta@cat"], depsfinder=tools.getMockDepsFinderCmd(["a#ta@cat"]), dependson=["R1"])) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("a#ta@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 1, "Map: %s" % components) self.assertTrue("a#ta@cat" in components) self.assertTrue("R1" in components["a#ta@cat"].actions) self.assertTrue("R2" in components["a#ta@cat"].actions) self.assertEquals(len(components["a#ta@cat"].actions), 2) self.assertEquals(len(depgraph.dag.node_attributes("a#ta@cat")), 2) self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "a#ta@cat")))
def test_simple_deps_ta_tb_b_a_withdepsfinder(self): """ RuleSet: #ta->#tb, Components: b#tb, a#ta (reverse) Component a does provide a depfinder that returns b#tb Expecting: a#ta -> b#tb """ rules = set() rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="Ra", action="Action for a", types=["ta@cat"], depsfinder=tools.getMockDepsFinderCmd(["b#tb@cat"]), dependson=["Rb"])) rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["tb@cat"])) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("b#tb@cat"), Component("a#ta@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 2, "Map: %s" % components) self.assertTrue("a#ta@cat" in components) self.assertTrue("b#tb@cat" in components) self.assertTrue(depgraph.dag is not None) self.assertTrue(depgraph.dag.has_node("a#ta@cat")) self.assertTrue(depgraph.dag.has_node("b#tb@cat")) self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "b#tb@cat")))
def test_simple_noroot(self): """ There are no root in the given component list. RuleSet: #ta->#tb, #ta->#tc, #tb->#tc (triangle) Components: b#tb, a#ta (each depsfinder returns c#tc) Expecting: a#ta -> b#tb, a#ta -> c#tc """ rules = set() rules.add( tools.create_rule( ruleset=self.__class__.__name__, name="Ra", action="Action for a", types=["ta@cat"], depsfinder=tools.getMockDepsFinderCmd(["c#tc@cat"]), dependson=["Rb", "Rc"], ) ) rules.add( tools.create_rule( ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["tb@cat"], depsfinder=tools.getMockDepsFinderCmd(["c#tc@cat"]), dependson=["Rc"], ) ) rules.add( tools.create_rule(ruleset=self.__class__.__name__, name="Rc", action="Action for c", types=["tc@cat"]) ) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("b#tb@cat"), Component("a#ta@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 3, "Map: %s" % components) self.assertTrue("a#ta@cat" in components) self.assertTrue("b#tb@cat" in components) self.assertTrue("c#tc@cat" in components) self.assertTrue(depgraph.dag is not None) self.assertTrue(depgraph.dag.has_node("a#ta@cat")) self.assertTrue(depgraph.dag.has_node("b#tb@cat")) self.assertTrue(depgraph.dag.has_node("c#tc@cat")) self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "c#tc@cat"))) self.assertTrue(depgraph.dag.has_edge(("b#tb@cat", "c#tc@cat")))
def test_rule_applied_at_most_once(self): """ Check that a given rule is applied at most once for a given component. RuleSet: #ta->#tc, #tb->#tc Components: a#ta, b#tb (each depsfinder returns c#tc) Expecting: c#tc contains a single action (applied once only). """ rules = set() rules.add( tools.create_rule( ruleset=self.__class__.__name__, name="Ra", action="Action for a", types=["ta@cat"], depsfinder=tools.getMockDepsFinderCmd(["c#tc@cat"]), dependson=["Rc"], ) ) rules.add( tools.create_rule( ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["tb@cat"], depsfinder=tools.getMockDepsFinderCmd(["c#tc@cat"]), dependson=["Rc"], ) ) rules.add( tools.create_rule(ruleset=self.__class__.__name__, name="Rc", action="Action for c", types=["tc@cat"]) ) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("b#tb@cat"), Component("a#ta@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 3, "Map: %s" % components) self.assertTrue("c#tc@cat" in components) self.assertTrue("Rc" in components["c#tc@cat"].actions) self.assertEquals(components["c#tc@cat"].actions["Rc"], "Action for c") self.assertEquals(len(components["c#tc@cat"].actions), 1) self.assertEquals(len(depgraph.dag.node_attributes("c#tc@cat")), 1)
def test_only_root_rules_applied(self): """ Check that a rule is applied on a parameter only if it is a potential root. RuleSet: #t(action1)->#t(action2) Components: a#t, b#t (a#t depsfinder returns b#t) Expecting: a#t contains only 1 action while b#t contains two actions. """ rules = set() rules.add( tools.create_rule( ruleset=self.__class__.__name__, name="Ra", action="Action for a", types=["t@cat"], filter="%name =~ a", depsfinder=tools.getMockDepsFinderCmd(["b#t@cat"]), dependson=["Rdep"], ) ) rules.add( tools.create_rule( ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["t@cat"], filter="%name =~ b", dependson=["Rdep"], ) ) rules.add( tools.create_rule(ruleset=self.__class__.__name__, name="Rdep", action="Action for dep", types=["t@cat"]) ) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("a#t@cat"), Component("b#t@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 2, "Map: %s" % components) self.assertTrue("a#t@cat" in components) self.assertTrue("b#t@cat" in components) self.assertEquals(len(components["a#t@cat"].actions), 1) self.assertTrue("Ra" in components["a#t@cat"].actions) self.assertEquals(len(components["b#t@cat"].actions), 2) self.assertTrue("Rb" in components["b#t@cat"].actions) self.assertTrue("Rdep" in components["b#t@cat"].actions) self.assertEquals(len(depgraph.dag.node_attributes("a#t@cat")), 1) self.assertEquals(len(depgraph.dag.node_attributes("b#t@cat")), 2)
def test_rule_applied_only_on_deps(self): """ Check that a rule 'd' is applied on a component 'e' only if 'e' is a parameter or if it is a dependency of a component 'c' which was applied a rule 'r' where 'r'.dependson includes 'd'. RuleSet: #ta->#tb, #tc Components: a#ta, c#tc (a#ta depsfinder returns foo#tc) Expecting: foo#tc should not contain any action. """ rules = set() rules.add( tools.create_rule( ruleset=self.__class__.__name__, name="Ra", action="Action for a", types=["ta@cat"], depsfinder=tools.getMockDepsFinderCmd(["foo#tc@cat"]), dependson=["Rb"], ) ) rules.add( tools.create_rule(ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["tb@cat"]) ) rules.add( tools.create_rule(ruleset=self.__class__.__name__, name="Rc", action="Action for c", types=["tc@cat"]) ) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("a#ta@cat"), Component("c#tc@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 3, "Map: %s" % components) self.assertTrue("foo#tc@cat" in components) self.assertTrue("c#tc@cat" in components) self.assertTrue("Rc" in components["c#tc@cat"].actions) self.assertEquals(components["c#tc@cat"].actions["Rc"], "Action for c") self.assertEquals(len(components["c#tc@cat"].actions), 1) self.assertEquals(len(depgraph.dag.node_attributes("c#tc@cat")), 1) self.assertEquals(len(components["foo#tc@cat"].actions), 0) self.assertEquals(len(depgraph.dag.node_attributes("foo#tc@cat")), 0)
def test_substitution_in_depsfinder(self): rules = set() pattern = "%id-%name-%type-%category-%ruleset-%rulename" rules.add(tools.create_rule(ruleset="RS", name="RN", action="Action", depsfinder=tools.getMockDepsFinderCmd([pattern]), types=["known@cat"], dependson=["Dummy"])) rules.add(tools.create_rule(ruleset="RS", name="Dummy")) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("foo#known@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 2) self.assertTrue("foo#known@cat" in components) self.assertTrue("foo#known@cat-foo-known-cat-RS-RN" in components) self.assertTrue(depgraph.dag is not None) self.assertTrue(depgraph.dag.has_node("foo#known@cat")) self.assertTrue(depgraph.dag.has_node("foo#known@cat-foo-known-cat-RS-RN"))
def test_multiple_deps_ta_tb_a_withdepsfinder(self): """ RuleSet: #ta->#tb, Components: a#ta Component a does provide a depfinder that returns b1#tb, b2#tb, c#tc Expecting: a#ta -> b1#tb, a#ta->b2#tb """ rules = set() rules.add( tools.create_rule( ruleset=self.__class__.__name__, name="Ra", action="Action for a", types=["ta@cat"], depsfinder=tools.getMockDepsFinderCmd(["b1#tb@cat", "b2#tb@cat", "c#tc@cat"]), dependson=["Rb"], ) ) rules.add( tools.create_rule(ruleset=self.__class__.__name__, name="Rb", action="Action for b", types=["tb@cat"]) ) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("a#ta@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 4, "Map: %s" % components) self.assertTrue("a#ta@cat" in components) self.assertTrue("b1#tb@cat" in components) self.assertTrue("b2#tb@cat" in components) self.assertTrue("c#tc@cat" in components) self.assertTrue(depgraph.dag is not None) self.assertTrue(depgraph.dag.has_node("a#ta@cat")) self.assertTrue(depgraph.dag.has_node("b1#tb@cat")) self.assertTrue(depgraph.dag.has_node("b2#tb@cat")) self.assertTrue(depgraph.dag.has_node("c#tc@cat")) self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "b1#tb@cat"))) self.assertTrue(depgraph.dag.has_edge(("a#ta@cat", "b2#tb@cat"))) # There are no rules for #tc, therefore, no dependency hold. self.assertFalse(depgraph.dag.has_edge(("a#ta@cat", "c#tc@cat")))
def test_filtered_none_components_requested(self): """ When filtered out components are requested, rules are not applied, but the components remains in the depgraph. RuleSet: #root (filter = NONE) -> #deps Components: a#root, b#deps Component a provides a depfinder that returns c#deps but it is filtered out Expecting: a#root, b#deps (a#root has no action) """ rules = set() rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="R-root", action="Root Action", types=["root@cat"], depsfinder=tools.getMockDepsFinderCmd(["c#deps@cat"]), dependson=["R-deps"], filter=NONE)) rules.add(tools.create_rule(ruleset=self.__class__.__name__, name="R-deps", action="Deps Action", types=["deps@cat"])) ruleset = RuleSet(rules) depgraph = ruleset.get_depgraph([Component("a#root@cat"), Component("b#deps@cat")]) components = depgraph.components_map self.assertTrue(components is not None) self.assertEquals(len(components), 2) self.assertTrue(depgraph.dag is not None) self.assertTrue("a#root@cat" in components) self.assertTrue("b#deps@cat" in components) self.assertTrue("c#deps@cat" not in components) self.assertTrue("R-root" not in components["a#root@cat"].actions) self.assertTrue("R-deps" in components["b#deps@cat"].actions) self.assertTrue(depgraph.dag.has_node("a#root@cat")) self.assertTrue(depgraph.dag.has_node("b#deps@cat")) self.assertFalse(depgraph.dag.has_node("c#deps@cat"))