330
331
# This should replicate 'import root-xxyyzz as root1'
331
332
InstrumentedImportReplacer(scope=globals(), name='root1',
332
module_path=self.root_name,
333
module_path=[self.root_name],
334
member=None, children=[])
336
336
self.assertEqual(InstrumentedImportReplacer,
337
337
object.__getattribute__(root1, '__class__'))
343
343
('_import', 'root1'),
344
344
('import', self.root_name, []),
347
def test_import_mod(self):
348
"""Test 'import root-XXX.mod-XXX as mod2'"""
352
# mod1 shouldn't exist yet
355
self.fail('mod1 was not supposed to exist yet')
357
mod_path = self.root_name + '.' + self.mod_name
358
InstrumentedImportReplacer(scope=globals(), name='mod1',
359
module_path=[self.root_name, self.mod_name],
360
member=None, children=[])
362
self.assertEqual(InstrumentedImportReplacer,
363
object.__getattribute__(mod1, '__class__'))
364
self.assertEqual(2, mod1.var2)
365
self.assertEqual('y', mod1.func2('y'))
367
self.assertEqual([('__getattribute__', 'var2'),
370
('import', mod_path, []),
373
def test_import_mod_from_root(self):
374
"""Test 'from root-XXX import mod-XXX as mod2'"""
378
# mod2 shouldn't exist yet
381
self.fail('mod2 was not supposed to exist yet')
383
InstrumentedImportReplacer(scope=globals(), name='mod2',
384
module_path=[self.root_name],
385
member=self.mod_name, children=[])
387
self.assertEqual(InstrumentedImportReplacer,
388
object.__getattribute__(mod2, '__class__'))
389
self.assertEqual(2, mod2.var2)
390
self.assertEqual('y', mod2.func2('y'))
392
self.assertEqual([('__getattribute__', 'var2'),
395
('import', self.root_name, [self.mod_name]),