summaryrefslogtreecommitdiff
path: root/Lib/test/test_compileall.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_compileall.py')
-rw-r--r--Lib/test/test_compileall.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
index ba9fe465f8..0505c521d1 100644
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -39,11 +39,10 @@ class CompileallTests(unittest.TestCase):
compare = struct.pack('<4sl', imp.get_magic(), mtime)
return data, compare
+ @unittest.skipUnless(hasattr(os, 'stat'), 'test needs os.stat()')
def recreation_check(self, metadata):
"""Check that compileall recreates bytecode when the new metadata is
used."""
- if not hasattr(os, 'stat'):
- return
py_compile.compile(self.source_path)
self.assertEqual(*self.data())
with open(self.bc_path, 'rb') as file:
@@ -178,6 +177,29 @@ class CommandLineTests(unittest.TestCase):
self.assertNotCompiled(self.initfn)
self.assertNotCompiled(self.barfn)
+ def test_no_args_respects_force_flag(self):
+ bazfn = script_helper.make_script(self.directory, 'baz', '')
+ self.assertRunOK(PYTHONPATH=self.directory)
+ pycpath = imp.cache_from_source(bazfn)
+ # Set atime/mtime backward to avoid file timestamp resolution issues
+ os.utime(pycpath, (time.time()-60,)*2)
+ mtime = os.stat(pycpath).st_mtime
+ # Without force, no recompilation
+ self.assertRunOK(PYTHONPATH=self.directory)
+ mtime2 = os.stat(pycpath).st_mtime
+ self.assertEqual(mtime, mtime2)
+ # Now force it.
+ self.assertRunOK('-f', PYTHONPATH=self.directory)
+ mtime2 = os.stat(pycpath).st_mtime
+ self.assertNotEqual(mtime, mtime2)
+
+ def test_no_args_respects_quiet_flag(self):
+ script_helper.make_script(self.directory, 'baz', '')
+ noisy = self.assertRunOK(PYTHONPATH=self.directory)
+ self.assertIn(b'Listing ', noisy)
+ quiet = self.assertRunOK('-q', PYTHONPATH=self.directory)
+ self.assertNotIn(b'Listing ', quiet)
+
# Ensure that the default behavior of compileall's CLI is to create
# PEP 3147 pyc/pyo files.
for name, ext, switch in [