def setUp(self): self.rootdir = tempfile.mkdtemp() self.pydir = os.path.join(self.rootdir, 'src', '__python__') self._materialize_tree( self.rootdir, {'src/': {'__python__/': self._PATH_SPEC}}) foo_script = os.path.join(self.rootdir, 'foo.py') self.importer = imputil.Importer(self.rootdir, 'foo', foo_script, False) bar_script = os.path.join(self.pydir, 'bar', '__init__.py') self.bar_importer = imputil.Importer( self.rootdir, 'bar', bar_script, False) fred_script = os.path.join(self.pydir, 'bar', 'fred', '__init__.py') self.fred_importer = imputil.Importer( self.rootdir, 'bar.fred', fred_script, False) self.foo_import = imputil.Import( 'foo', os.path.join(self.pydir, 'foo.py')) self.qux_import = imputil.Import( 'qux', os.path.join(self.pydir, 'qux.py')) self.bar_import = imputil.Import( 'bar', os.path.join(self.pydir, 'bar/__init__.py')) self.fred_import = imputil.Import( 'bar.fred', os.path.join(self.pydir, 'bar/fred/__init__.py')) self.quux_import = imputil.Import( 'bar.fred.quux', os.path.join(self.pydir, 'bar/fred/quux.py')) self.baz2_import = imputil.Import( 'bar.baz', os.path.join(self.pydir, 'bar/baz.py')) self.foo2_import = imputil.Import( 'bar.foo', os.path.join(self.pydir, 'bar/foo.py')) self.baz_import = imputil.Import( 'baz', os.path.join(self.pydir, 'baz.py'))
def testImportFromNativeAs(self): imp = imputil.Import('__go__/fmt', is_native=True) imp.add_binding(imputil.Import.MEMBER, 'foo', 'Printf') self._check_imports('from "__go__/fmt" import Printf as foo', [imp])
def testImportFromNativeMultiple(self): imp = imputil.Import('__go__/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])