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

Side by Side Diff: Lib/test/test_compileall.py

Issue 26101: Lib/test/test_compileall.py fails when run directly
Patch Set: Created 3 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import sys 1 import sys
2 import compileall 2 import compileall
3 import importlib.util 3 import importlib.util
4 import test.test_importlib.util 4 import test.test_importlib.util
5 import os 5 import os
6 import pathlib 6 import pathlib
7 import py_compile 7 import py_compile
8 import shutil 8 import shutil
9 import struct 9 import struct
10 import tempfile 10 import tempfile
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 os.unlink(self.bc_path) 96 os.unlink(self.bc_path)
97 os.unlink(self.bc_path2) 97 os.unlink(self.bc_path2)
98 # Test against bad files 98 # Test against bad files
99 self.add_bad_source_file() 99 self.add_bad_source_file()
100 self.assertFalse(compileall.compile_file(self.bad_source_path, 100 self.assertFalse(compileall.compile_file(self.bad_source_path,
101 force=False, quiet=2)) 101 force=False, quiet=2))
102 self.assertFalse(compileall.compile_dir(self.directory, 102 self.assertFalse(compileall.compile_dir(self.directory,
103 force=False, quiet=2)) 103 force=False, quiet=2))
104 104
105 def test_compile_path(self): 105 def test_compile_path(self):
106 # Exclude Lib/test/ which contains invalid Python files like
107 # Lib/test/badsyntax_pep3120.py
108 testdir = os.path.realpath(os.path.dirname(__file__))
109 if testdir in sys.path:
110 self.addCleanup(setattr, sys, 'path', sys.path)
111
112 sys.path = list(sys.path)
113 try:
114 sys.path.remove(testdir)
115 except ValueError:
116 pass
117
106 self.assertTrue(compileall.compile_path(quiet=2)) 118 self.assertTrue(compileall.compile_path(quiet=2))
107 119
108 with test.test_importlib.util.import_state(path=[self.directory]): 120 with test.test_importlib.util.import_state(path=[self.directory]):
109 self.add_bad_source_file() 121 self.add_bad_source_file()
110 self.assertFalse(compileall.compile_path(skip_curdir=False, 122 self.assertFalse(compileall.compile_path(skip_curdir=False,
111 force=True, quiet=2)) 123 force=True, quiet=2))
112 124
113 def test_no_pycache_in_non_package(self): 125 def test_no_pycache_in_non_package(self):
114 # Bug 8563 reported that __pycache__ directories got created by 126 # Bug 8563 reported that __pycache__ directories got created by
115 # compile_file() for non-.py files. 127 # compile_file() for non-.py files.
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 def test_workers_available_cores(self, compile_dir): 527 def test_workers_available_cores(self, compile_dir):
516 with mock.patch("sys.argv", 528 with mock.patch("sys.argv",
517 new=[sys.executable, self.directory, "-j0"]): 529 new=[sys.executable, self.directory, "-j0"]):
518 compileall.main() 530 compileall.main()
519 self.assertTrue(compile_dir.called) 531 self.assertTrue(compile_dir.called)
520 self.assertEqual(compile_dir.call_args[-1]['workers'], None) 532 self.assertEqual(compile_dir.call_args[-1]['workers'], None)
521 533
522 534
523 if __name__ == "__main__": 535 if __name__ == "__main__":
524 unittest.main() 536 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

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