Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testResolveRelativeSymbol(self):
# importing the Symbol object from baz/__init__.py while in baz/f.py
parent = resolve.Direct("baz/f.py", "baz.f")
imp = parsepy.ImportStatement(".Symbol", is_from=True)
r = resolve.Resolver(self.path, parent)
f = r.resolve_import(imp)
self.assertTrue(isinstance(f, resolve.Local))
self.assertEqual(f.path, "baz/__init__.py")
self.assertEqual(f.module_name, "baz")
def testGetAbsoluteName(self):
test_cases = [
("x.y", "a.b", "x.y.a.b"),
("", "a.b", "a.b"),
("x.y", ".a.b", "x.y.a.b"),
("x.y", "..a.b", "x.a.b"),
("x.y", "...a.b", "...a.b"),
]
for parent, name, expected in test_cases:
self.assertEqual(
resolve.get_absolute_name(parent, name),
expected)
g.add_file_recursive("a.py")
g.build()
self.assertEqual(g.ordered_deps_list(), [
("a.py", ["b.py", "c.py"]),
("b.py", ["d.py"]),
("c.py", []),
("d.py", [])])
self.assertEqual(g.get_all_unresolved(), set(["e"]))
sources = g.ordered_sorted_source_files()
self.check_order(sources, ["d.py"], ["b.py"], ["a.py"])
self.check_order(sources, ["c.py"], ["a.py"])
self.assertEqual(sorted(g.provenance.keys()),
["a.py", "b.py", "c.py", "d.py"])
# a.py is a directly added source
provenance = g.provenance["a.py"]
self.assertTrue(isinstance(provenance, resolve.Direct))
self.assertEqual(provenance.module_name, 'module.name')
# b.py came from fs1
self.assertEqual(g.provenance["b.py"].fs, "fs1")
def follow_file(self, f, seen, trim):
"""Whether to recurse into a file's dependencies."""
return (f not in self.graph.nodes and
f not in seen and
(not trim or
not isinstance(self.provenance[f],
(resolve.Builtin, resolve.System))))