Handle importing pkg.mod by executing

__import__('mod', {'__packaging__': 'pkg', level=1) w/o properly (and
thus not segfaulting).
This commit is contained in:
Brett Cannon 2012-04-14 21:50:00 -04:00
parent 59f9c3affc
commit 49f8d8b016
4 changed files with 276 additions and 253 deletions

View file

@ -193,6 +193,15 @@ class RelativeImports(unittest.TestCase):
self.assertEqual(module.__name__, '__runpy_pkg__.uncle.cousin')
self.relative_import_test(create, globals_, callback)
def test_import_relative_import_no_fromlist(self):
# Import a relative module w/ no fromlist.
create = ['crash.__init__', 'crash.mod']
globals_ = [{'__package__': 'crash', '__name__': 'crash'}]
def callback(global_):
import_util.import_('crash')
mod = import_util.import_('mod', global_, {}, [], 1)
self.assertEqual(mod.__name__, 'crash.mod')
self.relative_import_test(create, globals_, callback)
def test_main():