Beispiel #1
0
 def create_build_use_case(self) -> BuildConfigurationUC:
     """
     Plumbing to make build use case working.
     """
     configuration_io = YamlConfigurationIO(self.args.output)
     code_parser = (PythonParser()
                    if self.args.lang in ["py", "python"] else GoParser())
     source_files = source_file_iterator(self.args.root_dir,
                                         self.args.lang[:2])
     return BuildConfigurationUC(configuration_io, code_parser,
                                 source_files, self.args.lang)
Beispiel #2
0
 def create_check_use_case(self) -> CheckDependenciesUC:
     """
     Plumbing to make check use case working.
     """
     configuration = YamlConfigurationIO(self.args.config).read()
     code_parser = (PythonParser() if configuration.lang
                    in ["py", "python"] else GoParser())
     report_printer = ReportPrinter()
     source_files = source_file_iterator(self.args.root_dir,
                                         configuration.lang[:2])
     return CheckDependenciesUC(configuration, report_printer, code_parser,
                                source_files)
Beispiel #3
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)
Beispiel #4
0
from dep_check.dependency_finder import get_dependencies
from dep_check.infra.go_parser import GoParser
from dep_check.models import Dependency, Module, SourceCode, SourceFile

PARSER = GoParser()


def test_empty() -> None:
    """
    Test empty code case.
    """
    # Given
    module = Module("")
    source_code = SourceCode("")
    source_file = SourceFile(module=module, code=source_code)

    # When
    dependencies = get_dependencies(source_file, PARSER)

    # Then
    assert dependencies == frozenset()


def test_nominal() -> None:
    source_file = SourceFile(
        Module("string.string"),
        SourceCode("""package main
    import "fmt"
    import (
        "go/parser"
        "go/module"