blob: 205457f3b4801e7a710fe1e7071f8638bc1cae38 [file] [log] [blame]
Martin v. Löwis4b003072010-03-16 13:19:21 +00001import sys
Brett Cannonbefb14f2009-02-10 02:10:16 +00002import compileall
Brett Cannon7822e122013-06-14 23:04:02 -04003import importlib.util
Brett Cannon1e3c3e92015-12-27 13:17:04 -08004import test.test_importlib.util
Brett Cannonbefb14f2009-02-10 02:10:16 +00005import os
Brett Cannon65ed7502015-10-09 15:09:43 -07006import pathlib
Brett Cannonbefb14f2009-02-10 02:10:16 +00007import py_compile
8import shutil
9import struct
Brett Cannonbefb14f2009-02-10 02:10:16 +000010import tempfile
R. David Murray650f1472010-11-20 21:18:51 +000011import time
Brett Cannonbefb14f2009-02-10 02:10:16 +000012import unittest
Martin v. Löwis4b003072010-03-16 13:19:21 +000013import io
Petr Viktorin4267c982019-09-26 11:53:51 +020014import errno
Brett Cannonbefb14f2009-02-10 02:10:16 +000015
Brett Cannonf1a8df02014-09-12 10:39:48 -040016from unittest import mock, skipUnless
17try:
18 from concurrent.futures import ProcessPoolExecutor
19 _have_multiprocessing = True
20except ImportError:
21 _have_multiprocessing = False
22
Berker Peksagce643912015-05-06 06:33:17 +030023from test import support
24from test.support import script_helper
Brett Cannonbefb14f2009-02-10 02:10:16 +000025
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -040026from .test_py_compile import without_source_date_epoch
27from .test_py_compile import SourceDateEpochTestMeta
28
29
30class CompileallTestsBase:
Brett Cannonbefb14f2009-02-10 02:10:16 +000031
32 def setUp(self):
33 self.directory = tempfile.mkdtemp()
34 self.source_path = os.path.join(self.directory, '_test.py')
Brett Cannon7822e122013-06-14 23:04:02 -040035 self.bc_path = importlib.util.cache_from_source(self.source_path)
Brett Cannonbefb14f2009-02-10 02:10:16 +000036 with open(self.source_path, 'w') as file:
37 file.write('x = 123\n')
Matthias Klosec33b9022010-03-16 00:36:26 +000038 self.source_path2 = os.path.join(self.directory, '_test2.py')
Brett Cannon7822e122013-06-14 23:04:02 -040039 self.bc_path2 = importlib.util.cache_from_source(self.source_path2)
Matthias Klosec33b9022010-03-16 00:36:26 +000040 shutil.copyfile(self.source_path, self.source_path2)
Georg Brandl45438462011-02-07 12:36:54 +000041 self.subdirectory = os.path.join(self.directory, '_subdir')
42 os.mkdir(self.subdirectory)
43 self.source_path3 = os.path.join(self.subdirectory, '_test3.py')
44 shutil.copyfile(self.source_path, self.source_path3)
Brett Cannonbefb14f2009-02-10 02:10:16 +000045
46 def tearDown(self):
47 shutil.rmtree(self.directory)
48
Petr Viktorin4267c982019-09-26 11:53:51 +020049 def create_long_path(self):
50 long_path = os.path.join(self.directory, "long")
51
52 # Create a long path, 10 directories at a time.
53 # It will be 100 directories deep, or shorter if the OS limits it.
54 for i in range(10):
55 longer_path = os.path.join(
56 long_path, *(f"long_directory_{i}_{j}" for j in range(10))
57 )
58
59 # Check if we can open __pycache__/*.pyc.
60 # Also, put in the source file that we want to compile
61 longer_source = os.path.join(longer_path, '_test_long.py')
62 longer_cache = importlib.util.cache_from_source(longer_source)
63 try:
64 os.makedirs(longer_path)
65 shutil.copyfile(self.source_path, longer_source)
66 os.makedirs(os.path.dirname(longer_cache))
67 # Make sure we can write to the cache
68 with open(longer_cache, 'w'):
69 pass
70 except FileNotFoundError:
71 # On Windows, a FileNotFoundError("The filename or extension
72 # is too long") is raised for long paths
73 if sys.platform == "win32":
74 break
75 else:
76 raise
77 except OSError as exc:
78 if exc.errno == errno.ENAMETOOLONG:
79 break
80 else:
81 raise
82
83 # Remove the __pycache__
84 shutil.rmtree(os.path.dirname(longer_cache))
85
86 long_path = longer_path
87 long_source = longer_source
88 long_cache = longer_cache
89
90 if i < 2:
91 raise ValueError('Path limit is too short')
92
93 self.source_path_long = long_source
94 self.bc_path_long = long_cache
95
Brett Cannon1e3c3e92015-12-27 13:17:04 -080096 def add_bad_source_file(self):
97 self.bad_source_path = os.path.join(self.directory, '_test_bad.py')
98 with open(self.bad_source_path, 'w') as file:
99 file.write('x (\n')
100
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400101 def timestamp_metadata(self):
Brett Cannonbefb14f2009-02-10 02:10:16 +0000102 with open(self.bc_path, 'rb') as file:
Benjamin Peterson42aa93b2017-12-09 10:26:52 -0800103 data = file.read(12)
Brett Cannonbefb14f2009-02-10 02:10:16 +0000104 mtime = int(os.stat(self.source_path).st_mtime)
Benjamin Peterson42aa93b2017-12-09 10:26:52 -0800105 compare = struct.pack('<4sll', importlib.util.MAGIC_NUMBER, 0, mtime)
Brett Cannonbefb14f2009-02-10 02:10:16 +0000106 return data, compare
107
108 def recreation_check(self, metadata):
109 """Check that compileall recreates bytecode when the new metadata is
110 used."""
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400111 if os.environ.get('SOURCE_DATE_EPOCH'):
112 raise unittest.SkipTest('SOURCE_DATE_EPOCH is set')
Brett Cannonbefb14f2009-02-10 02:10:16 +0000113 py_compile.compile(self.source_path)
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400114 self.assertEqual(*self.timestamp_metadata())
Brett Cannonbefb14f2009-02-10 02:10:16 +0000115 with open(self.bc_path, 'rb') as file:
116 bc = file.read()[len(metadata):]
117 with open(self.bc_path, 'wb') as file:
118 file.write(metadata)
119 file.write(bc)
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400120 self.assertNotEqual(*self.timestamp_metadata())
Brett Cannonbefb14f2009-02-10 02:10:16 +0000121 compileall.compile_dir(self.directory, force=False, quiet=True)
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400122 self.assertTrue(*self.timestamp_metadata())
Brett Cannonbefb14f2009-02-10 02:10:16 +0000123
124 def test_mtime(self):
125 # Test a change in mtime leads to a new .pyc.
Benjamin Peterson42aa93b2017-12-09 10:26:52 -0800126 self.recreation_check(struct.pack('<4sll', importlib.util.MAGIC_NUMBER,
127 0, 1))
Brett Cannonbefb14f2009-02-10 02:10:16 +0000128
129 def test_magic_number(self):
130 # Test a change in mtime leads to a new .pyc.
131 self.recreation_check(b'\0\0\0\0')
132
Matthias Klosec33b9022010-03-16 00:36:26 +0000133 def test_compile_files(self):
134 # Test compiling a single file, and complete directory
135 for fn in (self.bc_path, self.bc_path2):
136 try:
137 os.unlink(fn)
138 except:
139 pass
Brett Cannon1e3c3e92015-12-27 13:17:04 -0800140 self.assertTrue(compileall.compile_file(self.source_path,
141 force=False, quiet=True))
Barry Warsaw28a691b2010-04-17 00:19:56 +0000142 self.assertTrue(os.path.isfile(self.bc_path) and
143 not os.path.isfile(self.bc_path2))
Matthias Klosec33b9022010-03-16 00:36:26 +0000144 os.unlink(self.bc_path)
Brett Cannon1e3c3e92015-12-27 13:17:04 -0800145 self.assertTrue(compileall.compile_dir(self.directory, force=False,
146 quiet=True))
Barry Warsaw28a691b2010-04-17 00:19:56 +0000147 self.assertTrue(os.path.isfile(self.bc_path) and
148 os.path.isfile(self.bc_path2))
Matthias Klosec33b9022010-03-16 00:36:26 +0000149 os.unlink(self.bc_path)
150 os.unlink(self.bc_path2)
Brett Cannon1e3c3e92015-12-27 13:17:04 -0800151 # Test against bad files
152 self.add_bad_source_file()
153 self.assertFalse(compileall.compile_file(self.bad_source_path,
154 force=False, quiet=2))
155 self.assertFalse(compileall.compile_dir(self.directory,
156 force=False, quiet=2))
157
Berker Peksag812a2b62016-10-01 00:54:18 +0300158 def test_compile_file_pathlike(self):
159 self.assertFalse(os.path.isfile(self.bc_path))
160 # we should also test the output
161 with support.captured_stdout() as stdout:
162 self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path)))
Berker Peksagd8e97132016-10-01 02:44:37 +0300163 self.assertRegex(stdout.getvalue(), r'Compiling ([^WindowsPath|PosixPath].*)')
Berker Peksag812a2b62016-10-01 00:54:18 +0300164 self.assertTrue(os.path.isfile(self.bc_path))
165
166 def test_compile_file_pathlike_ddir(self):
167 self.assertFalse(os.path.isfile(self.bc_path))
168 self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path),
169 ddir=pathlib.Path('ddir_path'),
170 quiet=2))
171 self.assertTrue(os.path.isfile(self.bc_path))
172
Brett Cannon1e3c3e92015-12-27 13:17:04 -0800173 def test_compile_path(self):
Berker Peksag408b78c2016-09-28 17:38:53 +0300174 with test.test_importlib.util.import_state(path=[self.directory]):
175 self.assertTrue(compileall.compile_path(quiet=2))
Brett Cannon1e3c3e92015-12-27 13:17:04 -0800176
177 with test.test_importlib.util.import_state(path=[self.directory]):
178 self.add_bad_source_file()
179 self.assertFalse(compileall.compile_path(skip_curdir=False,
180 force=True, quiet=2))
Brett Cannonbefb14f2009-02-10 02:10:16 +0000181
Barry Warsawc8a99de2010-04-29 18:43:10 +0000182 def test_no_pycache_in_non_package(self):
183 # Bug 8563 reported that __pycache__ directories got created by
184 # compile_file() for non-.py files.
185 data_dir = os.path.join(self.directory, 'data')
186 data_file = os.path.join(data_dir, 'file')
187 os.mkdir(data_dir)
188 # touch data/file
189 with open(data_file, 'w'):
190 pass
191 compileall.compile_file(data_file)
192 self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))
193
Georg Brandl8334fd92010-12-04 10:26:46 +0000194 def test_optimize(self):
195 # make sure compiling with different optimization settings than the
196 # interpreter's creates the correct file names
Brett Cannonf299abd2015-04-13 14:21:02 -0400197 optimize, opt = (1, 1) if __debug__ else (0, '')
Georg Brandl8334fd92010-12-04 10:26:46 +0000198 compileall.compile_dir(self.directory, quiet=True, optimize=optimize)
Brett Cannon7822e122013-06-14 23:04:02 -0400199 cached = importlib.util.cache_from_source(self.source_path,
Brett Cannonf299abd2015-04-13 14:21:02 -0400200 optimization=opt)
Georg Brandl8334fd92010-12-04 10:26:46 +0000201 self.assertTrue(os.path.isfile(cached))
Brett Cannon7822e122013-06-14 23:04:02 -0400202 cached2 = importlib.util.cache_from_source(self.source_path2,
Brett Cannonf299abd2015-04-13 14:21:02 -0400203 optimization=opt)
Georg Brandl45438462011-02-07 12:36:54 +0000204 self.assertTrue(os.path.isfile(cached2))
Brett Cannon7822e122013-06-14 23:04:02 -0400205 cached3 = importlib.util.cache_from_source(self.source_path3,
Brett Cannonf299abd2015-04-13 14:21:02 -0400206 optimization=opt)
Georg Brandl45438462011-02-07 12:36:54 +0000207 self.assertTrue(os.path.isfile(cached3))
Georg Brandl8334fd92010-12-04 10:26:46 +0000208
Berker Peksag812a2b62016-10-01 00:54:18 +0300209 def test_compile_dir_pathlike(self):
210 self.assertFalse(os.path.isfile(self.bc_path))
211 with support.captured_stdout() as stdout:
212 compileall.compile_dir(pathlib.Path(self.directory))
Berker Peksagd8e97132016-10-01 02:44:37 +0300213 line = stdout.getvalue().splitlines()[0]
214 self.assertRegex(line, r'Listing ([^WindowsPath|PosixPath].*)')
Berker Peksag812a2b62016-10-01 00:54:18 +0300215 self.assertTrue(os.path.isfile(self.bc_path))
216
Dustin Spicuzza1d817e42018-11-23 12:06:55 -0500217 @mock.patch('concurrent.futures.ProcessPoolExecutor')
Brett Cannonf1a8df02014-09-12 10:39:48 -0400218 def test_compile_pool_called(self, pool_mock):
219 compileall.compile_dir(self.directory, quiet=True, workers=5)
220 self.assertTrue(pool_mock.called)
221
222 def test_compile_workers_non_positive(self):
223 with self.assertRaisesRegex(ValueError,
224 "workers must be greater or equal to 0"):
225 compileall.compile_dir(self.directory, workers=-1)
226
Dustin Spicuzza1d817e42018-11-23 12:06:55 -0500227 @mock.patch('concurrent.futures.ProcessPoolExecutor')
Brett Cannonf1a8df02014-09-12 10:39:48 -0400228 def test_compile_workers_cpu_count(self, pool_mock):
229 compileall.compile_dir(self.directory, quiet=True, workers=0)
230 self.assertEqual(pool_mock.call_args[1]['max_workers'], None)
231
Dustin Spicuzza1d817e42018-11-23 12:06:55 -0500232 @mock.patch('concurrent.futures.ProcessPoolExecutor')
Brett Cannonf1a8df02014-09-12 10:39:48 -0400233 @mock.patch('compileall.compile_file')
234 def test_compile_one_worker(self, compile_file_mock, pool_mock):
235 compileall.compile_dir(self.directory, quiet=True)
236 self.assertFalse(pool_mock.called)
237 self.assertTrue(compile_file_mock.called)
238
Dustin Spicuzza1d817e42018-11-23 12:06:55 -0500239 @mock.patch('concurrent.futures.ProcessPoolExecutor', new=None)
Berker Peksagd86ef052015-04-22 09:39:19 +0300240 @mock.patch('compileall.compile_file')
241 def test_compile_missing_multiprocessing(self, compile_file_mock):
242 compileall.compile_dir(self.directory, quiet=True, workers=5)
243 self.assertTrue(compile_file_mock.called)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000244
Petr Viktorin4267c982019-09-26 11:53:51 +0200245 def test_compile_dir_maxlevels(self):
Lumír 'Frenzy' Balhar8e7bb992019-09-26 08:28:26 +0200246 # Test the actual impact of maxlevels attr
Petr Viktorin4267c982019-09-26 11:53:51 +0200247 self.create_long_path()
Lumír 'Frenzy' Balhar8e7bb992019-09-26 08:28:26 +0200248 compileall.compile_dir(os.path.join(self.directory, "long"),
249 maxlevels=10, quiet=True)
250 self.assertFalse(os.path.isfile(self.bc_path_long))
251 compileall.compile_dir(os.path.join(self.directory, "long"),
Petr Viktorin4267c982019-09-26 11:53:51 +0200252 quiet=True)
Lumír 'Frenzy' Balhar8e7bb992019-09-26 08:28:26 +0200253 self.assertTrue(os.path.isfile(self.bc_path_long))
254
255 def test_strip_only(self):
256 fullpath = ["test", "build", "real", "path"]
257 path = os.path.join(self.directory, *fullpath)
258 os.makedirs(path)
259 script = script_helper.make_script(path, "test", "1 / 0")
260 bc = importlib.util.cache_from_source(script)
261 stripdir = os.path.join(self.directory, *fullpath[:2])
262 compileall.compile_dir(path, quiet=True, stripdir=stripdir)
263 rc, out, err = script_helper.assert_python_failure(bc)
264 expected_in = os.path.join(*fullpath[2:])
265 self.assertIn(
266 expected_in,
267 str(err, encoding=sys.getdefaultencoding())
268 )
269 self.assertNotIn(
270 stripdir,
271 str(err, encoding=sys.getdefaultencoding())
272 )
273
274 def test_prepend_only(self):
275 fullpath = ["test", "build", "real", "path"]
276 path = os.path.join(self.directory, *fullpath)
277 os.makedirs(path)
278 script = script_helper.make_script(path, "test", "1 / 0")
279 bc = importlib.util.cache_from_source(script)
280 prependdir = "/foo"
281 compileall.compile_dir(path, quiet=True, prependdir=prependdir)
282 rc, out, err = script_helper.assert_python_failure(bc)
283 expected_in = os.path.join(prependdir, self.directory, *fullpath)
284 self.assertIn(
285 expected_in,
286 str(err, encoding=sys.getdefaultencoding())
287 )
288
289 def test_strip_and_prepend(self):
290 fullpath = ["test", "build", "real", "path"]
291 path = os.path.join(self.directory, *fullpath)
292 os.makedirs(path)
293 script = script_helper.make_script(path, "test", "1 / 0")
294 bc = importlib.util.cache_from_source(script)
295 stripdir = os.path.join(self.directory, *fullpath[:2])
296 prependdir = "/foo"
297 compileall.compile_dir(path, quiet=True,
298 stripdir=stripdir, prependdir=prependdir)
299 rc, out, err = script_helper.assert_python_failure(bc)
300 expected_in = os.path.join(prependdir, *fullpath[2:])
301 self.assertIn(
302 expected_in,
303 str(err, encoding=sys.getdefaultencoding())
304 )
305 self.assertNotIn(
306 stripdir,
307 str(err, encoding=sys.getdefaultencoding())
308 )
309
310 def test_strip_prepend_and_ddir(self):
311 fullpath = ["test", "build", "real", "path", "ddir"]
312 path = os.path.join(self.directory, *fullpath)
313 os.makedirs(path)
314 script_helper.make_script(path, "test", "1 / 0")
315 with self.assertRaises(ValueError):
316 compileall.compile_dir(path, quiet=True, ddir="/bar",
317 stripdir="/foo", prependdir="/bar")
318
319 def test_multiple_optimization_levels(self):
320 script = script_helper.make_script(self.directory,
321 "test_optimization",
322 "a = 0")
323 bc = []
324 for opt_level in "", 1, 2, 3:
325 bc.append(importlib.util.cache_from_source(script,
326 optimization=opt_level))
327 test_combinations = [[0, 1], [1, 2], [0, 2], [0, 1, 2]]
328 for opt_combination in test_combinations:
329 compileall.compile_file(script, quiet=True,
330 optimize=opt_combination)
331 for opt_level in opt_combination:
332 self.assertTrue(os.path.isfile(bc[opt_level]))
333 try:
334 os.unlink(bc[opt_level])
335 except Exception:
336 pass
337
338 @support.skip_unless_symlink
339 def test_ignore_symlink_destination(self):
340 # Create folders for allowed files, symlinks and prohibited area
341 allowed_path = os.path.join(self.directory, "test", "dir", "allowed")
342 symlinks_path = os.path.join(self.directory, "test", "dir", "symlinks")
343 prohibited_path = os.path.join(self.directory, "test", "dir", "prohibited")
344 os.makedirs(allowed_path)
345 os.makedirs(symlinks_path)
346 os.makedirs(prohibited_path)
347
348 # Create scripts and symlinks and remember their byte-compiled versions
349 allowed_script = script_helper.make_script(allowed_path, "test_allowed", "a = 0")
350 prohibited_script = script_helper.make_script(prohibited_path, "test_prohibited", "a = 0")
351 allowed_symlink = os.path.join(symlinks_path, "test_allowed.py")
352 prohibited_symlink = os.path.join(symlinks_path, "test_prohibited.py")
353 os.symlink(allowed_script, allowed_symlink)
354 os.symlink(prohibited_script, prohibited_symlink)
355 allowed_bc = importlib.util.cache_from_source(allowed_symlink)
356 prohibited_bc = importlib.util.cache_from_source(prohibited_symlink)
357
358 compileall.compile_dir(symlinks_path, quiet=True, limit_sl_dest=allowed_path)
359
360 self.assertTrue(os.path.isfile(allowed_bc))
361 self.assertFalse(os.path.isfile(prohibited_bc))
362
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400363
364class CompileallTestsWithSourceEpoch(CompileallTestsBase,
365 unittest.TestCase,
366 metaclass=SourceDateEpochTestMeta,
367 source_date_epoch=True):
368 pass
369
370
371class CompileallTestsWithoutSourceEpoch(CompileallTestsBase,
372 unittest.TestCase,
373 metaclass=SourceDateEpochTestMeta,
374 source_date_epoch=False):
375 pass
376
377
Martin v. Löwis4b003072010-03-16 13:19:21 +0000378class EncodingTest(unittest.TestCase):
Barry Warsaw28a691b2010-04-17 00:19:56 +0000379 """Issue 6716: compileall should escape source code when printing errors
380 to stdout."""
Martin v. Löwis4b003072010-03-16 13:19:21 +0000381
382 def setUp(self):
383 self.directory = tempfile.mkdtemp()
384 self.source_path = os.path.join(self.directory, '_test.py')
385 with open(self.source_path, 'w', encoding='utf-8') as file:
386 file.write('# -*- coding: utf-8 -*-\n')
387 file.write('print u"\u20ac"\n')
388
389 def tearDown(self):
390 shutil.rmtree(self.directory)
391
392 def test_error(self):
393 try:
394 orig_stdout = sys.stdout
395 sys.stdout = io.TextIOWrapper(io.BytesIO(),encoding='ascii')
396 compileall.compile_dir(self.directory)
397 finally:
398 sys.stdout = orig_stdout
399
Barry Warsawc8a99de2010-04-29 18:43:10 +0000400
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400401class CommandLineTestsBase:
R. David Murray650f1472010-11-20 21:18:51 +0000402 """Test compileall's CLI."""
Barry Warsaw28a691b2010-04-17 00:19:56 +0000403
Brett Cannon65ed7502015-10-09 15:09:43 -0700404 @classmethod
405 def setUpClass(cls):
406 for path in filter(os.path.isdir, sys.path):
407 directory_created = False
408 directory = pathlib.Path(path) / '__pycache__'
409 path = directory / 'test.try'
410 try:
411 if not directory.is_dir():
412 directory.mkdir()
413 directory_created = True
414 with path.open('w') as file:
415 file.write('# for test_compileall')
416 except OSError:
417 sys_path_writable = False
418 break
419 finally:
420 support.unlink(str(path))
421 if directory_created:
422 directory.rmdir()
423 else:
424 sys_path_writable = True
425 cls._sys_path_writable = sys_path_writable
426
427 def _skip_if_sys_path_not_writable(self):
428 if not self._sys_path_writable:
429 raise unittest.SkipTest('not all entries on sys.path are writable')
430
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400431 def _get_run_args(self, args):
Victor Stinner9def2842016-01-18 12:15:08 +0100432 return [*support.optim_args_from_interpreter_flags(),
433 '-S', '-m', 'compileall',
434 *args]
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400435
R. David Murray5317e9c2010-12-16 19:08:51 +0000436 def assertRunOK(self, *args, **env_vars):
437 rc, out, err = script_helper.assert_python_ok(
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400438 *self._get_run_args(args), **env_vars)
R. David Murray95333e32010-12-14 22:32:50 +0000439 self.assertEqual(b'', err)
440 return out
441
R. David Murray5317e9c2010-12-16 19:08:51 +0000442 def assertRunNotOK(self, *args, **env_vars):
R. David Murray95333e32010-12-14 22:32:50 +0000443 rc, out, err = script_helper.assert_python_failure(
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400444 *self._get_run_args(args), **env_vars)
R. David Murray95333e32010-12-14 22:32:50 +0000445 return rc, out, err
446
447 def assertCompiled(self, fn):
Brett Cannon7822e122013-06-14 23:04:02 -0400448 path = importlib.util.cache_from_source(fn)
449 self.assertTrue(os.path.exists(path))
R. David Murray95333e32010-12-14 22:32:50 +0000450
451 def assertNotCompiled(self, fn):
Brett Cannon7822e122013-06-14 23:04:02 -0400452 path = importlib.util.cache_from_source(fn)
453 self.assertFalse(os.path.exists(path))
R. David Murray95333e32010-12-14 22:32:50 +0000454
Barry Warsaw28a691b2010-04-17 00:19:56 +0000455 def setUp(self):
Barry Warsaw28a691b2010-04-17 00:19:56 +0000456 self.directory = tempfile.mkdtemp()
Brett Cannon65ed7502015-10-09 15:09:43 -0700457 self.addCleanup(support.rmtree, self.directory)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000458 self.pkgdir = os.path.join(self.directory, 'foo')
459 os.mkdir(self.pkgdir)
R. David Murray95333e32010-12-14 22:32:50 +0000460 self.pkgdir_cachedir = os.path.join(self.pkgdir, '__pycache__')
461 # Create the __init__.py and a package module.
462 self.initfn = script_helper.make_script(self.pkgdir, '__init__', '')
463 self.barfn = script_helper.make_script(self.pkgdir, 'bar', '')
Barry Warsaw28a691b2010-04-17 00:19:56 +0000464
R. David Murray5317e9c2010-12-16 19:08:51 +0000465 def test_no_args_compiles_path(self):
466 # Note that -l is implied for the no args case.
Brett Cannon65ed7502015-10-09 15:09:43 -0700467 self._skip_if_sys_path_not_writable()
R. David Murray5317e9c2010-12-16 19:08:51 +0000468 bazfn = script_helper.make_script(self.directory, 'baz', '')
469 self.assertRunOK(PYTHONPATH=self.directory)
470 self.assertCompiled(bazfn)
471 self.assertNotCompiled(self.initfn)
472 self.assertNotCompiled(self.barfn)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000473
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400474 @without_source_date_epoch # timestamp invalidation test
R David Murray8a1d1e62013-12-15 20:49:38 -0500475 def test_no_args_respects_force_flag(self):
Brett Cannon65ed7502015-10-09 15:09:43 -0700476 self._skip_if_sys_path_not_writable()
R David Murray8a1d1e62013-12-15 20:49:38 -0500477 bazfn = script_helper.make_script(self.directory, 'baz', '')
478 self.assertRunOK(PYTHONPATH=self.directory)
R David Murray755d5ea2013-12-15 20:56:00 -0500479 pycpath = importlib.util.cache_from_source(bazfn)
R David Murray8a1d1e62013-12-15 20:49:38 -0500480 # Set atime/mtime backward to avoid file timestamp resolution issues
481 os.utime(pycpath, (time.time()-60,)*2)
482 mtime = os.stat(pycpath).st_mtime
483 # Without force, no recompilation
484 self.assertRunOK(PYTHONPATH=self.directory)
485 mtime2 = os.stat(pycpath).st_mtime
486 self.assertEqual(mtime, mtime2)
487 # Now force it.
488 self.assertRunOK('-f', PYTHONPATH=self.directory)
489 mtime2 = os.stat(pycpath).st_mtime
490 self.assertNotEqual(mtime, mtime2)
491
492 def test_no_args_respects_quiet_flag(self):
Brett Cannon65ed7502015-10-09 15:09:43 -0700493 self._skip_if_sys_path_not_writable()
R David Murray8a1d1e62013-12-15 20:49:38 -0500494 script_helper.make_script(self.directory, 'baz', '')
495 noisy = self.assertRunOK(PYTHONPATH=self.directory)
496 self.assertIn(b'Listing ', noisy)
497 quiet = self.assertRunOK('-q', PYTHONPATH=self.directory)
498 self.assertNotIn(b'Listing ', quiet)
499
Georg Brandl1463a3f2010-10-14 07:42:27 +0000500 # Ensure that the default behavior of compileall's CLI is to create
Brett Cannonf299abd2015-04-13 14:21:02 -0400501 # PEP 3147/PEP 488 pyc files.
Georg Brandl1463a3f2010-10-14 07:42:27 +0000502 for name, ext, switch in [
503 ('normal', 'pyc', []),
Brett Cannonf299abd2015-04-13 14:21:02 -0400504 ('optimize', 'opt-1.pyc', ['-O']),
505 ('doubleoptimize', 'opt-2.pyc', ['-OO']),
Georg Brandl1463a3f2010-10-14 07:42:27 +0000506 ]:
507 def f(self, ext=ext, switch=switch):
R. David Murray95333e32010-12-14 22:32:50 +0000508 script_helper.assert_python_ok(*(switch +
509 ['-m', 'compileall', '-q', self.pkgdir]))
Georg Brandl1463a3f2010-10-14 07:42:27 +0000510 # Verify the __pycache__ directory contents.
R. David Murray95333e32010-12-14 22:32:50 +0000511 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
Brett Cannon7822e122013-06-14 23:04:02 -0400512 expected = sorted(base.format(sys.implementation.cache_tag, ext)
513 for base in ('__init__.{}.{}', 'bar.{}.{}'))
R. David Murray95333e32010-12-14 22:32:50 +0000514 self.assertEqual(sorted(os.listdir(self.pkgdir_cachedir)), expected)
Georg Brandl1463a3f2010-10-14 07:42:27 +0000515 # Make sure there are no .pyc files in the source directory.
R. David Murray95333e32010-12-14 22:32:50 +0000516 self.assertFalse([fn for fn in os.listdir(self.pkgdir)
517 if fn.endswith(ext)])
Georg Brandl1463a3f2010-10-14 07:42:27 +0000518 locals()['test_pep3147_paths_' + name] = f
Barry Warsaw28a691b2010-04-17 00:19:56 +0000519
520 def test_legacy_paths(self):
521 # Ensure that with the proper switch, compileall leaves legacy
Brett Cannonf299abd2015-04-13 14:21:02 -0400522 # pyc files, and no __pycache__ directory.
R. David Murray95333e32010-12-14 22:32:50 +0000523 self.assertRunOK('-b', '-q', self.pkgdir)
Barry Warsaw28a691b2010-04-17 00:19:56 +0000524 # Verify the __pycache__ directory contents.
R. David Murray95333e32010-12-14 22:32:50 +0000525 self.assertFalse(os.path.exists(self.pkgdir_cachedir))
Brett Cannonf299abd2015-04-13 14:21:02 -0400526 expected = sorted(['__init__.py', '__init__.pyc', 'bar.py',
527 'bar.pyc'])
Barry Warsaw28a691b2010-04-17 00:19:56 +0000528 self.assertEqual(sorted(os.listdir(self.pkgdir)), expected)
529
Barry Warsawc04317f2010-04-26 15:59:03 +0000530 def test_multiple_runs(self):
531 # Bug 8527 reported that multiple calls produced empty
532 # __pycache__/__pycache__ directories.
R. David Murray95333e32010-12-14 22:32:50 +0000533 self.assertRunOK('-q', self.pkgdir)
Barry Warsawc04317f2010-04-26 15:59:03 +0000534 # Verify the __pycache__ directory contents.
R. David Murray95333e32010-12-14 22:32:50 +0000535 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
536 cachecachedir = os.path.join(self.pkgdir_cachedir, '__pycache__')
Barry Warsawc04317f2010-04-26 15:59:03 +0000537 self.assertFalse(os.path.exists(cachecachedir))
538 # Call compileall again.
R. David Murray95333e32010-12-14 22:32:50 +0000539 self.assertRunOK('-q', self.pkgdir)
540 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
Barry Warsawc04317f2010-04-26 15:59:03 +0000541 self.assertFalse(os.path.exists(cachecachedir))
542
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400543 @without_source_date_epoch # timestamp invalidation test
R. David Murray650f1472010-11-20 21:18:51 +0000544 def test_force(self):
R. David Murray95333e32010-12-14 22:32:50 +0000545 self.assertRunOK('-q', self.pkgdir)
Brett Cannon7822e122013-06-14 23:04:02 -0400546 pycpath = importlib.util.cache_from_source(self.barfn)
R. David Murray650f1472010-11-20 21:18:51 +0000547 # set atime/mtime backward to avoid file timestamp resolution issues
548 os.utime(pycpath, (time.time()-60,)*2)
R. David Murray95333e32010-12-14 22:32:50 +0000549 mtime = os.stat(pycpath).st_mtime
550 # without force, no recompilation
551 self.assertRunOK('-q', self.pkgdir)
552 mtime2 = os.stat(pycpath).st_mtime
553 self.assertEqual(mtime, mtime2)
554 # now force it.
555 self.assertRunOK('-q', '-f', self.pkgdir)
556 mtime2 = os.stat(pycpath).st_mtime
557 self.assertNotEqual(mtime, mtime2)
R. David Murray650f1472010-11-20 21:18:51 +0000558
R. David Murray95333e32010-12-14 22:32:50 +0000559 def test_recursion_control(self):
560 subpackage = os.path.join(self.pkgdir, 'spam')
561 os.mkdir(subpackage)
562 subinitfn = script_helper.make_script(subpackage, '__init__', '')
563 hamfn = script_helper.make_script(subpackage, 'ham', '')
564 self.assertRunOK('-q', '-l', self.pkgdir)
565 self.assertNotCompiled(subinitfn)
566 self.assertFalse(os.path.exists(os.path.join(subpackage, '__pycache__')))
567 self.assertRunOK('-q', self.pkgdir)
568 self.assertCompiled(subinitfn)
569 self.assertCompiled(hamfn)
R. David Murray650f1472010-11-20 21:18:51 +0000570
Benjamin Peterson344ff4a2014-08-19 16:13:26 -0500571 def test_recursion_limit(self):
572 subpackage = os.path.join(self.pkgdir, 'spam')
573 subpackage2 = os.path.join(subpackage, 'ham')
574 subpackage3 = os.path.join(subpackage2, 'eggs')
575 for pkg in (subpackage, subpackage2, subpackage3):
576 script_helper.make_pkg(pkg)
577
578 subinitfn = os.path.join(subpackage, '__init__.py')
579 hamfn = script_helper.make_script(subpackage, 'ham', '')
580 spamfn = script_helper.make_script(subpackage2, 'spam', '')
581 eggfn = script_helper.make_script(subpackage3, 'egg', '')
582
583 self.assertRunOK('-q', '-r 0', self.pkgdir)
584 self.assertNotCompiled(subinitfn)
585 self.assertFalse(
586 os.path.exists(os.path.join(subpackage, '__pycache__')))
587
588 self.assertRunOK('-q', '-r 1', self.pkgdir)
589 self.assertCompiled(subinitfn)
590 self.assertCompiled(hamfn)
591 self.assertNotCompiled(spamfn)
592
593 self.assertRunOK('-q', '-r 2', self.pkgdir)
594 self.assertCompiled(subinitfn)
595 self.assertCompiled(hamfn)
596 self.assertCompiled(spamfn)
597 self.assertNotCompiled(eggfn)
598
599 self.assertRunOK('-q', '-r 5', self.pkgdir)
600 self.assertCompiled(subinitfn)
601 self.assertCompiled(hamfn)
602 self.assertCompiled(spamfn)
603 self.assertCompiled(eggfn)
604
Lumír 'Frenzy' Balhar8e7bb992019-09-26 08:28:26 +0200605 @support.skip_unless_symlink
606 def test_symlink_loop(self):
607 # Currently, compileall ignores symlinks to directories.
608 # If that limitation is ever lifted, it should protect against
609 # recursion in symlink loops.
610 pkg = os.path.join(self.pkgdir, 'spam')
611 script_helper.make_pkg(pkg)
612 os.symlink('.', os.path.join(pkg, 'evil'))
613 os.symlink('.', os.path.join(pkg, 'evil2'))
614 self.assertRunOK('-q', self.pkgdir)
615 self.assertCompiled(os.path.join(
616 self.pkgdir, 'spam', 'evil', 'evil2', '__init__.py'
617 ))
618
R. David Murray650f1472010-11-20 21:18:51 +0000619 def test_quiet(self):
R. David Murray95333e32010-12-14 22:32:50 +0000620 noisy = self.assertRunOK(self.pkgdir)
621 quiet = self.assertRunOK('-q', self.pkgdir)
622 self.assertNotEqual(b'', noisy)
623 self.assertEqual(b'', quiet)
R. David Murray650f1472010-11-20 21:18:51 +0000624
Berker Peksag6554b862014-10-15 11:10:57 +0300625 def test_silent(self):
626 script_helper.make_script(self.pkgdir, 'crunchyfrog', 'bad(syntax')
627 _, quiet, _ = self.assertRunNotOK('-q', self.pkgdir)
628 _, silent, _ = self.assertRunNotOK('-qq', self.pkgdir)
629 self.assertNotEqual(b'', quiet)
630 self.assertEqual(b'', silent)
631
R. David Murray650f1472010-11-20 21:18:51 +0000632 def test_regexp(self):
R David Murrayee1a7cb2011-07-01 14:55:43 -0400633 self.assertRunOK('-q', '-x', r'ba[^\\/]*$', self.pkgdir)
R. David Murray95333e32010-12-14 22:32:50 +0000634 self.assertNotCompiled(self.barfn)
635 self.assertCompiled(self.initfn)
R. David Murray650f1472010-11-20 21:18:51 +0000636
R. David Murray95333e32010-12-14 22:32:50 +0000637 def test_multiple_dirs(self):
638 pkgdir2 = os.path.join(self.directory, 'foo2')
639 os.mkdir(pkgdir2)
640 init2fn = script_helper.make_script(pkgdir2, '__init__', '')
641 bar2fn = script_helper.make_script(pkgdir2, 'bar2', '')
642 self.assertRunOK('-q', self.pkgdir, pkgdir2)
643 self.assertCompiled(self.initfn)
644 self.assertCompiled(self.barfn)
645 self.assertCompiled(init2fn)
646 self.assertCompiled(bar2fn)
647
R. David Murray95333e32010-12-14 22:32:50 +0000648 def test_d_compile_error(self):
649 script_helper.make_script(self.pkgdir, 'crunchyfrog', 'bad(syntax')
650 rc, out, err = self.assertRunNotOK('-q', '-d', 'dinsdale', self.pkgdir)
651 self.assertRegex(out, b'File "dinsdale')
652
653 def test_d_runtime_error(self):
654 bazfn = script_helper.make_script(self.pkgdir, 'baz', 'raise Exception')
655 self.assertRunOK('-q', '-d', 'dinsdale', self.pkgdir)
656 fn = script_helper.make_script(self.pkgdir, 'bing', 'import baz')
Brett Cannon7822e122013-06-14 23:04:02 -0400657 pyc = importlib.util.cache_from_source(bazfn)
R. David Murray95333e32010-12-14 22:32:50 +0000658 os.rename(pyc, os.path.join(self.pkgdir, 'baz.pyc'))
659 os.remove(bazfn)
Victor Stinnere8785ff2013-10-12 14:44:01 +0200660 rc, out, err = script_helper.assert_python_failure(fn, __isolated=False)
R. David Murray95333e32010-12-14 22:32:50 +0000661 self.assertRegex(err, b'File "dinsdale')
662
663 def test_include_bad_file(self):
664 rc, out, err = self.assertRunNotOK(
665 '-i', os.path.join(self.directory, 'nosuchfile'), self.pkgdir)
666 self.assertRegex(out, b'rror.*nosuchfile')
667 self.assertNotRegex(err, b'Traceback')
Brett Cannon7822e122013-06-14 23:04:02 -0400668 self.assertFalse(os.path.exists(importlib.util.cache_from_source(
R. David Murray95333e32010-12-14 22:32:50 +0000669 self.pkgdir_cachedir)))
670
671 def test_include_file_with_arg(self):
672 f1 = script_helper.make_script(self.pkgdir, 'f1', '')
673 f2 = script_helper.make_script(self.pkgdir, 'f2', '')
674 f3 = script_helper.make_script(self.pkgdir, 'f3', '')
675 f4 = script_helper.make_script(self.pkgdir, 'f4', '')
676 with open(os.path.join(self.directory, 'l1'), 'w') as l1:
677 l1.write(os.path.join(self.pkgdir, 'f1.py')+os.linesep)
678 l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
679 self.assertRunOK('-i', os.path.join(self.directory, 'l1'), f4)
680 self.assertCompiled(f1)
681 self.assertCompiled(f2)
682 self.assertNotCompiled(f3)
683 self.assertCompiled(f4)
684
685 def test_include_file_no_arg(self):
686 f1 = script_helper.make_script(self.pkgdir, 'f1', '')
687 f2 = script_helper.make_script(self.pkgdir, 'f2', '')
688 f3 = script_helper.make_script(self.pkgdir, 'f3', '')
689 f4 = script_helper.make_script(self.pkgdir, 'f4', '')
690 with open(os.path.join(self.directory, 'l1'), 'w') as l1:
691 l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
692 self.assertRunOK('-i', os.path.join(self.directory, 'l1'))
693 self.assertNotCompiled(f1)
694 self.assertCompiled(f2)
695 self.assertNotCompiled(f3)
696 self.assertNotCompiled(f4)
697
698 def test_include_on_stdin(self):
699 f1 = script_helper.make_script(self.pkgdir, 'f1', '')
700 f2 = script_helper.make_script(self.pkgdir, 'f2', '')
701 f3 = script_helper.make_script(self.pkgdir, 'f3', '')
702 f4 = script_helper.make_script(self.pkgdir, 'f4', '')
Benjamin Petersona820c7c2012-09-25 11:42:35 -0400703 p = script_helper.spawn_python(*(self._get_run_args(()) + ['-i', '-']))
R. David Murray95333e32010-12-14 22:32:50 +0000704 p.stdin.write((f3+os.linesep).encode('ascii'))
705 script_helper.kill_python(p)
706 self.assertNotCompiled(f1)
707 self.assertNotCompiled(f2)
708 self.assertCompiled(f3)
709 self.assertNotCompiled(f4)
710
711 def test_compiles_as_much_as_possible(self):
712 bingfn = script_helper.make_script(self.pkgdir, 'bing', 'syntax(error')
713 rc, out, err = self.assertRunNotOK('nosuchfile', self.initfn,
714 bingfn, self.barfn)
R. David Murray5317e9c2010-12-16 19:08:51 +0000715 self.assertRegex(out, b'rror')
R. David Murray95333e32010-12-14 22:32:50 +0000716 self.assertNotCompiled(bingfn)
717 self.assertCompiled(self.initfn)
718 self.assertCompiled(self.barfn)
719
R. David Murray5317e9c2010-12-16 19:08:51 +0000720 def test_invalid_arg_produces_message(self):
721 out = self.assertRunOK('badfilename')
Victor Stinner53071262011-05-11 00:36:28 +0200722 self.assertRegex(out, b"Can't list 'badfilename'")
R. David Murray650f1472010-11-20 21:18:51 +0000723
Benjamin Peterson42aa93b2017-12-09 10:26:52 -0800724 def test_pyc_invalidation_mode(self):
725 script_helper.make_script(self.pkgdir, 'f1', '')
726 pyc = importlib.util.cache_from_source(
727 os.path.join(self.pkgdir, 'f1.py'))
728 self.assertRunOK('--invalidation-mode=checked-hash', self.pkgdir)
729 with open(pyc, 'rb') as fp:
730 data = fp.read()
731 self.assertEqual(int.from_bytes(data[4:8], 'little'), 0b11)
732 self.assertRunOK('--invalidation-mode=unchecked-hash', self.pkgdir)
733 with open(pyc, 'rb') as fp:
734 data = fp.read()
735 self.assertEqual(int.from_bytes(data[4:8], 'little'), 0b01)
736
Brett Cannonf1a8df02014-09-12 10:39:48 -0400737 @skipUnless(_have_multiprocessing, "requires multiprocessing")
738 def test_workers(self):
739 bar2fn = script_helper.make_script(self.directory, 'bar2', '')
740 files = []
741 for suffix in range(5):
742 pkgdir = os.path.join(self.directory, 'foo{}'.format(suffix))
743 os.mkdir(pkgdir)
744 fn = script_helper.make_script(pkgdir, '__init__', '')
745 files.append(script_helper.make_script(pkgdir, 'bar2', ''))
746
747 self.assertRunOK(self.directory, '-j', '0')
748 self.assertCompiled(bar2fn)
749 for file in files:
750 self.assertCompiled(file)
751
752 @mock.patch('compileall.compile_dir')
753 def test_workers_available_cores(self, compile_dir):
754 with mock.patch("sys.argv",
755 new=[sys.executable, self.directory, "-j0"]):
756 compileall.main()
757 self.assertTrue(compile_dir.called)
Antoine Pitrou1a2dd822019-05-15 23:45:18 +0200758 self.assertEqual(compile_dir.call_args[-1]['workers'], 0)
Brett Cannonf1a8df02014-09-12 10:39:48 -0400759
Lumír 'Frenzy' Balhar8e7bb992019-09-26 08:28:26 +0200760 def test_strip_and_prepend(self):
761 fullpath = ["test", "build", "real", "path"]
762 path = os.path.join(self.directory, *fullpath)
763 os.makedirs(path)
764 script = script_helper.make_script(path, "test", "1 / 0")
765 bc = importlib.util.cache_from_source(script)
766 stripdir = os.path.join(self.directory, *fullpath[:2])
767 prependdir = "/foo"
768 self.assertRunOK("-s", stripdir, "-p", prependdir, path)
769 rc, out, err = script_helper.assert_python_failure(bc)
770 expected_in = os.path.join(prependdir, *fullpath[2:])
771 self.assertIn(
772 expected_in,
773 str(err, encoding=sys.getdefaultencoding())
774 )
775 self.assertNotIn(
776 stripdir,
777 str(err, encoding=sys.getdefaultencoding())
778 )
779
780 def test_multiple_optimization_levels(self):
781 path = os.path.join(self.directory, "optimizations")
782 os.makedirs(path)
783 script = script_helper.make_script(path,
784 "test_optimization",
785 "a = 0")
786 bc = []
787 for opt_level in "", 1, 2, 3:
788 bc.append(importlib.util.cache_from_source(script,
789 optimization=opt_level))
790 test_combinations = [["0", "1"],
791 ["1", "2"],
792 ["0", "2"],
793 ["0", "1", "2"]]
794 for opt_combination in test_combinations:
795 self.assertRunOK(path, *("-o" + str(n) for n in opt_combination))
796 for opt_level in opt_combination:
797 self.assertTrue(os.path.isfile(bc[int(opt_level)]))
798 try:
799 os.unlink(bc[opt_level])
800 except Exception:
801 pass
802
803 @support.skip_unless_symlink
804 def test_ignore_symlink_destination(self):
805 # Create folders for allowed files, symlinks and prohibited area
806 allowed_path = os.path.join(self.directory, "test", "dir", "allowed")
807 symlinks_path = os.path.join(self.directory, "test", "dir", "symlinks")
808 prohibited_path = os.path.join(self.directory, "test", "dir", "prohibited")
809 os.makedirs(allowed_path)
810 os.makedirs(symlinks_path)
811 os.makedirs(prohibited_path)
812
813 # Create scripts and symlinks and remember their byte-compiled versions
814 allowed_script = script_helper.make_script(allowed_path, "test_allowed", "a = 0")
815 prohibited_script = script_helper.make_script(prohibited_path, "test_prohibited", "a = 0")
816 allowed_symlink = os.path.join(symlinks_path, "test_allowed.py")
817 prohibited_symlink = os.path.join(symlinks_path, "test_prohibited.py")
818 os.symlink(allowed_script, allowed_symlink)
819 os.symlink(prohibited_script, prohibited_symlink)
820 allowed_bc = importlib.util.cache_from_source(allowed_symlink)
821 prohibited_bc = importlib.util.cache_from_source(prohibited_symlink)
822
823 self.assertRunOK(symlinks_path, "-e", allowed_path)
824
825 self.assertTrue(os.path.isfile(allowed_bc))
826 self.assertFalse(os.path.isfile(prohibited_bc))
827
Barry Warsaw28a691b2010-04-17 00:19:56 +0000828
Min ho Kimc4cacc82019-07-31 08:16:13 +1000829class CommandLineTestsWithSourceEpoch(CommandLineTestsBase,
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400830 unittest.TestCase,
831 metaclass=SourceDateEpochTestMeta,
832 source_date_epoch=True):
833 pass
834
835
Min ho Kimc4cacc82019-07-31 08:16:13 +1000836class CommandLineTestsNoSourceEpoch(CommandLineTestsBase,
Elvis Pranskevichusa6b3ec52018-10-10 12:43:14 -0400837 unittest.TestCase,
838 metaclass=SourceDateEpochTestMeta,
839 source_date_epoch=False):
840 pass
841
842
843
Brett Cannonbefb14f2009-02-10 02:10:16 +0000844if __name__ == "__main__":
Brett Cannon7822e122013-06-14 23:04:02 -0400845 unittest.main()