Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_compileall.CompileallTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def data
def recreation_check
def test_mtime
def test_magic_number
def test_compile_files
def test_no_pycache_in_non_package
def test_optimize

Public Attributes

 directory
 source_path
 bc_path
 source_path2
 bc_path2
 subdirectory
 source_path3

Detailed Description

Definition at line 16 of file test_compileall.py.


Member Function Documentation

Definition at line 35 of file test_compileall.py.

00035 
00036     def data(self):
00037         with open(self.bc_path, 'rb') as file:
00038             data = file.read(8)
00039         mtime = int(os.stat(self.source_path).st_mtime)
00040         compare = struct.pack('<4sl', imp.get_magic(), mtime)
00041         return data, compare

Here is the caller graph for this function:

Check that compileall recreates bytecode when the new metadata is
used.

Definition at line 42 of file test_compileall.py.

00042 
00043     def recreation_check(self, metadata):
00044         """Check that compileall recreates bytecode when the new metadata is
00045         used."""
00046         if not hasattr(os, 'stat'):
00047             return
00048         py_compile.compile(self.source_path)
00049         self.assertEqual(*self.data())
00050         with open(self.bc_path, 'rb') as file:
00051             bc = file.read()[len(metadata):]
00052         with open(self.bc_path, 'wb') as file:
00053             file.write(metadata)
00054             file.write(bc)
00055         self.assertNotEqual(*self.data())
00056         compileall.compile_dir(self.directory, force=False, quiet=True)
00057         self.assertTrue(*self.data())

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 18 of file test_compileall.py.

00018 
00019     def setUp(self):
00020         self.directory = tempfile.mkdtemp()
00021         self.source_path = os.path.join(self.directory, '_test.py')
00022         self.bc_path = imp.cache_from_source(self.source_path)
00023         with open(self.source_path, 'w') as file:
00024             file.write('x = 123\n')
00025         self.source_path2 = os.path.join(self.directory, '_test2.py')
00026         self.bc_path2 = imp.cache_from_source(self.source_path2)
00027         shutil.copyfile(self.source_path, self.source_path2)
00028         self.subdirectory = os.path.join(self.directory, '_subdir')
00029         os.mkdir(self.subdirectory)
00030         self.source_path3 = os.path.join(self.subdirectory, '_test3.py')
00031         shutil.copyfile(self.source_path, self.source_path3)

Here is the caller graph for this function:

Definition at line 32 of file test_compileall.py.

00032 
00033     def tearDown(self):
00034         shutil.rmtree(self.directory)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 66 of file test_compileall.py.

00066 
00067     def test_compile_files(self):
00068         # Test compiling a single file, and complete directory
00069         for fn in (self.bc_path, self.bc_path2):
00070             try:
00071                 os.unlink(fn)
00072             except:
00073                 pass
00074         compileall.compile_file(self.source_path, force=False, quiet=True)
00075         self.assertTrue(os.path.isfile(self.bc_path) and
00076                         not os.path.isfile(self.bc_path2))
00077         os.unlink(self.bc_path)
00078         compileall.compile_dir(self.directory, force=False, quiet=True)
00079         self.assertTrue(os.path.isfile(self.bc_path) and
00080                         os.path.isfile(self.bc_path2))
00081         os.unlink(self.bc_path)
00082         os.unlink(self.bc_path2)

Here is the call graph for this function:

Definition at line 62 of file test_compileall.py.

00062 
00063     def test_magic_number(self):
00064         # Test a change in mtime leads to a new .pyc.
00065         self.recreation_check(b'\0\0\0\0')

Here is the call graph for this function:

Definition at line 58 of file test_compileall.py.

00058 
00059     def test_mtime(self):
00060         # Test a change in mtime leads to a new .pyc.
00061         self.recreation_check(struct.pack('<4sl', imp.get_magic(), 1))

Here is the call graph for this function:

Definition at line 83 of file test_compileall.py.

00083 
00084     def test_no_pycache_in_non_package(self):
00085         # Bug 8563 reported that __pycache__ directories got created by
00086         # compile_file() for non-.py files.
00087         data_dir = os.path.join(self.directory, 'data')
00088         data_file = os.path.join(data_dir, 'file')
00089         os.mkdir(data_dir)
00090         # touch data/file
00091         with open(data_file, 'w'):
00092             pass
00093         compileall.compile_file(data_file)
00094         self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))

Here is the call graph for this function:

Definition at line 95 of file test_compileall.py.

00095 
00096     def test_optimize(self):
00097         # make sure compiling with different optimization settings than the
00098         # interpreter's creates the correct file names
00099         optimize = 1 if __debug__ else 0
00100         compileall.compile_dir(self.directory, quiet=True, optimize=optimize)
00101         cached = imp.cache_from_source(self.source_path,
00102                                        debug_override=not optimize)
00103         self.assertTrue(os.path.isfile(cached))
00104         cached2 = imp.cache_from_source(self.source_path2,
00105                                        debug_override=not optimize)
00106         self.assertTrue(os.path.isfile(cached2))
00107         cached3 = imp.cache_from_source(self.source_path3,
00108                                        debug_override=not optimize)
00109         self.assertTrue(os.path.isfile(cached3))
00110 

Here is the call graph for this function:


Member Data Documentation

Definition at line 21 of file test_compileall.py.

Definition at line 25 of file test_compileall.py.

Definition at line 19 of file test_compileall.py.

Definition at line 20 of file test_compileall.py.

Definition at line 24 of file test_compileall.py.

Definition at line 29 of file test_compileall.py.

Definition at line 27 of file test_compileall.py.


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