def test_add_import(add_module): graph = ImportGraph() a, b = "foo", "bar" # Adding the module should make no difference to the result. if add_module: graph.add_module(a) graph.add_import(importer=a, imported=b) assert {a, b} == graph.modules assert {b} == graph.find_modules_directly_imported_by(a) assert set() == graph.find_modules_directly_imported_by(b)
def test_remove_import(): graph = ImportGraph() a, b, c = "foo", "bar", "baz" graph.add_import(importer=a, imported=b) graph.add_import(importer=a, imported=c) graph.remove_import(importer=a, imported=b) assert {a, b, c} == graph.modules assert {c} == graph.find_modules_directly_imported_by(a)
def test_find_modules_directly_imported_by(): graph = ImportGraph() a, b, c = "foo", "bar", "baz" d, e, f = "foo.one", "bar.one", "baz.one" graph.add_import(importer=a, imported=b) graph.add_import(importer=a, imported=c) graph.add_import(importer=a, imported=d) graph.add_import(importer=b, imported=e) graph.add_import(importer=f, imported=a) assert {b, c, d} == graph.find_modules_directly_imported_by("foo")