def test_constructor_007(self): "Test conversion from dictionary: more complex graph" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"] } dg = Digraph(d) e = dg.output_to_dict() assert(d==e)
def __resolve_depends_on_one_req_impl(self, req): tag_content = req.brmo["Depends on"] # If available, it must not empty if not tag_content.get_content(): print("+++ ERROR %s: 'Depends on' field has len 0" % (req.get_id())) return False # Step through the list tag_content_split = tag_content.get_content().split() for split_tag in tag_content_split: if split_tag not in self.get_all_requirement_ids(): logger.error(LogFormatter.format( 47, "'Depends on' points to a " "non-existing requirement '%s'" % split_tag, req.get_id())) return False # It is not allowed to have self-references: it does not # make any sense, that a requirement references itself. if split_tag == req.get_id(): logger.error(LogFormatter.format( 59, "'Depends on' points to the " "requirement itself", req.get_id())) return False # Mark down the depends on... dep_req = self.__requirements[split_tag] # This is exactly the other way as used in the 'Depends on' tracer.debug("Add edge [%s] -> [%s]", dep_req.get_id(), req.get_id()) Digraph.create_edge(dep_req, req) # Delete the original tag del req.brmo["Depends on"] return True
def __read(self, tname, input_handler, commit, file_info, req_set): '''Read in the topic and create all the tags.''' Encoding.check_unicode(tname) self.__tags = TxtRecord.from_string( file_info.get_content(), tname, input_handler.get_txt_io_config()) for tag in self.__tags: # If the topic has subtopics, read them also in. if tag.get_tag() == "SubTopic": lfile_info = input_handler.get_file_info_with_type( commit, "topics", tag.get_content() + ".tic") ntopic = Topic(self.__digraph, self._config, input_handler, commit, lfile_info, req_set) self.__digraph.add_node(ntopic) Digraph.create_edge(self, ntopic) elif tag.get_tag() == "Name": if self.__topic_name is not None: # There can (currently) be only one name assert False self.__topic_name = tag.get_content() elif tag.get_tag() == "IncludeRequirements": if tag.get_content() != "full": raise RMTException(113, "IncludeRequirements value not " "supported [%s]" % tag.get_content(), self.name) self.__requirements = req_set.restrict_to_topics(tname) tracer.debug("Found [%d] requirements for topic [%s]", self.__requirements.get_requirements_cnt(), tname) # Check for the existence of the name if self.__topic_name is None: raise RMTException(62, "Mandatory tag 'Name' not given in topic", self.name)
def test_find_02(self): "Digraph find with element not available" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"] } dg = Digraph(d) n = dg.find("Z") assert(n==None)
def __resolve_solved_by_one_req_deps(self, req): content = req.brmo["Solved by"].get_content() # If available, it must not empty if not content: logger.error(LogFormatter.format( 77, "'Solved by' field has length 0", req.get_id())) return False # Step through the list dep_list = content.split() tracer.debug("dependent list [%s]", dep_list) for dep in dep_list: if dep not in self.__requirements: logger.error(LogFormatter.format( 74, "'Solved by' points to a " "non-existing requirement '%s'" % dep, req.get_id())) return False # It is not allowed to have self-references: it does not # make any sense, that a requirement references itself. if dep == req.get_id(): logger.error(LogFormatter.format( 75, "'Solved by' points to the " "requirement itself", req.get_id())) return False # Mark down the depends on... dep_req = self.__requirements[dep] # This is exactly the other way as used in the 'Depends on' tracer.debug("Add edge [%s] -> [%s]", dep_req.get_id(), req.get_id()) Digraph.create_edge(req, dep_req) # Delete the original tag del req.brmo["Solved by"] return True
def test_find_01(self): "Digraph find with element available" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"] } dg = Digraph(d) n = dg.find("A") assert(n.name=="A")
def __resolve_depends_on_one_req(self, req_node, also_solved_by): tracer.debug("Called.") req = req_node.get_requirement() if req.get_value("Type") == Requirement.rt_master_requirement: # There must no 'Depends on' if "Depends on" in req.brmo: print("+++ ERROR %s: initial requirement has " "Depends on field." % (req.id)) return False # It self does not have any depends on nodes req.graph_depends_on = None # This is the master! return True # For all other requirements types there must be a 'Depends on' if "Depends on" not in req.brmo: if also_solved_by: # Skip handling this requirement return True print("+++ ERROR %s: non-initial requirement has " "no 'Depends on' field." % (req.id)) return False t = req.brmo["Depends on"] # If available, it must not empty if len(t.get_content()) == 0: print("+++ ERROR %s: 'Depends on' field has len 0" % (req.id)) return False # Step through the list tl = t.get_content().split() for ts in tl: if ts not in self.get_all_requirement_ids(): logger.error(LogFormatter.format( 47, "'Depends on' points to a " "non-existing requirement '%s'" % ts, req.id)) return False # It is not allowed to have self-references: it does not # make any sense, that a requirement references itself. if ts == req.id: logger.error(LogFormatter.format( 59, "'Depends on' points to the " "requirement itself", req.id)) return False # Mark down the depends on... dep_req_node = self._named_nodes[ts] # This is exactly the other way as used in the 'Depends on' tracer.debug("Add edge [%s] -> [%s]" % (dep_req_node.get_requirement().get_id(), req.get_id())) Digraph.create_edge(self, dep_req_node, req_node) # Copy and delete the original tag ## XXX Not neede any more? req.tags["Depends on"] = t.split() del req.brmo["Depends on"] return True
def test_get_named_node_01(self): "Digraph get named node with map available" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"] } dg = Digraph(d) dg.build_named_nodes() n = dg.get_named_node("A") assert(n.name=="A")
def rmttest_get_named_node_03(self): "Digraph get named node with map not available" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = Digraph(d) with pytest.raises(RMTException) as rmte: dg.get_named_node("NotThere") assert 22 == rmte.id()
def rmttest_add_node_01(self): "Digraph add node with two times same name" dg = Digraph() n1 = Digraph.Node("myname") n2 = Digraph.Node("myname") dg.add_node(n1) with pytest.raises(RMTException) as rmte: dg.add_node(n2) assert 39 == rmte.id()
def rmttest_get_named_node_02(self): "Digraph get named node with map available but invalid node name" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = Digraph(d) dg.build_named_nodes() with pytest.raises(RMTException) as rmte: dg.get_named_node("NotThere") assert 23 == rmte.id()
def rmttest_build_named_nodes_01(self): "Digraph build named nodes with node without name" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = Digraph(d) n = dg.find("A") n.name = None with pytest.raises(RMTException) as rmte: dg.build_named_nodes() assert 20 == rmte.id()
def test_get_named_node_03(self): "Digraph get named node with map not available" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"] } dg = Digraph(d) try: n = dg.get_named_node("NotThere") assert(False) except RMTException, rmte: assert(rmte.id()==22)
def test_add_node_01(self): "Digraph add node with two times same name" dg = Digraph() n1 = Digraph.Node("myname") n2 = Digraph.Node("myname") dg.add_node(n1) try: dg.add_node(n2) assert(False) except RMTException, rmte: assert(rmte.id() == 39)
def test_get_named_node_02(self): "Digraph get named node with map available but invalid node name" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"] } dg = Digraph(d) dg.build_named_nodes() try: n = dg.get_named_node("NotThere") assert(False) except RMTException, rmte: assert(rmte.id()==23)
def __init__(self, all_reqs, name, tparam, config): Digraph.__init__(self) MemLogStore.__init__(self) assert len(tparam) == 2 self.name = name self.topic_dir = tparam[0] self.master_topic = tparam[1] self.config = config self.read_topics(self.topic_dir, self.master_topic) if all_reqs != None: self.reqset = self.reqs_limit(all_reqs)
def test_build_named_nodes_01(self): "Digraph build named nodes with node without name" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"] } dg = Digraph(d) n = dg.find("A") n.name=None try: dg.build_named_nodes() assert(False) except RMTException, rmte: assert(rmte.id()==20)
def rmttest_build_named_nodes_02(self): "Digraph build named nodes with two nodes with same name" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = Digraph(d) n = dg.find("A") n.name = "Twice" n = dg.find("B") n.name = "Twice" with pytest.raises(RMTException) as rmte: dg.build_named_nodes() assert 21 == rmte.id()
def read(self): self.digraph.add_node(self) fd = file(os.path.join(self.dir, self.name + ".tic")) self.t = TxtRecord.from_fd(fd, self.name, self.parser_config) for tag in self.t: # If the topic has subtopics, read them also in. if tag.get_tag()=="SubTopic": ntopic = Topic(self.dir, tag.get_content(), self.digraph, self.parser_config, self.level+1, self) #self.outgoing.append(ntopic) Digraph.create_edge(self, ntopic) #self.outgoing.append(ntopic) fd.close()
def __init__(self, mods, opts, config): Digraph.__init__(self) MemLogStore.__init__(self) self.reqs = {} self.mods = mods self.opts = opts # The requirement set is only (fully) usable, when everything # is fine. self.state = self.er_fine self.config = config self.version_id = None # The analytic modules store the results in this map: self.analytics = {} self.constraints = {}
def test_build_named_nodes_02(self): "Digraph build named nodes with two nodes with same name" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"] } dg = Digraph(d) n = dg.find("A") n.name = "Twice" n = dg.find("B") n.name = "Twice" try: dg.build_named_nodes() assert(False) except RMTException, rmte: assert(rmte.id()==21)
def __init__(self, config, input_handler, commit, object_cache, input_mods): '''Constructs a RequirementSet. This does not read everything in: please use the appropriate method to do so.''' tracer.info("called") Digraph.__init__(self) MemLogStore.__init__(self) self.__config = config self.__object_cache = object_cache self.__input_mods = input_mods # TODO: is this the structure that is needed? self.__requirements = {} self.__read_requirements(input_handler, commit)
def __init__(self, config): '''Constructs a RequirementSet. This does not read everything in: please use the appropriate method to do so.''' tracer.debug("Called.") Digraph.__init__(self) UsableFlag.__init__(self) self._config = config self.__master_nodes = None # The key is the id the value the constraint. self.__constraints = {} # This holds only ready to use CE3 objects. self.__ce3set = CE3Set() # All the test cases for this requirement set self.__testcases = {} tracer.debug("Finished.")
def __resolve_solved_by_one_req(self, req_node): '''Resolve the 'Solved by' for one requirement.''' assert isinstance(req_node, RequirementDNode) req = req_node.get_requirement() tracer.debug("Called: requirement id [%s]." % req.get_id()) # It is a 'normal' case when there is no 'Solved by' (until now). if "Solved by" not in req.brmo: return True content = req.brmo["Solved by"].get_content() # If available, it must not empty if len(content) == 0: logger.error(LogFormatter.format( 77, "'Solved by' field has length 0", req.get_id())) return False # Step through the list dep_list = content.split() tracer.debug("dependent list [%s]" % dep_list) for dep in dep_list: if dep not in self._named_nodes: logger.error(LogFormatter.format( 74, "'Solved by' points to a " "non-existing requirement '%s'" % dep, req.get_id())) return False # It is not allowed to have self-references: it does not # make any sense, that a requirement references itself. if dep == req.get_id(): logger.error(LogFormatter.format( 75, "'Solved by' points to the " "requirement itself", req.id)) return False # Mark down the depends on... dep_req_node = self._named_nodes[dep] assert isinstance(dep_req_node, RequirementDNode) # This is exactly the other way as used in the 'Depends on' tracer.debug("Add edge [%s] -> [%s]" % (dep_req_node.get_requirement().get_id(), req.get_id())) Digraph.create_edge(self, req_node, dep_req_node) # Delete the original tag del req.brmo["Solved by"] return True
def __init__(self, directory, config, add_dir_components=["rmtoo", "inputs"], mod_components=["rmtoo", "inputs"]): """Read in the modules directory.""" Digraph.__init__(self) self.config = config # The different types of tags self.tagtypes = {} # TODO: add symbolic constants for this self.tagtypes["reqtag"] = {} self.tagtypes["reqdeps"] = {} self.tagtypes["ctstag"] = {} # Split it up into components dir_components = self.split_directory(directory) dir_components.extend(add_dir_components) self.load(dir_components, mod_components)
def __init__(self, config): '''Read in the modules''' Digraph.__init__(self) self._config = config self.__reqdeps_sorted = None # The different types of tags self.__tagtypes = {} self.__tagtypes[InputModuleTypes.reqtag] = {} self.__tagtypes[InputModuleTypes.reqdeps] = {} self.__tagtypes[InputModuleTypes.ctstag] = {} self.__tagtypes[InputModuleTypes.testcase] = {} self.__plugin_manager = extension.ExtensionManager( namespace='rmtoo.input.plugin', invoke_on_load=False) self.__load()
def __init__(self, directory, opts, config, add_dir_components = ["rmtoo", "modules"], mod_components = ["rmtoo", "modules"]): Digraph.__init__(self) self.opts = opts self.config = config # The different types of tags self.tagtypes = {} self.tagtypes["reqtag"] = {} self.tagtypes["reqdeps"] = {} self.tagtypes["ctstag"] = {} # Split it up into components dir_components = self.split_directory(directory) dir_components.extend(add_dir_components) self.load(dir_components, mod_components)
def __init__(self, directory, config, add_dir_components=["rmtoo", "inputs"], mod_components=["rmtoo", "inputs"]): '''Read in the modules directory.''' Digraph.__init__(self) self._config = config self.__reqdeps_sorted = None # The different types of tags self.__tagtypes = {} self.__tagtypes[InputModuleTypes.reqtag] = {} self.__tagtypes[InputModuleTypes.reqdeps] = {} self.__tagtypes[InputModuleTypes.ctstag] = {} self.__tagtypes[InputModuleTypes.testcase] = {} # Split it up into components dir_components = self._split_directory(directory) dir_components.extend(add_dir_components) self.__load(dir_components, mod_components)
def DEPRECATED___init__(self, config, name, config_prefix_str, req_input_dir): tracer.info("name [%s] config_prefix [%s] req_input_dir [%s]" % (name, config_prefix_str, req_input_dir)) Digraph.__init__(self) MemLogStore.__init__(self) # The name of the TopicSet. self.name = name # The directory where all topics are stored. self.topic_dir = config.get_value(config_prefix_str + '.directory') # The master (i.e. the initial) topic. self.master_topic = config.get_value(config_prefix_str + '.name') self.config = config self.internal_init_requirements() # TODO: is this needed???? # if all_reqs != None: # self.mReqset = self.reqs_limit(all_reqs) self.output_handlers = [] self.init_output_handler()
def __init__(self, config, input_handler, commit, object_cache, input_mods): '''Read in all the dependent topics and the requirements.''' tracer.info("Called; commit timestamp [%s]", input_handler.get_timestamp(commit)) Digraph.__init__(self) UsableFlag.__init__(self) self._config = config self.__input_handler = input_handler self.__commit = commit self.__object_cache = object_cache self.__input_mods = input_mods # Because it is possible that things are failing, there is the need to # have some defaults here: self.__complete_requirement_set = None self.__topic = None self.__requirement_set = None # First: read in all the requirements. self.__read_requirement_set() if not self.is_usable(): tracer.error("Errors during reading the requirements.") return # Second: read in all the topics. # Stored here is the initial node of the topic digraph. self.__topic = self.__read_topics() if not self.is_usable(): tracer.error("Errors during reading the topics.") return # Third: restrict requirements to those which are # needed in the topic. self.__requirement_set = self.__restrict_requirements_set() if not self.is_usable(): tracer.error("Errors during restriction of the requirements.") return tracer.debug("Finished.")
def rmttest_tsort_003(self): "One node digraph" dg = Digraph({"A": []}) tsort = topological_sort(dg) tnames = node_list_to_node_name_list(tsort) assert tnames == ["A"], "incorrect"
def rmttest_cc_001(self): "Connected digraph" digraph = Digraph({"A": ["B"], "B": ["C"], "C": []}) ccs = connected_components(digraph) self.assertEqual(1, ccs.get_length())
def rmttest_tsort_001(self): "Simple three node digraph" dg = Digraph({"A": ["B", "C"], "B": ["C"], "C": []}) tsort = topological_sort(dg) tnames = node_list_to_node_name_list(tsort) assert tnames == ['C', 'B', 'A'], "incorrect"
def rmttest_tsort_002(self): "Zero node digraph" dg = Digraph({}) tsort = topological_sort(dg) tnames = node_list_to_node_name_list(tsort) assert tnames == [], "incorrect"
def __init__(self): Digraph.__init__(self)
def rmttest_constructor_001(self): "Test conversion from dictionary to graph and back (two nodes)" d = {"A": ["B"], "B": []} dg = Digraph(d) e = dg.output_to_dict() self.assertEqual(d, e)
def rmttest_neg_01(self): "Node test: not find outgoing node which is not there" n = Digraph.Node() r = n.find_outgoing("nixdamit") assert r is None
def rmttest_find_02(self): "Digraph find with element not available" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = Digraph(d) n = dg.find("Z") self.assertIsNone(n)
def rmttest_constructor_004(self): "Test conversion from dict to graph and back (one node to itself)" d = {"A": ["A"]} dg = Digraph(d) e = dg.output_to_dict() self.assertEqual(d, e)
def rmttest_constructor_002(self): "Test conversion from dictionary to graph and back (zero nodes)" d = {} dg = Digraph(d) e = dg.output_to_dict() self.assertEqual(d, e)
def rmttest_constructor_005(self): "Test conversion: error: pointed node does not exists" d = {"A": ["B"]} with self.assertRaises(RMTException) as rmte: Digraph(d) self.assertEqual(24, rmte.id())
def rmttest_constructor_007(self): "Test conversion from dictionary: more complex graph" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = Digraph(d) e = dg.output_to_dict() self.assertEqual(d, e)
def rmttest_find_01(self): "Digraph find with element available" d = {"A": ["B"], "B": ["A", "C", "D"], "C": ["A", "D"], "D": ["D"]} dg = Digraph(d) n = dg.find("A") self.assertEqual("A", n.name)
def __init__(self, d=None): Digraph.__init__(self) if d != None: self.create_from_dict(d)
def rmttest_neg_02(self): "Node test: check if is_self_of_ancient is correct" n = Digraph.Node() r = n.is_self_of_ancient(None) assert not r
def rmttest_constructor_006(self): "Test conversion from dictionary: two node circle" d = {"A": ["B"], "B": ["A"]} dg = Digraph(d) e = dg.output_to_dict() self.assertEqual(d, e)
def __init__(self, d=None): Digraph.__init__( self, d, lambda nname: Requirement(None, nname, None, None, None))