Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
importlib.test.source.test_abc_loader.SourceOnlyLoaderTests Class Reference
Inheritance diagram for importlib.test.source.test_abc_loader.SourceOnlyLoaderTests:
Inheritance graph
[legend]
Collaboration diagram for importlib.test.source.test_abc_loader.SourceOnlyLoaderTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_get_source
def test_is_package
def test_get_code
def test_load_module
def test_package_settings
def test_get_source_encoding
def setUp
def verify_module
def verify_code

Public Attributes

 package
 path
 name
 cached
 loader

Static Public Attributes

 loader_mock = SourceOnlyLoaderMock

Detailed Description

Test importlib.abc.SourceLoader for source-only loading.

Reload testing is subsumed by the tests for
importlib.util.module_for_loader.

Definition at line 576 of file test_abc_loader.py.


Member Function Documentation

def importlib.test.source.test_abc_loader.SourceLoaderTestHarness.setUp (   self,
  is_package = True,
  kwargs 
) [inherited]

Definition at line 540 of file test_abc_loader.py.

00540 
00541     def setUp(self, *, is_package=True, **kwargs):
00542         self.package = 'pkg'
00543         if is_package:
00544             self.path = os.path.join(self.package, '__init__.py')
00545             self.name = self.package
00546         else:
00547             module_name = 'mod'
00548             self.path = os.path.join(self.package, '.'.join(['mod', 'py']))
00549             self.name = '.'.join([self.package, module_name])
00550         self.cached = imp.cache_from_source(self.path)
00551         self.loader = self.loader_mock(self.path, **kwargs)

Here is the caller graph for this function:

Definition at line 605 of file test_abc_loader.py.

00605 
00606     def test_get_code(self):
00607         # Verify the code object is created.
00608         code_object = self.loader.get_code(self.name)
00609         self.verify_code(code_object)

Here is the call graph for this function:

Definition at line 587 of file test_abc_loader.py.

00587 
00588     def test_get_source(self):
00589         # Verify the source code is returned as a string.
00590         # If an IOError is raised by get_data then raise ImportError.
00591         expected_source = self.loader.source.decode('utf-8')
00592         self.assertEqual(self.loader.get_source(self.name), expected_source)
00593         def raise_IOError(path):
00594             raise IOError
00595         self.loader.get_data = raise_IOError
00596         with self.assertRaises(ImportError):
00597             self.loader.get_source(self.name)

Here is the call graph for this function:

Definition at line 630 of file test_abc_loader.py.

00630 
00631     def test_get_source_encoding(self):
00632         # Source is considered encoded in UTF-8 by default unless otherwise
00633         # specified by an encoding line.
00634         source = "_ = 'ü'"
00635         self.loader.source = source.encode('utf-8')
00636         returned_source = self.loader.get_source(self.name)
00637         self.assertEqual(returned_source, source)
00638         source = "# coding: latin-1\n_ = ü"
00639         self.loader.source = source.encode('latin-1')
00640         returned_source = self.loader.get_source(self.name)
00641         self.assertEqual(returned_source, source)
00642 
00643 
@unittest.skipIf(sys.dont_write_bytecode, "sys.dont_write_bytecode is true")

Here is the call graph for this function:

Definition at line 598 of file test_abc_loader.py.

00598 
00599     def test_is_package(self):
00600         # Properly detect when loading a package.
00601         self.setUp(is_package=True)
00602         self.assertTrue(self.loader.is_package(self.name))
00603         self.setUp(is_package=False)
00604         self.assertFalse(self.loader.is_package(self.name))

Here is the call graph for this function:

Definition at line 610 of file test_abc_loader.py.

00610 
00611     def test_load_module(self):
00612         # Loading a module should set __name__, __loader__, __package__,
00613         # __path__ (for packages), __file__, and __cached__.
00614         # The module should also be put into sys.modules.
00615         with util.uncache(self.name):
00616             module = self.loader.load_module(self.name)
00617             self.verify_module(module)
00618             self.assertEqual(module.__path__, [os.path.dirname(self.path)])
00619             self.assertTrue(self.name in sys.modules)

Here is the call graph for this function:

Definition at line 620 of file test_abc_loader.py.

00620 
00621     def test_package_settings(self):
00622         # __package__ needs to be set, while __path__ is set on if the module
00623         # is a package.
00624         # Testing the values for a package are covered by test_load_module.
00625         self.setUp(is_package=False)
00626         with util.uncache(self.name):
00627             module = self.loader.load_module(self.name)
00628             self.verify_module(module)
00629             self.assertTrue(not hasattr(module, '__path__'))

Here is the call graph for this function:

Definition at line 565 of file test_abc_loader.py.

00565 
00566     def verify_code(self, code_object):
00567         module = imp.new_module(self.name)
00568         module.__file__ = self.path
00569         module.__cached__ = self.cached
00570         module.__package__ = self.package
00571         module.__loader__ = self.loader
00572         module.__path__ = []
00573         exec(code_object, module.__dict__)
00574         self.verify_module(module)
00575 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 552 of file test_abc_loader.py.

00552 
00553     def verify_module(self, module):
00554         self.assertEqual(module.__name__, self.name)
00555         self.assertEqual(module.__file__, self.path)
00556         self.assertEqual(module.__cached__, self.cached)
00557         self.assertEqual(module.__package__, self.package)
00558         self.assertEqual(module.__loader__, self.loader)
00559         values = module._.split('::')
00560         self.assertEqual(values[0], self.name)
00561         self.assertEqual(values[1], self.path)
00562         self.assertEqual(values[2], self.cached)
00563         self.assertEqual(values[3], self.package)
00564         self.assertEqual(values[4], repr(self.loader))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 549 of file test_abc_loader.py.

Definition at line 550 of file test_abc_loader.py.

Definition at line 585 of file test_abc_loader.py.

Definition at line 544 of file test_abc_loader.py.

Definition at line 541 of file test_abc_loader.py.

Definition at line 543 of file test_abc_loader.py.


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