Beispiel #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",
    ])
Beispiel #2
0
def test_fold_module(source_files) -> None:
    """
    Test result with a set source files and a module to fold.
    """
    # Given
    conf_graph = {"fold_modules": ["amodule"]}
    drawer = Mock()
    use_case = DrawGraphUC(drawer, PARSER, source_files, conf_graph)

    # When
    use_case.run()

    # Then
    drawer.write.assert_called()  # type: ignore
    global_dep = drawer.write.call_args[0][0]

    assert global_dep == {
        "simple_module":
        set((
            Dependency(Module("module")),
            Dependency(Module("module.inside.module")),
            Dependency(Module("amodule")),
        )),
        "amodule":
        set((Dependency(Module("module")),
             Dependency(Module("module.inside.module")))),
    }
Beispiel #3
0
def test_hide_empty_config(mock_method, source_files) -> None:

    # Given
    drawer = Mock()
    config = {"fold_modules": ["module"]}
    use_case = DrawGraphUC(drawer, PARSER, source_files, config)

    # When
    use_case.run()

    # Then
    mock_method.assert_called_with(GLOBAL_DEPENDENCIES)
Beispiel #4
0
def test_hide_empty_dict(mock_method) -> None:

    # Given
    source_files: Iterator[SourceFile] = iter([])
    drawer = Mock()
    config = {"hide_modules": ["toto", "tata"]}
    use_case = DrawGraphUC(drawer, PARSER, source_files, config)

    # When
    use_case.run()

    # Then
    mock_method.assert_called_with({})
Beispiel #5
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()
Beispiel #6
0
def test_empty_source_files() -> None:
    """
    Test result with no source files given.
    """
    # Given
    source_files: Iterator[SourceFile] = iter([])
    drawer = Mock()
    use_case = DrawGraphUC(drawer, PARSER, source_files)

    # When
    use_case.run()

    # Then
    drawer.write.assert_called_with({})
Beispiel #7
0
def test_nominal(source_files) -> None:
    """
    Test result with a set source files.
    """
    # Given
    drawer = Mock()
    use_case = DrawGraphUC(drawer, PARSER, source_files)

    # When
    use_case.run()

    # Then
    drawer.write.assert_called()  # type: ignore
    global_dep = drawer.write.call_args[0][0]

    assert global_dep == GLOBAL_DEPENDENCIES
Beispiel #8
0
def test_pop_empty_module_from_dependencies(source_files) -> None:
    # Given
    drawer = Mock()
    config = {"hide_modules": ["module"]}
    use_case = DrawGraphUC(drawer, PARSER, source_files, config)

    # When
    use_case.run()

    # Then
    drawer.write.assert_called_with({
        "simple_module":
        set((Dependency(Module("amodule")), )),
        "amodule.local_module":
        set((Dependency(Module("amodule")),
             Dependency(Module("amodule.inside")))),
    })
Beispiel #9
0
def test_hide_nominal(source_files) -> None:
    # Given
    drawer = Mock()
    config = {"hide_modules": ["amodule"]}
    use_case = DrawGraphUC(drawer, PARSER, source_files, config)

    # When
    use_case.run()

    # Then
    drawer.write.assert_called()  # type: ignore
    global_dep = drawer.write.call_args[0][0]

    assert global_dep == {
        "simple_module":
        set((Dependency(Module("module")),
             Dependency(Module("module.inside.module"))))
    }
Beispiel #10
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)
Beispiel #11
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)