(self)
| 593 | |
| 594 | @support.requires_subprocess() |
| 595 | def test_startup_imports(self): |
| 596 | # Get sys.path in isolated mode (python3 -I) |
| 597 | popen = subprocess.Popen([sys.executable, '-X', 'utf8', '-I', |
| 598 | '-c', 'import sys; print(repr(sys.path))'], |
| 599 | stdout=subprocess.PIPE, |
| 600 | encoding='utf-8', |
| 601 | errors='surrogateescape') |
| 602 | stdout = popen.communicate()[0] |
| 603 | self.assertEqual(popen.returncode, 0, repr(stdout)) |
| 604 | isolated_paths = ast.literal_eval(stdout) |
| 605 | |
| 606 | # bpo-27807: Even with -I, the site module executes all .pth files |
| 607 | # found in sys.path (see site.addpackage()). Skip the test if at least |
| 608 | # one .pth file is found. |
| 609 | for path in isolated_paths: |
| 610 | pth_files = glob.glob(os.path.join(glob.escape(path), "*.pth")) |
| 611 | if pth_files: |
| 612 | self.skipTest(f"found {len(pth_files)} .pth files in: {path}") |
| 613 | |
| 614 | # This tests checks which modules are loaded by Python when it |
| 615 | # initially starts upon startup. |
| 616 | popen = subprocess.Popen([sys.executable, '-X', 'utf8', '-I', '-v', |
| 617 | '-c', 'import sys; print(set(sys.modules))'], |
| 618 | stdout=subprocess.PIPE, |
| 619 | stderr=subprocess.PIPE, |
| 620 | encoding='utf-8', |
| 621 | errors='surrogateescape') |
| 622 | stdout, stderr = popen.communicate() |
| 623 | self.assertEqual(popen.returncode, 0, (stdout, stderr)) |
| 624 | modules = ast.literal_eval(stdout) |
| 625 | |
| 626 | self.assertIn('site', modules) |
| 627 | |
| 628 | # http://bugs.python.org/issue19205 |
| 629 | re_mods = {'re', '_sre', 're._compiler', 're._constants', 're._parser'} |
| 630 | self.assertFalse(modules.intersection(re_mods), stderr) |
| 631 | |
| 632 | # http://bugs.python.org/issue9548 |
| 633 | self.assertNotIn('locale', modules, stderr) |
| 634 | |
| 635 | # http://bugs.python.org/issue19209 |
| 636 | self.assertNotIn('copyreg', modules, stderr) |
| 637 | |
| 638 | # http://bugs.python.org/issue19218 |
| 639 | collection_mods = {'_collections', 'collections', 'functools', |
| 640 | 'heapq', 'itertools', 'keyword', 'operator', |
| 641 | 'reprlib', 'types', 'weakref' |
| 642 | }.difference(sys.builtin_module_names) |
| 643 | self.assertFalse(modules.intersection(collection_mods), stderr) |
| 644 | |
| 645 | @support.requires_subprocess() |
| 646 | def test_startup_interactivehook(self): |
nothing calls this directly
no test coverage detected