Back to index

python3.2  3.2.2
Public Member Functions
importlib.test.import_.test_fromlist.HandlingFromlist Class Reference

List of all members.

Public Member Functions

def test_object
def test_unexistent_object
def test_module_from_package
def test_no_module_from_package
def test_empty_string
def basic_star_test
def test_using_star
def test_fromlist_as_tuple
def test_star_with_others

Detailed Description

Using fromlist triggers different actions based on what is being asked
of it.

If fromlist specifies an object on a module, nothing special happens
[object case]. This is even true if the object does not exist [bad object].

If a package is being imported, then what is listed in fromlist may be
treated as a module to be imported [module]. But once again, even if
something in fromlist does not exist as a module, no error is thrown
[no module]. And this extends to what is contained in __all__ when '*' is
imported [using *]. And '*' does not need to be the only name in the
fromlist [using * with others].

Definition at line 32 of file test_fromlist.py.


Member Function Documentation

Definition at line 87 of file test_fromlist.py.

00087 
00088     def basic_star_test(self, fromlist=['*']):
00089         # [using *]
00090         with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
00091             with util.import_state(meta_path=[mock]):
00092                 mock['pkg'].__all__ = ['module']
00093                 module = import_util.import_('pkg', fromlist=fromlist)
00094                 self.assertEqual(module.__name__, 'pkg')
00095                 self.assertTrue(hasattr(module, 'module'))
00096                 self.assertEqual(module.module.__name__, 'pkg.module')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 81 of file test_fromlist.py.

00081 
00082     def test_empty_string(self):
00083         with util.mock_modules('pkg.__init__', 'pkg.mod') as importer:
00084             with util.import_state(meta_path=[importer]):
00085                 module = import_util.import_('pkg.mod', fromlist=[''])
00086                 self.assertEqual(module.__name__, 'pkg.mod')

Here is the call graph for this function:

Definition at line 101 of file test_fromlist.py.

00101 
00102     def test_fromlist_as_tuple(self):
00103         self.basic_star_test(('*',))

Here is the call graph for this function:

Definition at line 64 of file test_fromlist.py.

00064 
00065     def test_module_from_package(self):
00066         # [module]
00067         with util.mock_modules('pkg.__init__', 'pkg.module') as importer:
00068             with util.import_state(meta_path=[importer]):
00069                 module = import_util.import_('pkg', fromlist=['module'])
00070                 self.assertEqual(module.__name__, 'pkg')
00071                 self.assertTrue(hasattr(module, 'module'))
00072                 self.assertEqual(module.module.__name__, 'pkg.module')

Here is the call graph for this function:

Definition at line 73 of file test_fromlist.py.

00073 
00074     def test_no_module_from_package(self):
00075         # [no module]
00076         with util.mock_modules('pkg.__init__') as importer:
00077             with util.import_state(meta_path=[importer]):
00078                 module = import_util.import_('pkg', fromlist='non_existent')
00079                 self.assertEqual(module.__name__, 'pkg')
00080                 self.assertTrue(not hasattr(module, 'non_existent'))

Here is the call graph for this function:

Definition at line 49 of file test_fromlist.py.

00049 
00050     def test_object(self):
00051         # [object case]
00052         with util.mock_modules('module') as importer:
00053             with util.import_state(meta_path=[importer]):
00054                 module = import_util.import_('module', fromlist=['attr'])
00055                 self.assertEqual(module.__name__, 'module')

Here is the call graph for this function:

Definition at line 104 of file test_fromlist.py.

00104 
00105     def test_star_with_others(self):
00106         # [using * with others]
00107         context = util.mock_modules('pkg.__init__', 'pkg.module1', 'pkg.module2')
00108         with context as mock:
00109             with util.import_state(meta_path=[mock]):
00110                 mock['pkg'].__all__ = ['module1']
00111                 module = import_util.import_('pkg', fromlist=['module2', '*'])
00112                 self.assertEqual(module.__name__, 'pkg')
00113                 self.assertTrue(hasattr(module, 'module1'))
00114                 self.assertTrue(hasattr(module, 'module2'))
00115                 self.assertEqual(module.module1.__name__, 'pkg.module1')
00116                 self.assertEqual(module.module2.__name__, 'pkg.module2')
00117 

Here is the call graph for this function:

Definition at line 56 of file test_fromlist.py.

00056 
00057     def test_unexistent_object(self):
00058         # [bad object]
00059         with util.mock_modules('module') as importer:
00060             with util.import_state(meta_path=[importer]):
00061                 module = import_util.import_('module', fromlist=['non_existent'])
00062                 self.assertEqual(module.__name__, 'module')
00063                 self.assertTrue(not hasattr(module, 'non_existent'))

Here is the call graph for this function:

Definition at line 97 of file test_fromlist.py.

00097 
00098     def test_using_star(self):
00099         # [using *]
00100         self.basic_star_test()

Here is the call graph for this function:


The documentation for this class was generated from the following file: