Back to index

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

List of all members.

Public Member Functions

def verify_code
def test_code_with_everything
def test_no_bytecode
def test_code_bad_timestamp
def test_code_bad_magic
def test_dont_write_bytecode
def test_no_set_data
def test_set_data_raises_exceptions
def setUp
def verify_module
def verify_code

Public Attributes

 package
 path
 name
 cached
 loader

Static Public Attributes

 loader_mock = SourceLoaderMock

Detailed Description

Test importlib.abc.SourceLoader's use of bytecode.

Source-only testing handled by SourceOnlyLoaderTests.

Definition at line 644 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 690 of file test_abc_loader.py.

00690 
00691     def test_code_bad_magic(self):
00692         # Skip over bytecode with a bad magic number.
00693         self.setUp(magic=b'0000')
00694         # If bytecode is used then EOFError would be raised by marshal.
00695         self.loader.bytecode = self.loader.bytecode[8:]
00696         code_object = self.loader.get_code(self.name)
00697         self.verify_code(code_object, bytecode_written=True)

Here is the call graph for this function:

Definition at line 678 of file test_abc_loader.py.

00678 
00679     def test_code_bad_timestamp(self):
00680         # Bytecode is only used when the timestamp matches the source EXACTLY.
00681         for source_mtime in (0, 2):
00682             assert source_mtime != self.loader.source_mtime
00683             original = self.loader.source_mtime
00684             self.loader.source_mtime = source_mtime
00685             # If bytecode is used then EOFError would be raised by marshal.
00686             self.loader.bytecode = self.loader.bytecode[8:]
00687             code_object = self.loader.get_code(self.name)
00688             self.verify_code(code_object, bytecode_written=True)
00689             self.loader.source_mtime = original

Here is the call graph for this function:

Definition at line 663 of file test_abc_loader.py.

00663 
00664     def test_code_with_everything(self):
00665         # When everything should work.
00666         code_object = self.loader.get_code(self.name)
00667         self.verify_code(code_object)

Here is the call graph for this function:

Definition at line 698 of file test_abc_loader.py.

00698 
00699     def test_dont_write_bytecode(self):
00700         # Bytecode is not written if sys.dont_write_bytecode is true.
00701         # Can assume it is false already thanks to the skipIf class decorator.
00702         try:
00703             sys.dont_write_bytecode = True
00704             self.loader.bytecode_path = "<does not exist>"
00705             code_object = self.loader.get_code(self.name)
00706             self.assertNotIn(self.cached, self.loader.written)
00707         finally:
00708             sys.dont_write_bytecode = False

Here is the call graph for this function:

Definition at line 668 of file test_abc_loader.py.

00668 
00669     def test_no_bytecode(self):
00670         # If no bytecode exists then move on to the source.
00671         self.loader.bytecode_path = "<does not exist>"
00672         # Sanity check
00673         with self.assertRaises(IOError):
00674             bytecode_path = imp.cache_from_source(self.path)
00675             self.loader.get_data(bytecode_path)
00676         code_object = self.loader.get_code(self.name)
00677         self.verify_code(code_object, bytecode_written=True)

Here is the call graph for this function:

Definition at line 709 of file test_abc_loader.py.

00709 
00710     def test_no_set_data(self):
00711         # If set_data is not defined, one can still read bytecode.
00712         self.setUp(magic=b'0000')
00713         original_set_data = self.loader.__class__.set_data
00714         try:
00715             del self.loader.__class__.set_data
00716             code_object = self.loader.get_code(self.name)
00717             self.verify_code(code_object)
00718         finally:
00719             self.loader.__class__.set_data = original_set_data

Here is the call graph for this function:

Definition at line 720 of file test_abc_loader.py.

00720 
00721     def test_set_data_raises_exceptions(self):
00722         # Raising NotImplementedError or IOError is okay for set_data.
00723         def raise_exception(exc):
00724             def closure(*args, **kwargs):
00725                 raise exc
00726             return closure
00727 
00728         self.setUp(magic=b'0000')
00729         self.loader.set_data = raise_exception(NotImplementedError)
00730         code_object = self.loader.get_code(self.name)
00731         self.verify_code(code_object)
00732 

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:

def importlib.test.source.test_abc_loader.SourceLoaderBytecodeTests.verify_code (   self,
  code_object,
  bytecode_written = False 
)

Definition at line 654 of file test_abc_loader.py.

00654 
00655     def verify_code(self, code_object, *, bytecode_written=False):
00656         super().verify_code(code_object)
00657         if bytecode_written:
00658             self.assertIn(self.cached, self.loader.written)
00659             data = bytearray(imp.get_magic())
00660             data.extend(marshal._w_long(self.loader.source_mtime))
00661             data.extend(marshal.dumps(code_object))
00662             self.assertEqual(self.loader.written[self.cached], bytes(data))

Here is the call 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 652 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: