How to use the importlab.utils.Tempdir function in importlab

To help you get started, we’ve selected a few importlab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / importlab / tests / test_resolve.py View on Github external
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)
github google / importlab / tests / test_output.py View on Github external
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)
github google / importlab / tests / test_fs.py View on Github external
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))
github google / importlab / tests / test_graph.py View on Github external
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))
github google / importlab / tests / test_resolve.py View on Github external
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),
                    "")
github google / importlab / tests / test_resolve.py View on Github external
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")
github google / importlab / tests / test_resolve.py View on Github external
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")