|
5 | 5 | import py_compile |
6 | 6 | import shutil |
7 | 7 | import struct |
8 | | -import subprocess |
9 | | -import sys |
10 | 8 | import tempfile |
11 | 9 | import time |
12 | 10 | import unittest |
@@ -181,6 +179,29 @@ def test_no_args_compiles_path(self): |
181 | 179 | self.assertNotCompiled(self.initfn) |
182 | 180 | self.assertNotCompiled(self.barfn) |
183 | 181 |
|
| 182 | + def test_no_args_respects_force_flag(self): |
| 183 | + bazfn = script_helper.make_script(self.directory, 'baz', '') |
| 184 | + self.assertRunOK(PYTHONPATH=self.directory) |
| 185 | + pycpath = importlib.util.cache_from_source(bazfn) |
| 186 | + # Set atime/mtime backward to avoid file timestamp resolution issues |
| 187 | + os.utime(pycpath, (time.time()-60,)*2) |
| 188 | + mtime = os.stat(pycpath).st_mtime |
| 189 | + # Without force, no recompilation |
| 190 | + self.assertRunOK(PYTHONPATH=self.directory) |
| 191 | + mtime2 = os.stat(pycpath).st_mtime |
| 192 | + self.assertEqual(mtime, mtime2) |
| 193 | + # Now force it. |
| 194 | + self.assertRunOK('-f', PYTHONPATH=self.directory) |
| 195 | + mtime2 = os.stat(pycpath).st_mtime |
| 196 | + self.assertNotEqual(mtime, mtime2) |
| 197 | + |
| 198 | + def test_no_args_respects_quiet_flag(self): |
| 199 | + script_helper.make_script(self.directory, 'baz', '') |
| 200 | + noisy = self.assertRunOK(PYTHONPATH=self.directory) |
| 201 | + self.assertIn(b'Listing ', noisy) |
| 202 | + quiet = self.assertRunOK('-q', PYTHONPATH=self.directory) |
| 203 | + self.assertNotIn(b'Listing ', quiet) |
| 204 | + |
184 | 205 | # Ensure that the default behavior of compileall's CLI is to create |
185 | 206 | # PEP 3147 pyc/pyo files. |
186 | 207 | for name, ext, switch in [ |
|
0 commit comments