本文整理汇总了Python中sequencer.dgm.model.RuleSet类的典型用法代码示例。如果您正苦于以下问题:Python RuleSet类的具体用法?Python RuleSet怎么用?Python RuleSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RuleSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiple_actions_nodeps
def test_multiple_actions_nodeps(self):
"""
Check that a given component can contain multiple actions.
RuleSet: #ta, #ta
Components: a#ta
Expecting: a#ta with 2 actions.
"""
rules = set()
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="R1",
action="Action for a",
types=["[email protected]"]))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="R2",
action="Action for a",
types=["[email protected]"]))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("a#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 1, "Map: %s" % components)
self.assertTrue("a#[email protected]" in components)
self.assertTrue("R1" in components["a#[email protected]"].actions)
self.assertTrue("R2" in components["a#[email protected]"].actions)
self.assertEquals(len(components["a#[email protected]"].actions), 2)
self.assertEquals(len(depgraph.dag.node_attributes("a#[email protected]")), 2)
示例2: test_filtered_components
def test_filtered_components(self):
"""
Check that filter other than NONE and ALL works as expected.
RuleSet: #root (filter = in.*)
Components: in#root in_foo#root out#root
Expecting: in#root, in_foo#root out#root
(out#root has no action, it has been filtered out)
"""
rules = set()
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="R",
types=["[email protected]"],
action="Root Action",
# WARNING: space is important here!!
filter="%name =~ in.*"))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("in#[email protected]"),
Component("in_foo#[email protected]"),
Component("out#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 3)
self.assertTrue("in#[email protected]" in components)
self.assertTrue("in_foo#[email protected]" in components)
self.assertTrue("out#[email protected]" in components)
self.assertTrue(depgraph.dag is not None)
self.assertTrue(depgraph.dag.has_node("in#[email protected]"))
self.assertTrue(depgraph.dag.has_node("in_foo#[email protected]"))
self.assertTrue(depgraph.dag.has_node("out#[email protected]"))
self.assertTrue("R" in components["in#[email protected]"].actions)
self.assertEquals("Root Action", components["in#[email protected]"].actions["R"])
self.assertTrue("R" in components["in_foo#[email protected]"].actions)
self.assertEquals("Root Action", components["in_foo#[email protected]"].actions["R"])
self.assertTrue("Root Action" not in components["out#[email protected]"].actions)
示例3: test_simple_nodeps_ta_tb_a_b
def test_simple_nodeps_ta_tb_a_b(self):
"""
RuleSet: #ta, #tb,
Components: a#ta, 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=["[email protected]"]))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="Rb",
action="Action for b",
types=["[email protected]"]))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("a#[email protected]"),
Component("b#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 2)
self.assertTrue("a#[email protected]" in components)
self.assertTrue("b#[email protected]" in components)
self.assertTrue(depgraph.dag is not None)
self.assertTrue(depgraph.dag.has_node("a#[email protected]"))
self.assertTrue(depgraph.dag.has_node("b#[email protected]"))
self.assertTrue("Ra" in components["a#[email protected]"].actions)
self.assertEquals("Action for a", components["a#[email protected]"].actions["Ra"])
self.assertTrue("Rb" in components["b#[email protected]"].actions)
self.assertEquals("Action for b", components["b#[email protected]"].actions["Rb"])
self.assertNoEdgeBetween(depgraph.dag, "a#[email protected]", "b#[email protected]")
示例4: test_no_root_with_self_cycle_in_graph_rules
def test_no_root_with_self_cycle_in_graph_rules(self):
"""
There are no match in the given component list.
RuleSet: #ta->#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=["[email protected]"],
depsfinder=tools.getMockDepsFinderCmd(["foo#[email protected]"]),
dependson=["Ra"]))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("c#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 1, "Map: %s" % components)
self.assertTrue("c#[email protected]" in components)
self.assertTrue(depgraph.dag is not None)
self.assertEquals(len(depgraph.dag.nodes()), 1)
self.assertTrue(depgraph.dag.has_node("c#[email protected]"))
示例5: test_root_in_simple_cycle
def test_root_in_simple_cycle(self):
"""
The root is in a simple cycle.
RuleSet: #ta->#tb, #tb->#tc, #tc->#ta (triangle)
Components: b#tb
Expecting: b#tb
"""
rules = set()
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="Ra",
action="Action for a",
types=["[email protected]"],
dependson=["Rb"]))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="Rb",
action="Action for b",
types=["[email protected]"],
dependson=["Rc"]))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="Rc",
action="Action for c",
dependson=["Ra"],
types=["[email protected]"]))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("b#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 1, "Map: %s" % components)
self.assertTrue("b#[email protected]" in components)
self.assertTrue(depgraph.dag is not None)
self.assertTrue(depgraph.dag.has_node("b#[email protected]"))
示例6: test_simple_deps_ta_tb_b_a_withdepsfinder
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=["[email protected]"],
depsfinder=tools.getMockDepsFinderCmd(["b#[email protected]"]),
dependson=["Rb"]))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="Rb",
action="Action for b",
types=["[email protected]"]))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("b#[email protected]"),
Component("a#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 2, "Map: %s" % components)
self.assertTrue("a#[email protected]" in components)
self.assertTrue("b#[email protected]" in components)
self.assertTrue(depgraph.dag is not None)
self.assertTrue(depgraph.dag.has_node("a#[email protected]"))
self.assertTrue(depgraph.dag.has_node("b#[email protected]"))
self.assertTrue(depgraph.dag.has_edge(("a#[email protected]", "b#[email protected]")))
示例7: test_simple_deps_ta_tb_b_a_nodepsfinder
def test_simple_deps_ta_tb_b_a_nodepsfinder(self):
"""
RuleSet: #ta->#tb,
Components: b#tb, a#ta (reverse than test_simple_deps_ta_tb_a_b_nodepsfinder)
Expecting: a#ta, b#tb (order does not count)
"""
rules = set()
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="Ra",
action="Action for a",
types=["[email protected]"],
dependson=["Rb"]))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="Rb",
action="Action for b",
types=["[email protected]"]))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("b#[email protected]"),
Component("a#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 2)
self.assertTrue("a#[email protected]" in components)
self.assertTrue("b#[email protected]" in components)
self.assertTrue(depgraph.dag is not None)
self.assertTrue(depgraph.dag.has_node("a#[email protected]"))
self.assertTrue(depgraph.dag.has_node("b#[email protected]"))
self.assertNoEdgeBetween(depgraph.dag, "a#[email protected]", "b#[email protected]")
示例8: test_filtered_none_components_deps
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=["[email protected]"],
depsfinder=tools.getMockDepsFinderCmd(["b#[email protected]"]),
dependson=["R-Deps"]))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="R-Deps",
action="Deps Action",
types=["[email protected]"],
filter=NONE))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("a#[email protected]")])
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#[email protected]" in components)
self.assertTrue("R-root" in components["a#[email protected]"].actions)
self.assertEquals("Root Action", components["a#[email protected]"].actions["R-root"])
self.assertTrue("b#[email protected]" in components)
self.assertTrue(depgraph.dag.has_node("a#[email protected]"))
self.assertTrue(depgraph.dag.has_node("b#[email protected]"))
self.assertTrue("Deps Action" not in components["b#[email protected]"].actions)
示例9: test_a_nop_b
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=["[email protected]"],
action=NONE,
depsfinder=tools.getMockDepsFinderCmd(["b#[email protected]"]),
dependson=['Dep']))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="Dep",
types=["[email protected]"],
action="Dep Action"))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("a#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 2)
self.assertTrue("a#[email protected]" in components)
self.assertTrue("b#[email protected]" in components)
self.assertTrue(depgraph.dag is not None)
self.assertTrue(depgraph.dag.has_node("a#[email protected]"))
self.assertTrue(depgraph.dag.has_node("b#[email protected]"))
self.assertFalse("Root" in components["a#[email protected]"].actions, components)
self.assertTrue("Dep" in components["b#[email protected]"].actions)
attributes = depgraph.dag.node_attributes("a#[email protected]")
self.assertEquals(len(attributes), 0)
attributes = depgraph.dag.node_attributes("b#[email protected]")
self.assertEquals(len(attributes), 1)
示例10: test_multiple_actions_cycle
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=["[email protected]"]))
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="R2",
action="Action for a",
types=["[email protected]"],
depsfinder=tools.getMockDepsFinderCmd(["a#[email protected]"]),
dependson=["R1"]))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("a#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 1, "Map: %s" % components)
self.assertTrue("a#[email protected]" in components)
self.assertTrue("R1" in components["a#[email protected]"].actions)
self.assertTrue("R2" in components["a#[email protected]"].actions)
self.assertEquals(len(components["a#[email protected]"].actions), 2)
self.assertEquals(len(depgraph.dag.node_attributes("a#[email protected]")), 2)
self.assertTrue(depgraph.dag.has_edge(("a#[email protected]", "a#[email protected]")))
示例11: test_ruleset_field_empty
def test_ruleset_field_empty(self):
ruleset = RuleSet(set())
self.assertTrue(ruleset.name is None)
self.assertEquals(ruleset.rules, set())
graph = ruleset.get_rules_graph()
self.assertTrue(graph is not None)
self.assertEquals(len(graph.edges()), 0)
self.assertEquals(len(graph.nodes()), 0)
示例12: test_ruleset_field_single
def test_ruleset_field_single(self):
rules = set()
rules.add(tools.create_rule(self.__class__.__name__,
"ruleset_field_single"))
ruleset = RuleSet(rules)
self.assertEquals(ruleset.name, self.__class__.__name__)
self.assertEquals(ruleset.rules, rules)
graph = ruleset.get_rules_graph()
self.assertTrue(graph is not None)
self.assertEquals(len(graph.edges()), 0)
self.assertEquals(len(graph.nodes()), 1)
self.assertTrue(graph.has_node("ruleset_field_single"))
示例13: test_only_root_rules_applied
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=["[email protected]"],
filter="%name =~ a",
depsfinder=tools.getMockDepsFinderCmd(["b#[email protected]"]),
dependson=["Rdep"],
)
)
rules.add(
tools.create_rule(
ruleset=self.__class__.__name__,
name="Rb",
action="Action for b",
types=["[email protected]"],
filter="%name =~ b",
dependson=["Rdep"],
)
)
rules.add(
tools.create_rule(ruleset=self.__class__.__name__, name="Rdep", action="Action for dep", types=["[email protected]"])
)
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("a#[email protected]"), Component("b#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 2, "Map: %s" % components)
self.assertTrue("a#[email protected]" in components)
self.assertTrue("b#[email protected]" in components)
self.assertEquals(len(components["a#[email protected]"].actions), 1)
self.assertTrue("Ra" in components["a#[email protected]"].actions)
self.assertEquals(len(components["b#[email protected]"].actions), 2)
self.assertTrue("Rb" in components["b#[email protected]"].actions)
self.assertTrue("Rdep" in components["b#[email protected]"].actions)
self.assertEquals(len(depgraph.dag.node_attributes("a#[email protected]")), 1)
self.assertEquals(len(depgraph.dag.node_attributes("b#[email protected]")), 2)
示例14: test_unknown_component
def test_unknown_component(self):
rules = set()
rules.add(tools.create_rule(ruleset=self.__class__.__name__,
name="test_unknown_component",
types=["[email protected]"]))
ruleset = RuleSet(rules)
depgraph = ruleset.get_depgraph([Component("foo#[email protected]")])
components = depgraph.components_map
self.assertTrue(components is not None)
self.assertEquals(len(components), 1)
self.assertTrue("foo#[email protected]" in components)
self.assertEquals(len(components["foo#[email protected]"].actions), 0)
self.assertTrue(depgraph.dag is not None)
self.assertTrue(depgraph.dag.has_node("foo#[email protected]"))
示例15: test_ruleset_dependencies
def test_ruleset_dependencies(self):
rules = set()
rules.add(tools.create_rule(self.__class__.__name__,
"ruleset_dependencies"))
rules.add(tools.create_rule(self.__class__.__name__,
"ruleset_dependencies2",
dependson=["ruleset_dependencies"]))
ruleset = RuleSet(rules)
self.assertEquals(ruleset.name, self.__class__.__name__)
self.assertEquals(ruleset.rules, rules)
graph = ruleset.get_rules_graph()
self.assertTrue(graph is not None)
self.assertEquals(len(graph.edges()), 1)
self.assertTrue(graph.has_edge(("ruleset_dependencies2",
"ruleset_dependencies")))