Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(274967)

Delta Between Two Patch Sets: Lib/test/test_compileall.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 9 months ago
Right Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_codeop.py ('k') | Lib/test/test_compile.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import sys 1 import sys
2 import compileall 2 import compileall
3 import importlib.util 3 import importlib.util
4 import os 4 import os
5 import py_compile 5 import py_compile
6 import shutil 6 import shutil
7 import struct 7 import struct
8 import subprocess
9 import sys
10 import tempfile 8 import tempfile
11 import time 9 import time
12 import unittest 10 import unittest
13 import io 11 import io
14 12
15 from test import support, script_helper 13 from test import support, script_helper
16 14
17 class CompileallTests(unittest.TestCase): 15 class CompileallTests(unittest.TestCase):
18 16
19 def setUp(self): 17 def setUp(self):
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 def _cleanup(self): 171 def _cleanup(self):
174 support.rmtree(self.directory) 172 support.rmtree(self.directory)
175 173
176 def test_no_args_compiles_path(self): 174 def test_no_args_compiles_path(self):
177 # Note that -l is implied for the no args case. 175 # Note that -l is implied for the no args case.
178 bazfn = script_helper.make_script(self.directory, 'baz', '') 176 bazfn = script_helper.make_script(self.directory, 'baz', '')
179 self.assertRunOK(PYTHONPATH=self.directory) 177 self.assertRunOK(PYTHONPATH=self.directory)
180 self.assertCompiled(bazfn) 178 self.assertCompiled(bazfn)
181 self.assertNotCompiled(self.initfn) 179 self.assertNotCompiled(self.initfn)
182 self.assertNotCompiled(self.barfn) 180 self.assertNotCompiled(self.barfn)
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)
183 204
184 # Ensure that the default behavior of compileall's CLI is to create 205 # Ensure that the default behavior of compileall's CLI is to create
185 # PEP 3147 pyc/pyo files. 206 # PEP 3147 pyc/pyo files.
186 for name, ext, switch in [ 207 for name, ext, switch in [
187 ('normal', 'pyc', []), 208 ('normal', 'pyc', []),
188 ('optimize', 'pyo', ['-O']), 209 ('optimize', 'pyo', ['-O']),
189 ('doubleoptimize', 'pyo', ['-OO']), 210 ('doubleoptimize', 'pyo', ['-OO']),
190 ]: 211 ]:
191 def f(self, ext=ext, switch=switch): 212 def f(self, ext=ext, switch=switch):
192 script_helper.assert_python_ok(*(switch + 213 script_helper.assert_python_ok(*(switch +
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 self.assertCompiled(self.initfn) 375 self.assertCompiled(self.initfn)
355 self.assertCompiled(self.barfn) 376 self.assertCompiled(self.barfn)
356 377
357 def test_invalid_arg_produces_message(self): 378 def test_invalid_arg_produces_message(self):
358 out = self.assertRunOK('badfilename') 379 out = self.assertRunOK('badfilename')
359 self.assertRegex(out, b"Can't list 'badfilename'") 380 self.assertRegex(out, b"Can't list 'badfilename'")
360 381
361 382
362 if __name__ == "__main__": 383 if __name__ == "__main__":
363 unittest.main() 384 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+