def test_does_nothing_if_module_is_already_squashed(self): graph = ImportGraph() graph.add_module("foo", is_squashed=True) graph.add_import(importer="foo", imported="bar") graph.squash_module("foo") assert graph.direct_import_exists(importer="foo", imported="bar")
def test_doesnt_error_if_imports_within_module(self): graph = ImportGraph() for module in [ "foo", "foo.green", "foo.blue", ]: graph.add_module(module) graph.add_import(importer="foo.blue", imported="foo.green") graph.squash_module("foo")
def test_marks_module_as_squashed(self): graph = ImportGraph() modules_to_squash = { "foo", "foo.green", } for module in modules_to_squash: graph.add_module(module) graph.squash_module("foo") assert graph.is_module_squashed("foo")
def test_contracts_import_to_descendant(self): graph = ImportGraph() for module in [ "foo", "foo.green", "bar.blue", ]: graph.add_module(module) graph.add_import(importer="bar.blue", imported="foo.green") graph.squash_module("foo") assert graph.direct_import_exists(importer="bar.blue", imported="foo")
def test_keeps_import_of_squashed_root(self): graph = ImportGraph() for module in [ "foo", "foo.green", "bar.blue", ]: graph.add_module(module) graph.add_import(importer="bar.blue", imported="foo") graph.squash_module("foo") assert graph.direct_import_exists(importer="bar.blue", imported="foo")
def test_updates_modules_in_graph(self): graph = ImportGraph() modules_to_squash = { "foo", "foo.green", "foo.blue", "foo.blue.alpha", } other_modules = { "bar", "bar.black", "baz", } for module in modules_to_squash | other_modules: graph.add_module(module) graph.squash_module("foo") assert {"foo"} | other_modules == graph.modules
def test_import_details_to_descendant_are_lost(self): graph = ImportGraph() for module in [ "foo", "foo.green", "bar.blue", ]: graph.add_module(module) graph.add_import( importer="bar.blue", imported="foo.green", line_number=1, line_contents="from foo import green", ) graph.squash_module("foo") assert [] == graph.get_import_details(importer="bar.blue", imported="foo")
def test_import_details_from_squashed_root_are_preserved(self): graph = ImportGraph() for module in [ "foo", "foo.green", "bar.blue", ]: graph.add_module(module) import_details = dict( importer="foo", imported="bar.blue", line_number=1, line_contents="from . import bar", ) graph.add_import(**import_details) graph.squash_module("foo") assert [import_details ] == graph.get_import_details(importer="foo", imported="bar.blue")
def test_raises_module_not_present_if_no_module(self): graph = ImportGraph() with pytest.raises(ModuleNotPresent): graph.squash_module("foo")