def test_chains_that_reenter_imported_package_dont_stop_longer_chains_being_included( self, ): graph = ImportGraph() graph.add_module("green") graph.add_module("blue") # Chain that reenters imported package. graph.add_import(importer="green.foo", imported="blue.foo") graph.add_import(importer="blue.foo", imported="brown") graph.add_import(importer="brown", imported="blue.bar") # Long indirect import. graph.add_import(importer="green.foo", imported="yellow.four") graph.add_import(importer="yellow.four", imported="yellow.three") graph.add_import(importer="yellow.three", imported="yellow.two") graph.add_import(importer="yellow.two", imported="yellow.one") graph.add_import(importer="yellow.one", imported="blue.bar") result = graph.find_shortest_chains(importer="green", imported="blue") assert result == { ("green.foo", "blue.foo"), ( "green.foo", "yellow.four", "yellow.three", "yellow.two", "yellow.one", "blue.bar", ), }
def test_top_level_import(self): graph = ImportGraph() graph.add_import(importer="green", imported="blue") result = graph.find_shortest_chains(importer="green", imported="blue") assert result == {("green", "blue")}
def test_import_between_top_level_and_child(self): graph = ImportGraph() graph.add_module("blue") graph.add_import(importer="green", imported="blue.foo") result = graph.find_shortest_chains(importer="green", imported="blue") assert result == {("green", "blue.foo")}
def test_grandchildren_import(self): graph = ImportGraph() graph.add_module("green") graph.add_module("blue") graph.add_import(importer="green.foo.one", imported="blue.bar.two") result = graph.find_shortest_chains(importer="green", imported="blue") assert result == {("green.foo.one", "blue.bar.two")}
def test_no_results_in_reverse_direction(self): graph = ImportGraph() graph.add_module("green") graph.add_module("blue") graph.add_import(importer="green.foo", imported="blue.bar") result = graph.find_shortest_chains(importer="blue", imported="green") assert result == set()
def test_first_level_child_import(self): graph = ImportGraph() graph.add_module("green") graph.add_module("blue") graph.add_import(importer="green.foo", imported="blue.bar") result = graph.find_shortest_chains(importer="green", imported="blue") assert result == {("green.foo", "blue.bar")}
def test_short_indirect_import(self): graph = ImportGraph() graph.add_module("green") graph.add_module("blue") graph.add_import(importer="green.indirect", imported="purple") graph.add_import(importer="purple", imported="blue.foo") result = graph.find_shortest_chains(importer="green", imported="blue") assert result == {("green.indirect", "purple", "blue.foo")}
def test_long_indirect_import(self): graph = ImportGraph() graph.add_module("green") graph.add_module("blue") graph.add_import(importer="green.baz", imported="yellow.three") graph.add_import(importer="yellow.three", imported="yellow.two") graph.add_import(importer="yellow.two", imported="yellow.one") graph.add_import(importer="yellow.one", imported="blue.foo") result = graph.find_shortest_chains(importer="green", imported="blue") assert result == {("green.baz", "yellow.three", "yellow.two", "yellow.one", "blue.foo")}