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)
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"))
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")))
def graphrules(db, config, args): """ This action fetch the rules from the DB sequencer table and call the DGM stage for the computation of the related graph. This graph is then given to the user in the DOT format. """ usage = "Usage: %prog [global_options] " + GRAPHRULES_ACTION_NAME + \ " [action_options] ruleset" doc = GRAPHRULES_DOC + \ " The graph is given in DOT format." parser = optparse.OptionParser(usage, description=doc) add_options_to(parser, ['--out'], config) (options, action_args) = parser.parse_args(args) if len(action_args) != 1: parser.error(GRAPHRULES_ACTION_NAME + ": ruleSet is missing.") req_ruleset = action_args[0] rules = db.get_rules_for(req_ruleset) ruleset = RuleSet(rules.values()) write_graph_to(ruleset.get_rules_graph(), options.out)