def test_local_import_case() -> None: """ Test code with local import case. """ # Given module = Module("module.toto") source_file = SourceFile(module=module, code=SourceCode(_LOCAL_CASE)) # When dependencies = get_dependencies(source_file, PARSER) # Then assert dependencies == _LOCAL_RESULT
def test_simple_case() -> None: """ Test simple code case. """ # Given module = Module("toto_program") source_file = SourceFile(module=module, code=SourceCode(_SIMPLE_CASE)) # When dependencies = get_dependencies(source_file, PARSER) # Then assert dependencies == _SIMPLE_RESULT
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 run(self) -> None: """ Build configuration from existing source files. """ global_dependencies: Dict[Module, Dependencies] = {} for source_file in self.source_files: dependencies = get_dependencies(source_file, self.parser) dependencies = self.std_lib_filter.filter(dependencies) global_dependencies[source_file.module] = dependencies dependency_rules = {} for module, dependencies in global_dependencies.items(): dependency_rules[str(module)] = [ ModuleWildcard(dependency.main_import) for dependency in dependencies ] self.printer.write(Configuration(dependency_rules))
def test_nominal() -> None: source_file = SourceFile( Module("string.string"), SourceCode("""package main import "fmt" import ( "go/parser" "go/module" "othermodule" ) import "amodule" """), ) assert get_dependencies(source_file, PARSER) == { Dependency("fmt"), Dependency("go/parser"), Dependency("go/module"), Dependency("othermodule"), Dependency("amodule"), }
def run(self) -> None: global_dependencies: GlobalDependencies = {} for source_file in self.source_files: module = Module(source_file.module.replace(".__init__", "")) dependencies = get_dependencies(source_file, self.parser) dependencies = self.std_lib_filter.filter(dependencies) global_dependencies[module] = dependencies global_dependencies = self._hide(global_dependencies) for fold_module in self.config.get("fold_modules", []): global_dependencies = _fold_dep(global_dependencies, fold_module) # To avoid a module to point itself, and make the graph more readable for module, deps in list(global_dependencies.items()): deps -= {dep for dep in deps if dep.main_import == module} if not global_dependencies[module]: global_dependencies.pop(module, None) self.drawer.write(global_dependencies)