Back to index

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

List of all members.

Public Member Functions

def assertRunOK
def assertRunNotOK
def assertCompiled
def assertNotCompiled
def setUp
def test_no_args_compiles_path
def f
def test_legacy_paths
def test_multiple_runs
def test_force
def test_recursion_control
def test_quiet
def test_regexp
def test_multiple_dirs
def test_d_takes_exactly_one_dir
def test_d_compile_error
def test_d_runtime_error
def test_include_bad_file
def test_include_file_with_arg
def test_include_file_no_arg
def test_include_on_stdin
def test_compiles_as_much_as_possible
def test_invalid_arg_produces_message

Public Attributes

 directory
 pkgdir
 pkgdir_cachedir
 initfn
 barfn

Private Member Functions

def _cleanup

Detailed Description

Test compileall's CLI.

Definition at line 134 of file test_compileall.py.


Member Function Documentation

Definition at line 164 of file test_compileall.py.

00164 
00165     def _cleanup(self):
00166         support.rmtree(self.directory)

Here is the caller graph for this function:

Definition at line 148 of file test_compileall.py.

00148 
00149     def assertCompiled(self, fn):
00150         self.assertTrue(os.path.exists(imp.cache_from_source(fn)))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 151 of file test_compileall.py.

00151 
00152     def assertNotCompiled(self, fn):
00153         self.assertFalse(os.path.exists(imp.cache_from_source(fn)))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_compileall.CommandLineTests.assertRunNotOK (   self,
  args,
  env_vars 
)

Definition at line 143 of file test_compileall.py.

00143 
00144     def assertRunNotOK(self, *args, **env_vars):
00145         rc, out, err = script_helper.assert_python_failure(
00146                         '-S', '-m', 'compileall', *args, **env_vars)
00147         return rc, out, err

Here is the caller graph for this function:

def test.test_compileall.CommandLineTests.assertRunOK (   self,
  args,
  env_vars 
)

Definition at line 137 of file test_compileall.py.

00137 
00138     def assertRunOK(self, *args, **env_vars):
00139         rc, out, err = script_helper.assert_python_ok(
00140                         '-S', '-m', 'compileall', *args, **env_vars)
00141         self.assertEqual(b'', err)
00142         return out

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_compileall.CommandLineTests.f (   self,
  ext = ext,
  switch = switch 
)

Definition at line 182 of file test_compileall.py.

00182 
00183         def f(self, ext=ext, switch=switch):
00184             script_helper.assert_python_ok(*(switch +
00185                 ['-m', 'compileall', '-q', self.pkgdir]))
00186             # Verify the __pycache__ directory contents.
00187             self.assertTrue(os.path.exists(self.pkgdir_cachedir))
00188             expected = sorted(base.format(imp.get_tag(), ext) for base in
00189                               ('__init__.{}.{}', 'bar.{}.{}'))
00190             self.assertEqual(sorted(os.listdir(self.pkgdir_cachedir)), expected)
00191             # Make sure there are no .pyc files in the source directory.
00192             self.assertFalse([fn for fn in os.listdir(self.pkgdir)
                              if fn.endswith(ext)])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 154 of file test_compileall.py.

00154 
00155     def setUp(self):
00156         self.addCleanup(self._cleanup)
00157         self.directory = tempfile.mkdtemp()
00158         self.pkgdir = os.path.join(self.directory, 'foo')
00159         os.mkdir(self.pkgdir)
00160         self.pkgdir_cachedir = os.path.join(self.pkgdir, '__pycache__')
00161         # Create the __init__.py and a package module.
00162         self.initfn = script_helper.make_script(self.pkgdir, '__init__', '')
00163         self.barfn = script_helper.make_script(self.pkgdir, 'bar', '')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 337 of file test_compileall.py.

00337 
00338     def test_compiles_as_much_as_possible(self):
00339         bingfn = script_helper.make_script(self.pkgdir, 'bing', 'syntax(error')
00340         rc, out, err = self.assertRunNotOK('nosuchfile', self.initfn,
00341                                            bingfn, self.barfn)
00342         self.assertRegex(out, b'rror')
00343         self.assertNotCompiled(bingfn)
00344         self.assertCompiled(self.initfn)
00345         self.assertCompiled(self.barfn)

Here is the call graph for this function:

Definition at line 274 of file test_compileall.py.

00274 
00275     def test_d_compile_error(self):
00276         script_helper.make_script(self.pkgdir, 'crunchyfrog', 'bad(syntax')
00277         rc, out, err = self.assertRunNotOK('-q', '-d', 'dinsdale', self.pkgdir)
00278         self.assertRegex(out, b'File "dinsdale')

Here is the call graph for this function:

Definition at line 279 of file test_compileall.py.

00279 
00280     def test_d_runtime_error(self):
00281         bazfn = script_helper.make_script(self.pkgdir, 'baz', 'raise Exception')
00282         self.assertRunOK('-q', '-d', 'dinsdale', self.pkgdir)
00283         fn = script_helper.make_script(self.pkgdir, 'bing', 'import baz')
00284         pyc = imp.cache_from_source(bazfn)
00285         os.rename(pyc, os.path.join(self.pkgdir, 'baz.pyc'))
00286         os.remove(bazfn)
00287         rc, out, err = script_helper.assert_python_failure(fn)
00288         self.assertRegex(err, b'File "dinsdale')

Here is the call graph for this function:

Definition at line 266 of file test_compileall.py.

00266 
00267     def test_d_takes_exactly_one_dir(self):
00268         rc, out, err = self.assertRunNotOK('-d', 'foo')
00269         self.assertEqual(out, b'')
00270         self.assertRegex(err, b'-d')
00271         rc, out, err = self.assertRunNotOK('-d', 'foo', 'bar')
00272         self.assertEqual(out, b'')
00273         self.assertRegex(err, b'-d')

Here is the call graph for this function:

Definition at line 217 of file test_compileall.py.

00217 
00218     def test_force(self):
00219         self.assertRunOK('-q', self.pkgdir)
00220         pycpath = imp.cache_from_source(self.barfn)
00221         # set atime/mtime backward to avoid file timestamp resolution issues
00222         os.utime(pycpath, (time.time()-60,)*2)
00223         mtime = os.stat(pycpath).st_mtime
00224         # without force, no recompilation
00225         self.assertRunOK('-q', self.pkgdir)
00226         mtime2 = os.stat(pycpath).st_mtime
00227         self.assertEqual(mtime, mtime2)
00228         # now force it.
00229         self.assertRunOK('-q', '-f', self.pkgdir)
00230         mtime2 = os.stat(pycpath).st_mtime
00231         self.assertNotEqual(mtime, mtime2)

Here is the call graph for this function:

Definition at line 289 of file test_compileall.py.

00289 
00290     def test_include_bad_file(self):
00291         rc, out, err = self.assertRunNotOK(
00292             '-i', os.path.join(self.directory, 'nosuchfile'), self.pkgdir)
00293         self.assertRegex(out, b'rror.*nosuchfile')
00294         self.assertNotRegex(err, b'Traceback')
00295         self.assertFalse(os.path.exists(imp.cache_from_source(
00296                                             self.pkgdir_cachedir)))

Here is the call graph for this function:

Definition at line 311 of file test_compileall.py.

00311 
00312     def test_include_file_no_arg(self):
00313         f1 = script_helper.make_script(self.pkgdir, 'f1', '')
00314         f2 = script_helper.make_script(self.pkgdir, 'f2', '')
00315         f3 = script_helper.make_script(self.pkgdir, 'f3', '')
00316         f4 = script_helper.make_script(self.pkgdir, 'f4', '')
00317         with open(os.path.join(self.directory, 'l1'), 'w') as l1:
00318             l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
00319         self.assertRunOK('-i', os.path.join(self.directory, 'l1'))
00320         self.assertNotCompiled(f1)
00321         self.assertCompiled(f2)
00322         self.assertNotCompiled(f3)
00323         self.assertNotCompiled(f4)

Here is the call graph for this function:

Definition at line 297 of file test_compileall.py.

00297 
00298     def test_include_file_with_arg(self):
00299         f1 = script_helper.make_script(self.pkgdir, 'f1', '')
00300         f2 = script_helper.make_script(self.pkgdir, 'f2', '')
00301         f3 = script_helper.make_script(self.pkgdir, 'f3', '')
00302         f4 = script_helper.make_script(self.pkgdir, 'f4', '')
00303         with open(os.path.join(self.directory, 'l1'), 'w') as l1:
00304             l1.write(os.path.join(self.pkgdir, 'f1.py')+os.linesep)
00305             l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
00306         self.assertRunOK('-i', os.path.join(self.directory, 'l1'), f4)
00307         self.assertCompiled(f1)
00308         self.assertCompiled(f2)
00309         self.assertNotCompiled(f3)
00310         self.assertCompiled(f4)

Here is the call graph for this function:

Definition at line 324 of file test_compileall.py.

00324 
00325     def test_include_on_stdin(self):
00326         f1 = script_helper.make_script(self.pkgdir, 'f1', '')
00327         f2 = script_helper.make_script(self.pkgdir, 'f2', '')
00328         f3 = script_helper.make_script(self.pkgdir, 'f3', '')
00329         f4 = script_helper.make_script(self.pkgdir, 'f4', '')
00330         p = script_helper.spawn_python('-m', 'compileall', '-i', '-')
00331         p.stdin.write((f3+os.linesep).encode('ascii'))
00332         script_helper.kill_python(p)
00333         self.assertNotCompiled(f1)
00334         self.assertNotCompiled(f2)
00335         self.assertCompiled(f3)
00336         self.assertNotCompiled(f4)

Here is the call graph for this function:

Definition at line 346 of file test_compileall.py.

00346 
00347     def test_invalid_arg_produces_message(self):
00348         out = self.assertRunOK('badfilename')
00349         self.assertRegex(out, b"Can't list 'badfilename'")
00350 

Here is the call graph for this function:

Definition at line 195 of file test_compileall.py.

00195 
00196     def test_legacy_paths(self):
00197         # Ensure that with the proper switch, compileall leaves legacy
00198         # pyc/pyo files, and no __pycache__ directory.
00199         self.assertRunOK('-b', '-q', self.pkgdir)
00200         # Verify the __pycache__ directory contents.
00201         self.assertFalse(os.path.exists(self.pkgdir_cachedir))
00202         expected = sorted(['__init__.py', '__init__.pyc', 'bar.py', 'bar.pyc'])
00203         self.assertEqual(sorted(os.listdir(self.pkgdir)), expected)

Here is the call graph for this function:

Definition at line 255 of file test_compileall.py.

00255 
00256     def test_multiple_dirs(self):
00257         pkgdir2 = os.path.join(self.directory, 'foo2')
00258         os.mkdir(pkgdir2)
00259         init2fn = script_helper.make_script(pkgdir2, '__init__', '')
00260         bar2fn = script_helper.make_script(pkgdir2, 'bar2', '')
00261         self.assertRunOK('-q', self.pkgdir, pkgdir2)
00262         self.assertCompiled(self.initfn)
00263         self.assertCompiled(self.barfn)
00264         self.assertCompiled(init2fn)
00265         self.assertCompiled(bar2fn)

Here is the call graph for this function:

Definition at line 204 of file test_compileall.py.

00204 
00205     def test_multiple_runs(self):
00206         # Bug 8527 reported that multiple calls produced empty
00207         # __pycache__/__pycache__ directories.
00208         self.assertRunOK('-q', self.pkgdir)
00209         # Verify the __pycache__ directory contents.
00210         self.assertTrue(os.path.exists(self.pkgdir_cachedir))
00211         cachecachedir = os.path.join(self.pkgdir_cachedir, '__pycache__')
00212         self.assertFalse(os.path.exists(cachecachedir))
00213         # Call compileall again.
00214         self.assertRunOK('-q', self.pkgdir)
00215         self.assertTrue(os.path.exists(self.pkgdir_cachedir))
00216         self.assertFalse(os.path.exists(cachecachedir))

Here is the call graph for this function:

Definition at line 167 of file test_compileall.py.

00167 
00168     def test_no_args_compiles_path(self):
00169         # Note that -l is implied for the no args case.
00170         bazfn = script_helper.make_script(self.directory, 'baz', '')
00171         self.assertRunOK(PYTHONPATH=self.directory)
00172         self.assertCompiled(bazfn)
00173         self.assertNotCompiled(self.initfn)
00174         self.assertNotCompiled(self.barfn)

Here is the call graph for this function:

Definition at line 244 of file test_compileall.py.

00244 
00245     def test_quiet(self):
00246         noisy = self.assertRunOK(self.pkgdir)
00247         quiet = self.assertRunOK('-q', self.pkgdir)
00248         self.assertNotEqual(b'', noisy)
00249         self.assertEqual(b'', quiet)

Here is the call graph for this function:

Definition at line 232 of file test_compileall.py.

00232 
00233     def test_recursion_control(self):
00234         subpackage = os.path.join(self.pkgdir, 'spam')
00235         os.mkdir(subpackage)
00236         subinitfn = script_helper.make_script(subpackage, '__init__', '')
00237         hamfn = script_helper.make_script(subpackage, 'ham', '')
00238         self.assertRunOK('-q', '-l', self.pkgdir)
00239         self.assertNotCompiled(subinitfn)
00240         self.assertFalse(os.path.exists(os.path.join(subpackage, '__pycache__')))
00241         self.assertRunOK('-q', self.pkgdir)
00242         self.assertCompiled(subinitfn)
00243         self.assertCompiled(hamfn)

Here is the call graph for this function:

Definition at line 250 of file test_compileall.py.

00250 
00251     def test_regexp(self):
00252         self.assertRunOK('-q', '-x', r'ba[^\\/]*$', self.pkgdir)
00253         self.assertNotCompiled(self.barfn)
00254         self.assertCompiled(self.initfn)

Here is the call graph for this function:


Member Data Documentation

Definition at line 162 of file test_compileall.py.

Definition at line 156 of file test_compileall.py.

Definition at line 161 of file test_compileall.py.

Definition at line 157 of file test_compileall.py.

Definition at line 159 of file test_compileall.py.


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