Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 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()
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 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 testNoTrivialEmptyDir(self):
f = fs.StoredFileSystem({"foo/a.py": True, "bar/b.py": True})
self.assertTrue(f.isdir("foo"))
self.assertTrue(f.isdir("bar"))
self.assertFalse(f.isdir(""))
def setUp(self):
self.py_fs = fs.StoredFileSystem(FILES)
self.pyi_fs = fs.PYIFileSystem(fs.StoredFileSystem(PYI_FILES))
self.path = [self.pyi_fs, self.py_fs]
def tearDown(self):
self.tempdir.teardown()
def testIsFile(self):
self.assertTrue(self.fs.isfile("a.py"))
self.assertTrue(self.fs.isfile("foo/c.py"))
self.assertFalse(self.fs.isfile("foo/b.py"))
def testIsDir(self):
self.assertTrue(self.fs.isdir("foo"))
self.assertTrue(self.fs.isdir(""))
self.assertFalse(self.fs.isdir("foo/c.py"))
self.assertFalse(self.fs.isdir("a.py"))
class LowercasingFileSystem(fs.RemappingFileSystem):
"""Remapping file system subclass for tests."""
def map_path(self, path):
return path.lower()
class TestRemappingFileSystem(unittest.TestCase):
"""Tests for RemappingFileSystem."""
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))