Skip to content

Commit 72dbea2

Browse files
authored
gh-115421: Test that our Makefile has all needed test folders (GH-115813)
1 parent 72d3cc9 commit 72dbea2

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
return result
37+
38+
def test_makefile_test_folders(self):
39+
test_dirs = self.list_test_dirs()
40+
idle_test = 'idlelib/idle_test'
41+
self.assertIn(idle_test, test_dirs)
42+
43+
used = [idle_test]
44+
for dirpath, _, _ in os.walk(support.TEST_HOME_DIR):
45+
dirname = os.path.basename(dirpath)
46+
if dirname == '__pycache__':
47+
continue
48+
49+
relpath = os.path.relpath(dirpath, support.STDLIB_DIR)
50+
with self.subTest(relpath=relpath):
51+
self.assertIn(
52+
relpath,
53+
test_dirs,
54+
msg=(
55+
f"{relpath!r} is not included in the Makefile's list "
56+
"of test directories to install"
57+
)
58+
)
59+
used.append(relpath)
60+
61+
# Check that there are no extra entries:
62+
unique_test_dirs = set(test_dirs)
63+
self.assertSetEqual(unique_test_dirs, set(used))
64+
self.assertEqual(len(test_dirs), len(unique_test_dirs))

0 commit comments

Comments
 (0)