def test_find_shortest_chain_returns_none_if_not_exists(): graph = ImportGraph() a, b, c = "foo", "bar", "baz" graph.add_import(importer=a, imported=b) graph.add_import(importer=b, imported=c) assert None is graph.find_shortest_chain(importer=c, imported=a)
def test_find_shortest_chain_when_exists(): graph = ImportGraph() a, b, c = "foo", "bar", "baz" d, e, f = "long", "way", "around" # Add short path. graph.add_import(importer=a, imported=b) graph.add_import(importer=b, imported=c) # Add longer path. graph.add_import(importer=a, imported=d) graph.add_import(importer=d, imported=e) graph.add_import(importer=e, imported=f) graph.add_import(importer=f, imported=c) assert (a, b, c) == graph.find_shortest_chain(importer=a, imported=c)