• Home
  • Raw
  • Download

Lines Matching +full:test +full:- +full:path

13 import test.test_importlib.util
28 from test import support
29 from test.support import os_helper
30 from test.support import script_helper
31 from test.test_py_compile import without_source_date_epoch
32 from test.test_py_compile import SourceDateEpochTestMeta
57 self.source_path = os.path.join(self.directory, '_test.py')
59 with open(self.source_path, 'w', encoding="utf-8") as file:
61 self.source_path2 = os.path.join(self.directory, '_test2.py')
64 self.subdirectory = os.path.join(self.directory, '_subdir')
66 self.source_path3 = os.path.join(self.subdirectory, '_test3.py')
73 self.bad_source_path = os.path.join(self.directory, '_test_bad.py')
74 with open(self.bad_source_path, 'w', encoding="utf-8") as file:
86 # Test to make sure we can handle mtimes larger than what a 32-bit
87 # signed number can hold as part of bpo-34990
89 os.utime(self.source_path, (2**32 - 1, 2**32 - 1))
96 # This is similar to the test above but we skip it if the OS doesn't
97 # support modification times larger than 32-bits.
122 # Test a change in mtime leads to a new .pyc.
127 # Test a change in mtime leads to a new .pyc.
131 # Test compiling a single file, and complete directory
139 self.assertTrue(os.path.isfile(self.bc_path) and
140 not os.path.isfile(self.bc_path2))
144 self.assertTrue(os.path.isfile(self.bc_path) and
145 os.path.isfile(self.bc_path2))
148 # Test against bad files
156 self.assertFalse(os.path.isfile(self.bc_path))
157 # we should also test the output
159 self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path)))
161 self.assertTrue(os.path.isfile(self.bc_path))
164 self.assertFalse(os.path.isfile(self.bc_path))
165 self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path),
166 ddir=pathlib.Path('ddir_path'),
168 self.assertTrue(os.path.isfile(self.bc_path))
171 with test.test_importlib.util.import_state(path=[self.directory]):
174 with test.test_importlib.util.import_state(path=[self.directory]):
181 # compile_file() for non-.py files.
182 data_dir = os.path.join(self.directory, 'data')
183 data_file = os.path.join(data_dir, 'file')
189 self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))
206 self.assertTrue(os.path.isfile(cached))
209 self.assertTrue(os.path.isfile(cached2))
212 self.assertTrue(os.path.isfile(cached3))
215 self.assertFalse(os.path.isfile(self.bc_path))
217 compileall.compile_dir(pathlib.Path(self.directory))
220 self.assertTrue(os.path.isfile(self.bc_path))
231 compileall.compile_dir(self.directory, workers=-1)
254 # Test the actual impact of maxlevels parameter
256 path = self.directory
258 path = os.path.join(path, f"dir_{i}")
259 source = os.path.join(path, 'script.py')
260 os.mkdir(path)
264 compileall.compile_dir(self.directory, quiet=True, maxlevels=depth - 1)
265 self.assertFalse(os.path.isfile(pyc_filename))
268 self.assertTrue(os.path.isfile(pyc_filename))
272 fullpath = ["test", "foo"]
273 path = self.directory
276 path = os.path.join(path, subdir)
277 os.mkdir(path)
278 script_helper.make_script(path, "__init__", "")
279 mods.append(script_helper.make_script(path, "mod",
290 expected_in = os.path.join(ddir, modpath)
291 mod_code_obj = test.test_importlib.util.get_code_from_pyc(modcode)
312 fullpath = ["test", "build", "real", "path"]
313 path = os.path.join(self.directory, *fullpath)
314 os.makedirs(path)
315 script = script_helper.make_script(path, "test", "1 / 0")
317 stripdir = os.path.join(self.directory, *fullpath[:2])
318 compileall.compile_dir(path, quiet=True, stripdir=stripdir)
320 expected_in = os.path.join(*fullpath[2:])
331 fullpath = ["test", "build", "real", "path"]
332 path = os.path.join(self.directory, *fullpath)
333 os.makedirs(path)
334 script = script_helper.make_script(path, "test", "1 / 0")
337 compileall.compile_dir(path, quiet=True, prependdir=prependdir)
339 expected_in = os.path.join(prependdir, self.directory, *fullpath)
346 fullpath = ["test", "build", "real", "path"]
347 path = os.path.join(self.directory, *fullpath)
348 os.makedirs(path)
349 script = script_helper.make_script(path, "test", "1 / 0")
351 stripdir = os.path.join(self.directory, *fullpath[:2])
353 compileall.compile_dir(path, quiet=True,
356 expected_in = os.path.join(prependdir, *fullpath[2:])
367 fullpath = ["test", "build", "real", "path", "ddir"]
368 path = os.path.join(self.directory, *fullpath)
369 os.makedirs(path)
370 script_helper.make_script(path, "test", "1 / 0")
372 compileall.compile_dir(path, quiet=True, ddir="/bar",
388 self.assertTrue(os.path.isfile(bc[opt_level]))
397 allowed_path = os.path.join(self.directory, "test", "dir", "allowed")
398 symlinks_path = os.path.join(self.directory, "test", "dir", "symlinks")
399 prohibited_path = os.path.join(self.directory, "test", "dir", "prohibited")
404 # Create scripts and symlinks and remember their byte-compiled versions
407 allowed_symlink = os.path.join(symlinks_path, "test_allowed.py")
408 prohibited_symlink = os.path.join(symlinks_path, "test_prohibited.py")
416 self.assertTrue(os.path.isfile(allowed_bc))
417 self.assertFalse(os.path.isfile(prohibited_bc))
440 self.source_path = os.path.join(self.directory, '_test.py')
441 with open(self.source_path, 'w', encoding='utf-8') as file:
442 file.write('# -*- coding: utf-8 -*-\n')
458 """Test compileall's CLI."""
462 for path in filter(os.path.isdir, sys.path):
464 directory = pathlib.Path(path) / '__pycache__'
465 path = directory / 'test.try'
470 path.write_text('# for test_compileall', encoding="utf-8")
475 os_helper.unlink(str(path))
484 raise unittest.SkipTest('not all entries on sys.path are writable')
488 '-S', '-m', 'compileall',
494 PYTHONIOENCODING='utf-8')
501 PYTHONIOENCODING='utf-8')
505 path = importlib.util.cache_from_source(fn)
506 self.assertTrue(os.path.exists(path))
509 path = importlib.util.cache_from_source(fn)
510 self.assertFalse(os.path.exists(path))
515 self.pkgdir = os.path.join(self.directory, 'foo')
517 self.pkgdir_cachedir = os.path.join(self.pkgdir, '__pycache__')
523 # Note that -l is implied for the no args case.
531 @without_source_date_epoch # timestamp invalidation test
538 os.utime(pycpath, (time.time()-60,)*2)
545 self.assertRunOK('-f', PYTHONPATH=self.directory)
554 quiet = self.assertRunOK('-q', PYTHONPATH=self.directory)
561 ('optimize', 'opt-1.pyc', ['-O']),
562 ('doubleoptimize', 'opt-2.pyc', ['-OO']),
566 ['-m', 'compileall', '-q', self.pkgdir]))
568 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
580 self.assertRunOK('-b', '-q', self.pkgdir)
582 self.assertFalse(os.path.exists(self.pkgdir_cachedir))
590 self.assertRunOK('-q', self.pkgdir)
592 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
593 cachecachedir = os.path.join(self.pkgdir_cachedir, '__pycache__')
594 self.assertFalse(os.path.exists(cachecachedir))
596 self.assertRunOK('-q', self.pkgdir)
597 self.assertTrue(os.path.exists(self.pkgdir_cachedir))
598 self.assertFalse(os.path.exists(cachecachedir))
600 @without_source_date_epoch # timestamp invalidation test
602 self.assertRunOK('-q', self.pkgdir)
605 os.utime(pycpath, (time.time()-60,)*2)
608 self.assertRunOK('-q', self.pkgdir)
612 self.assertRunOK('-q', '-f', self.pkgdir)
617 subpackage = os.path.join(self.pkgdir, 'spam')
621 self.assertRunOK('-q', '-l', self.pkgdir)
623 self.assertFalse(os.path.exists(os.path.join(subpackage, '__pycache__')))
624 self.assertRunOK('-q', self.pkgdir)
629 subpackage = os.path.join(self.pkgdir, 'spam')
630 subpackage2 = os.path.join(subpackage, 'ham')
631 subpackage3 = os.path.join(subpackage2, 'eggs')
635 subinitfn = os.path.join(subpackage, '__init__.py')
640 self.assertRunOK('-q', '-r 0', self.pkgdir)
643 os.path.exists(os.path.join(subpackage, '__pycache__')))
645 self.assertRunOK('-q', '-r 1', self.pkgdir)
650 self.assertRunOK('-q', '-r 2', self.pkgdir)
656 self.assertRunOK('-q', '-r 5', self.pkgdir)
667 pkg = os.path.join(self.pkgdir, 'spam')
669 os.symlink('.', os.path.join(pkg, 'evil'))
670 os.symlink('.', os.path.join(pkg, 'evil2'))
671 self.assertRunOK('-q', self.pkgdir)
672 self.assertCompiled(os.path.join(
678 quiet = self.assertRunOK('-q', self.pkgdir)
684 _, quiet, _ = self.assertRunNotOK('-q', self.pkgdir)
685 _, silent, _ = self.assertRunNotOK('-qq', self.pkgdir)
690 self.assertRunOK('-q', '-x', r'ba[^\\/]*$', self.pkgdir)
695 pkgdir2 = os.path.join(self.directory, 'foo2')
699 self.assertRunOK('-q', self.pkgdir, pkgdir2)
707 rc, out, err = self.assertRunNotOK('-q', '-d', 'dinsdale', self.pkgdir)
712 self.assertRunOK('-q', '-d', 'dinsdale', self.pkgdir)
715 os.rename(pyc, os.path.join(self.pkgdir, 'baz.pyc'))
722 '-i', os.path.join(self.directory, 'nosuchfile'), self.pkgdir)
725 self.assertFalse(os.path.exists(importlib.util.cache_from_source(
733 with open(os.path.join(self.directory, 'l1'), 'w', encoding="utf-8") as l1:
734 l1.write(os.path.join(self.pkgdir, 'f1.py')+os.linesep)
735 l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
736 self.assertRunOK('-i', os.path.join(self.directory, 'l1'), f4)
747 with open(os.path.join(self.directory, 'l1'), 'w', encoding="utf-8") as l1:
748 l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
749 self.assertRunOK('-i', os.path.join(self.directory, 'l1'))
760 p = script_helper.spawn_python(*(self._get_run_args(()) + ['-i', '-']))
784 os.path.join(self.pkgdir, 'f1.py'))
785 self.assertRunOK('--invalidation-mode=checked-hash', self.pkgdir)
789 self.assertRunOK('--invalidation-mode=unchecked-hash', self.pkgdir)
799 pkgdir = os.path.join(self.directory, 'foo{}'.format(suffix))
804 self.assertRunOK(self.directory, '-j', '0')
812 new=[sys.executable, self.directory, "-j0"]):
815 self.assertEqual(compile_dir.call_args[-1]['workers'], 0)
818 fullpath = ["test", "build", "real", "path"]
819 path = os.path.join(self.directory, *fullpath)
820 os.makedirs(path)
821 script = script_helper.make_script(path, "test", "1 / 0")
823 stripdir = os.path.join(self.directory, *fullpath[:2])
825 self.assertRunOK("-s", stripdir, "-p", prependdir, path)
827 expected_in = os.path.join(prependdir, *fullpath[2:])
838 path = os.path.join(self.directory, "optimizations")
839 os.makedirs(path)
840 script = script_helper.make_script(path,
852 self.assertRunOK(path, *("-o" + str(n) for n in opt_combination))
854 self.assertTrue(os.path.isfile(bc[int(opt_level)]))
863 allowed_path = os.path.join(self.directory, "test", "dir", "allowed")
864 symlinks_path = os.path.join(self.directory, "test", "dir", "symlinks")
865 prohibited_path = os.path.join(self.directory, "test", "dir", "prohibited")
870 # Create scripts and symlinks and remember their byte-compiled versions
873 allowed_symlink = os.path.join(symlinks_path, "test_allowed.py")
874 prohibited_symlink = os.path.join(symlinks_path, "test_prohibited.py")
880 self.assertRunOK(symlinks_path, "-e", allowed_path)
882 self.assertTrue(os.path.isfile(allowed_bc))
883 self.assertFalse(os.path.isfile(prohibited_bc))
888 self.assertRunNotOK(self.directory, "-o 1", "--hardlink-dupes")
897 with tempfile.TemporaryDirectory() as path:
899 script = script_helper.make_script(path, "script", "a = 0")
902 args = ["-q", "-o 0", "-o 1", "-o 2"]
904 args.append("--hardlink-dupes")
905 self.assertRunOK(path, *args)
928 # Test hardlink_dupes parameter of compileall.compile_dir()
931 self.path = None
935 with tempfile.TemporaryDirectory() as path:
936 self.path = path
937 yield path
938 self.path = None
941 return script_helper.make_script(self.path, name, code)
944 compileall.compile_dir(self.path, quiet=True, optimize=optimize,
953 compileall.compile_dir(self.path, quiet=True, optimize=0,
958 compileall.compile_dir(self.path, quiet=True, optimize=[0, 0],
998 # Test deduplication on all combinations
1032 # Test compile_dir() when pyc files already exists and the script
1046 # Recompilation without -o 1
1049 # opt-1.pyc should have the same inode as before and others should not
1053 # opt-1.pyc and opt-2.pyc have different content
1057 # Test that import updates a single pyc file when pyc files already
1071 # Import the module in Python with -O (optimization level 1)
1073 "-O", "-c", "import module", __isolated=False, PYTHONPATH=self.path
1076 # Only opt-1.pyc is changed
1080 # opt-1.pyc and opt-2.pyc have different content