Debian Codegraph @

lib-python/3/test/test_tools/test_makefile.py

raw symbols SCIP
1 """
2 Tests for `Makefile`.
3 """
4
5 import os
6 import unittest
7 from test import support
8 import sysconfig
9
10 MAKEFILE = sysconfig.get_makefile_filename()
11
12 if not support.check_impl_detail(cpython=True):
13 raise unittest.SkipTest('cpython only')
14 if not os.path.exists(MAKEFILE) or not os.path.isfile(MAKEFILE):
15 raise unittest.SkipTest('Makefile could not be found')
16
17
18 class TestMakefile(unittest.TestCase):
19 def list_test_dirs(self):
20 result = []
21 found_testsubdirs = False
22 with open(MAKEFILE, 'r', encoding='utf-8') as f:
23 for line in f:
24 if line.startswith('TESTSUBDIRS='):
25 found_testsubdirs = True
26 result.append(
27 line.removeprefix('TESTSUBDIRS=').replace(
28 '\\', '',
29 ).strip(),
30 )
31 continue
32 if found_testsubdirs:
33 if '\t' not in line:
34 break
35 result.append(line.replace('\\', '').strip())
36
37 # In Python 3.11 (and lower), many test modules are not in
38 # the tests/ directory. This check ignores them.
39 result = [d for d in result if d.startswith('test/') or d == 'test']
40
41 return result
42
43 def test_makefile_test_folders(self):
44 test_dirs = self.list_test_dirs()
45
46 used = []
47 for dirpath, _, _ in os.walk(support.TEST_HOME_DIR):
48 dirname = os.path.basename(dirpath)
49 if dirname == '__pycache__':
50 continue
51
52 relpath = os.path.relpath(dirpath, support.STDLIB_DIR)
53 with self.subTest(relpath=relpath):
54 self.assertIn(
55 relpath,
56 test_dirs,
57 msg=(
58 f"{relpath!r} is not included in the Makefile's list "
59 "of test directories to install"
60 )
61 )
62 used.append(relpath)
63
64 # Check that there are no extra entries:
65 unique_test_dirs = set(test_dirs)
66 self.assertSetEqual(unique_test_dirs, set(used))
67 self.assertEqual(len(test_dirs), len(unique_test_dirs))