def testRelativeUpLevel(self): imp = imputil.Import('bar.foo') imp.add_binding(imputil.Import.MODULE, 'foo', 1) node = pythonparser.parse('from .. import foo').body[0] self._assert_imports_equal([imp], self.fred_importer.visit(node))
def testRelativeUpLevelMember(self): imp = imputil.Import('bar.foo') imp.add_binding(imputil.Import.MEMBER, 'qux', 'qux') node = pythonparser.parse('from ..foo import qux').body[0] self._assert_imports_equal([imp], self.fred_importer.visit(node))
def testImportFromNativeMultiple(self): imp = imputil.Import('fmt', is_native=True) imp.add_binding(imputil.Import.MEMBER, 'Printf', 'Printf') imp.add_binding(imputil.Import.MEMBER, 'Println', 'Println') self._check_imports('from __go__.fmt import Printf, Println', [imp])
def testImportFromNativeAs(self): imp = imputil.Import('fmt', is_native=True) imp.add_binding(imputil.Import.MEMBER, 'foo', 'Printf') self._check_imports('from __go__.fmt import Printf as foo', [imp])
def testImportFromAs(self): imp = imputil.Import('bar.baz') imp.add_binding(imputil.Import.MODULE, 'qux', 1) self._check_imports('from bar import baz as qux', [imp])
def testImportFromAsMembers(self): imp = imputil.Import('foo') imp.add_binding(imputil.Import.MEMBER, 'baz', 'bar') self._check_imports('from foo import bar as baz', [imp])
def testImportFromMultiple(self): imp1 = imputil.Import('bar.baz') imp1.add_binding(imputil.Import.MODULE, 'baz', 1) imp2 = imputil.Import('bar.foo') imp2.add_binding(imputil.Import.MODULE, 'foo', 1) self._check_imports('from bar import baz, foo', [imp1, imp2])
def testImportFromMixedMembers(self): imp1 = imputil.Import('bar') imp1.add_binding(imputil.Import.MEMBER, 'qux', 'qux') imp2 = imputil.Import('bar.baz') imp2.add_binding(imputil.Import.MODULE, 'baz', 1) self._check_imports('from bar import qux, baz', [imp1, imp2])
def testImportMultiple(self): imp1 = imputil.Import('foo') imp1.add_binding(imputil.Import.MODULE, 'foo', 0) imp2 = imputil.Import('bar.baz') imp2.add_binding(imputil.Import.MODULE, 'bar', 0) self._check_imports('import foo, bar.baz', [imp1, imp2])
def testImportAs(self): imp = imputil.Import('foo') imp.add_binding(imputil.Import.MODULE, 'bar', 0) self._check_imports('import foo as bar', [imp])
def testImportFromNativeAs(self): imp = imputil.Import('fmt', is_native=True) imp.add_binding(imputil.Import.MEMBER, 'foo', 'Printf') self._assert_imports_equal( imp, self._visit_import('from __go__.fmt import Printf as foo'))
def testImportFromAsMembers(self): imp = imputil.Import('foo') imp.add_binding(imputil.Import.MEMBER, 'baz', 'bar') path = MockPath(nonexistent_modules=('foo.bar', )) self._assert_imports_equal( imp, self._visit_import('from foo import bar as baz', path=path))
def testImportFromAs(self): imp = imputil.Import('foo.bar') imp.add_binding(imputil.Import.MODULE, 'baz', 1) self._assert_imports_equal( imp, self._visit_import('from foo import bar as baz'))
def testImportAs(self): imp = imputil.Import('foo') imp.add_binding(imputil.Import.MODULE, 'bar', 0) self._assert_imports_equal(imp, self._visit_import('import foo as bar'))
def testImportFromNative(self): imp = imputil.Import('__go__/fmt', is_native=True) imp.add_binding(imputil.Import.MEMBER, 'Printf', 'Printf') self._check_imports('from "__go__/fmt" import Printf', [imp])