How to use the importlab.parsepy.ImportStatement 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_parsepy.py View on Github external
def test_dotted_from(self):
        self.assertEqual(self.parse("""
      from a.b.c import d as e
    """), [parsepy.ImportStatement(name='a.b.c.d', new_name='e', is_from=True)])
github google / importlab / tests / test_parsepy.py View on Github external
def test_multiple_3(self):
        self.assertEqual(self.parse("""
      import a, b as bb, a.x, a.x.y as a_x_y
    """), [parsepy.ImportStatement(name='a'),
           parsepy.ImportStatement(name='b', new_name='bb'),
           parsepy.ImportStatement(name='a.x', new_name='a.x'),
           parsepy.ImportStatement(name='a.x.y', new_name='a_x_y'),
           ])
github google / importlab / tests / test_resolve.py View on Github external
def testResolveParentPackageFile(self):
        imp = parsepy.ImportStatement("..a")
        r = self.make_resolver("foo/d.py", "foo.d")
        f = r.resolve_import(imp)
        self.assertEqual(f.path, "a.py")
        self.assertTrue(isinstance(f, resolve.Local))
        self.assertEqual(f.module_name, "..a")
github google / importlab / tests / test_parsepy.py View on Github external
def test_from(self):
        self.assertEqual(self.parse("""
      from a import b
    """), [parsepy.ImportStatement(name='a.b', new_name='b', is_from=True)])
github google / importlab / tests / test_resolve.py View on Github external
def testResolveSystemSymbol(self):
        imp = parsepy.ImportStatement("argparse.ArgumentParser",
                                      source="/system/argparse.pyc",
                                      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, "argparse")
github google / importlab / tests / test_parsepy.py View on Github external
def test_from_with_rename(self):
        self.assertEqual(self.parse("""
      from a import b as c
    """), [parsepy.ImportStatement(name='a.b', new_name='c', is_from=True)])
github google / importlab / tests / test_resolve.py View on Github external
def testResolveModuleFromFile(self):
        # from foo import c
        imp = parsepy.ImportStatement("foo.c", is_from=True)
        r = self.make_resolver("x.py", "x")
        f = r.resolve_import(imp)
        self.assertEqual(f.path, "foo/c.py")
        self.assertEqual(f.module_name, "foo.c")
github google / importlab / tests / test_resolve.py View on Github external
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")
github google / importlab / tests / test_resolve.py View on Github external
def testResolvePyiFile(self):
        imp = parsepy.ImportStatement("x")
        r = self.make_resolver("b.py", "b")
        f = r.resolve_import(imp)
        self.assertTrue(isinstance(f, resolve.Local))
        self.assertEqual(f.fs, self.pyi_fs)
        self.assertEqual(f.path, "x.pyi")
        self.assertEqual(f.module_name, "x")
github google / importlab / tests / test_resolve.py View on Github external
def testResolveSystemInitFile(self):
        # from foo.foo import foo
        imp = parsepy.ImportStatement("foo.bar.X",
                                      source="/system/foo/bar/__init__.pyc",
                                      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.bar")