def testResolveSystemRelative(self): with utils.Tempdir() as d: os_fs = fs.OSFileSystem(d.path) fspath = [os_fs] d.create_file("foo/x.py") d.create_file("foo/y.py") imp = parsepy.ImportStatement(".y") module = resolve.System(d["foo/x.py"], "foo.x") r = resolve.Resolver(fspath, module) f = r.resolve_import(imp) self.assertEqual(f.path, d["foo/y.py"]) self.assertTrue(isinstance(f, resolve.System)) self.assertEqual(f.module_name, "foo.y")
def test_trim(self): sources = [self.tempdir["x.py"]] mock_resolve_file = lambda f: resolve.System(f.path, f.module_name) with self.patch_resolve_import(mock_resolve_file): # Untrimmed g1 contains foo.b, the dep of system module foo.a. g1 = graph.ImportGraph.create(self.env, sources, trim=False) self.assertEqual( g1.sorted_source_files(), [[self.tempdir[x]] for x in ["foo/b.py", "foo/a.py", "x.py"]]) # Trimmed g2 stops at foo.a. g2 = graph.ImportGraph.create(self.env, sources, trim=True) self.assertEqual( g2.sorted_source_files(), [[self.tempdir[x]] for x in ["foo/a.py", "x.py"]])
def mock_resolve_file(f): path = os.path.splitext(f.path)[0] + ".so" return resolve.System(path, f.module_name)
deps.append((k, sorted(v))) return list(sorted(deps)) def ordered_sorted_source_files(self): return [list(sorted(x)) for x in self.sorted_source_files()] # Deps = { file : ([resolved deps], [broken deps], {dep_file:provenance}) } SIMPLE_DEPS = { "a.py": (["b.py", "c.py"], [], {"b.py": resolve.Local("b.py", "b", "fs1"), "c.py": resolve.Local("c.py", "c", "fs2") }), "b.py": (["d.py"], ["e"], {"d.py": resolve.System("d.py", "d")}) } SIMPLE_NONPY_DEPS = {"a.pyi": (["b.py"], [], {})} SIMPLE_CYCLIC_DEPS = { "a.py": (["b.py", "c.py"], ["e"], {}), "b.py": (["d.py", "a.py"], ["f"], {}), } SIMPLE_SYSTEM_DEPS = { "a.py": (["b.py"], [], {"b.py": resolve.System("b.py", "b")}), "b.py": (["c.py"], [], {"c.py": resolve.System("c.py", "c")}), }
def mock_resolve_import(resolver_self, item): resolved_file = resolve_import(resolver_self, item) return resolve.System(resolved_file.path, resolved_file.module_name)
deps.append((k, sorted(v))) return list(sorted(deps)) def ordered_sorted_source_files(self): return [list(sorted(x)) for x in self.sorted_source_files()] # Deps = { file : ([resolved deps], [broken deps], {dep_file:provenance}) } SIMPLE_DEPS = { "a.py": (["b.py", "c.py"], [], { "b.py": resolve.Local("b.py", "b", "fs1"), "c.py": resolve.Local("c.py", "c", "fs2") }), "b.py": (["d.py"], ["e"], { "d.py": resolve.System("d.py", "d") }) } SIMPLE_NONPY_DEPS = {"a.pyi": (["b.py"], [], {})} SIMPLE_CYCLIC_DEPS = { "a.py": (["b.py", "c.py"], ["e"], {}), "b.py": (["d.py", "a.py"], ["f"], {}), } SIMPLE_SYSTEM_DEPS = { "a.py": (["b.py"], [], { "b.py": resolve.System("b.py", "b") }), "b.py": (["c.py"], [], {
deps.append((k, sorted(v))) return list(sorted(deps)) def ordered_sorted_source_files(self): return [list(sorted(x)) for x in self.sorted_source_files()] # Deps = { file : ([resolved deps], [broken deps], {dep_file:provenance}) } SIMPLE_DEPS = { "a.py": (["b.py", "c.py"], [], { "b.py": resolve.Local("b.py", "b", "fs1"), "c.py": resolve.Local("c.py", "c", "fs2") }), "b.py": (["d.py"], ["e"], { "d.py": resolve.System("d.py", "d") }) } SIMPLE_CYCLIC_DEPS = { "a.py": (["b.py", "c.py"], ["e"], {}), "b.py": (["d.py", "a.py"], ["f"], {}), } class TestDependencyGraph(unittest.TestCase): """Tests for DependencyGraph.""" def check_order(self, xs, *args): """Checks that args form an increasing sequence within xs.""" indices = [xs.index(arg) for arg in args] for i in range(1, len(indices)):