예제 #1
0
def test_dot() -> None:
    """
    Test that the dot file is well generated
    """
    # Given
    source_files: Iterator[SourceFile] = iter([SIMPLE_FILE])
    drawer = GraphDrawer(Graph("tests/graph.svg"))
    use_case = DrawGraphUC(drawer, PARSER, source_files)

    # When
    use_case.run()

    # Then
    with open("/tmp/graph.dot", encoding="utf-8") as dot:
        lines = sorted(dot.readlines())

    assert lines == sorted([
        "digraph G {\n",
        "splines=true;\n",
        f"node[shape=box fontname=Arial style=filled fillcolor={drawer.graph.node_color}];\n",
        f"bgcolor={drawer.graph.background_color}\n",
        "\n",
        '"simple_module" -> "module"\n',
        '"simple_module" -> "module.inside.module"\n',
        '"simple_module" -> "amodule"\n',
        "}\n",
    ])
예제 #2
0
    def create_graph_use_case(self) -> DrawGraphUC:
        """
        Plumbing to make draw_graph use case working.
        """
        graph_conf = read_graph_config(self.args.config) if self.args.config else None

        code_parser = PythonParser()
        source_files = source_file_iterator(self.args.root_dir)
        graph = Graph(self.args.output, graph_conf)
        graph_drawer = GraphDrawer(graph)
        return DrawGraphUC(graph_drawer, code_parser, source_files, graph_conf)
예제 #3
0
def test_not_svg_with_dot(mock_method) -> None:
    """
    Test that no svg file is created when .dot in argument
    """
    # Given
    source_files: Iterator[SourceFile] = iter([SIMPLE_FILE])
    drawer = GraphDrawer(Graph("tests/graph.dot"))
    use_case = DrawGraphUC(drawer, PARSER, source_files)

    # When
    use_case.run()

    # Then
    mock_method.assert_not_called()
예제 #4
0
    def create_graph_use_case(self) -> DrawGraphUC:
        """
        Plumbing to make draw_graph use case working.
        """
        graph_conf = read_graph_config(self.args.config) if self.args.config else None

        if self.args.lang:
            lang = self.args.lang
        elif graph_conf and "lang" in graph_conf:
            lang = graph_conf["lang"]
        else:
            lang = "python"

        code_parser = PythonParser() if lang in ["py", "python"] else GoParser()
        source_files = source_file_iterator(self.args.root_dir, lang[:2])
        graph = Graph(self.args.output, graph_conf)
        graph_drawer = GraphDrawer(graph)
        return DrawGraphUC(graph_drawer, code_parser, source_files, graph_conf)