def test_cycles_returns_empty_list_for_empty_graph(self): sut = Graph() sut.add_group("g1") cycles = sut.cycles() self.assertTrue(len(cycles) == 0)
def test_create_creates_empty_graph_for_empty_graph(self): empty_graph = Graph() cycle_graph = sut.create(Graph(), empty_graph, empty_graph.cycles()) nodes = cycle_graph.nodes() self.assertEqual(len(nodes), 0)
def __init__(self, projects): Graph.__init__(self) self._projects = projects numdeps = [len(p.imports()) for p in projects] max_numdeps = max(numdeps) if numdeps else 1 for project in projects: self._add_node_for_project(project, max_numdeps) self._add_edges_for_project(project, projects, max_numdeps)
def test_create_creates_empty_graph_for_graph_without_cycles(self): graph = Graph() graph.add_node("1") graph.add_node("2") graph.add_node("3") # cycle 1 graph.add_edge("1", "2") graph.add_edge("2", "3") cycle_graph = sut.create(Graph(), graph, graph.cycles()) nodes = cycle_graph.nodes() self.assertEqual(len(nodes), 0)
def __init__(self, packages): Graph.__init__(self) (top_level_elements, self._imports_for_fqn) = _collect_top_level_elements( packages ) self._elements_by_fqn = {tle.fqn: tle for tle in top_level_elements} for package in packages: self._add_package(package) for tle in top_level_elements: external_deps = set(_filter_external_types(tle)) # if type_ in simple_names for type_ in external_deps: self._add_dependency(tle, type_) if isinstance(tle, Class): if tle.extends: self._add_dependency(tle, tle.extends, arrowhead="white_delta") for interface in tle.implements: self._add_dependency( tle, interface, line_type="dotted", arrowhead="white_delta" ) if isinstance(tle, Interface): if tle.extends: self._add_dependency(tle, tle.extends, arrowhead="white_delta")
def test_cycles_returns_exp_for_one_cycle(self): sut = Graph() sut.add_node("1") sut.add_node("2") sut.add_node("3") sut.add_node("4") sut.add_edge("1", "2") sut.add_edge("2", "3") sut.add_edge("3", "1") sut.add_edge("3", "4") cycles = sut.cycles() self.assertTrue(len(cycles) == 1) self.assertEqual(cycles, [["3", "2", "1"]])
def test_cycles_returns_one_cycle_for_two_cyclic_connected_cycles(self): sut = Graph() sut.add_node("1") sut.add_node("2") sut.add_node("3") sut.add_node("4") sut.add_node("5") sut.add_node("6") sut.add_node("7") # cycle 1 sut.add_edge("1", "2") sut.add_edge("2", "3") sut.add_edge("3", "1") # cycle 2 sut.add_edge("4", "5") sut.add_edge("5", "6") sut.add_edge("6", "4") # connecting cycles sut.add_edge("3", "4") sut.add_edge("4", "3") cycles = sut.cycles() self.assertTrue(len(cycles) == 1) self.assertEqual(cycles, [["6", "5", "4", "3", "2", "1"]])
def test_cycles_returns_empty_list_for_empty_grouped_graph(self): sut = Graph() cycles = sut.cycles(grouped=True) self.assertTrue(len(cycles) == 0)
def test_cycles_are_supported_for_numerical_and_string_ids(self): sut = Graph() sut.add_node("alpha") sut.add_node(2) sut.add_node(3) sut.add_node("4") sut.add_node("5") # cycle 1 sut.add_edge("alpha", 2) sut.add_edge(2, 3) sut.add_edge(3, "alpha") sut.add_edge("4", "alpha") cycles = sut.cycles() self.assertEqual(cycles[0], [3, 2, "alpha"])
def __init__(self, bundles): Graph.__init__(self) self._logger = logging.getLogger(self.__class__.__name__) self._bundles = bundles self._bundles_for_exports = _map_bundles_on_exports(bundles) self._create_dependency_graph()
def __init__(self, packages): Graph.__init__(self) _packages = packages self._add_packages(packages) self._add_dependencies(packages)
def test_mark_cycle_marks_only_cyclic_edges(self): sut = Graph() sut.add_node("1") sut.add_node("2") sut.add_node("3") sut.add_node("4") sut.add_node("5") # cycle 1 sut.add_edge("1", "2") sut.add_edge("2", "3") sut.add_edge("3", "1") sut.add_edge("4", "1") sut.mark_cycles(sut.cycles()) edge_colors = [node.color for node in sut.edges().values()] self.assertEqual( edge_colors, [ self._exp_color_cycle, self._exp_color_cycle, self._exp_color_cycle, self._exp_color_non_cycle_edge, ], )
def test_create_creates_expected_graph_for_simple_cycle(self): graph = Graph() graph.add_node("1") graph.add_node("2") graph.add_node("3") graph.add_node("4") # cycle 1 graph.add_edge("1", "2") graph.add_edge("2", "3") graph.add_edge("3", "1") cycle_graph = sut.create(Graph(), graph, graph.cycles()) nodes = cycle_graph.nodes().values() self.assertEqual([node.label for node in nodes], ["3", "2", "1"])