Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testResolveSystemPackageDir(self):
with utils.Tempdir() as d:
py_file = d.create_file("foo/__init__.py")
imp = parsepy.ImportStatement("foo",
source=d["foo"],
is_from=True)
r = self.make_resolver("x.py", "x")
f = r.resolve_import(imp)
self.assertTrue(isinstance(f, resolve.System))
self.assertEqual(f.module_name, "foo")
self.assertEqual(f.path, py_file)
def setUp(self):
self.tempdir = utils.Tempdir()
self.tempdir.setup()
filenames = [
self.tempdir.create_file(f, FILES[f])
for f in FILES]
self.fs = fs.OSFileSystem(self.tempdir.path)
env = environment.Environment(fs.Path([self.fs]), (3, 6))
self.graph = graph.ImportGraph.create(env, filenames)
def setUp(self):
self.tempdir = utils.Tempdir()
self.tempdir.setup()
for f in FILES:
self.tempdir.create_file(f, FILES[f])
self.fs = LowercasingFileSystem(
fs.OSFileSystem(self.tempdir.path))
def setUp(self):
self.tempdir = utils.Tempdir()
self.tempdir.setup()
self.filenames = [
self.tempdir.create_file(f, FILES[f])
for f in FILES]
self.fs = fs.OSFileSystem(self.tempdir.path)
self.env = environment.Environment(fs.Path([self.fs]), (3, 6))
def testInferModuleName(self):
with utils.Tempdir() as d:
os_fs = fs.OSFileSystem(d.path)
fspath = [os_fs]
py_file = d.create_file("foo/bar.py")
self.assertEqual(
resolve.infer_module_name(py_file, fspath),
"foo.bar")
# Standalone Python scripts often don't have extensions.
self.assertEqual(
resolve.infer_module_name(d["foo/baz"], fspath),
"foo.baz")
self.assertEqual(
resolve.infer_module_name(d["random/src.py"], fspath),
"random.src")
self.assertEqual(
resolve.infer_module_name("/some/random/file", fspath),
"")
def testGetPyFromPycSource(self):
# Override a source pyc file with the corresponding py file if it exists
# in the native filesystem.
with utils.Tempdir() as d:
py_file = d.create_file("f.py")
pyc_file = d.create_file("f.pyc")
imp = parsepy.ImportStatement("f", source=pyc_file)
r = self.make_resolver("x.py", "x")
f = r.resolve_import(imp)
self.assertEqual(f.path, py_file)
self.assertEqual(f.module_name, "f")
def testInferInitModuleName(self):
with utils.Tempdir() as d:
os_fs = fs.OSFileSystem(d.path)
fspath = [os_fs]
py_file = d.create_file("foo/__init__.py")
self.assertEqual(
resolve.infer_module_name(py_file, fspath),
"foo")