|
| 1 | +""" |
| 2 | +Tests for `Makefile`. |
| 3 | +""" |
| 4 | + |
| 5 | +import os |
| 6 | +import unittest |
| 7 | +from test import support |
| 8 | + |
| 9 | +MAKEFILE = os.path.join(support.REPO_ROOT, 'Makefile') |
| 10 | + |
| 11 | +if not support.check_impl_detail(cpython=True): |
| 12 | + raise unittest.SkipTest('cpython only') |
| 13 | +if support.MS_WINDOWS: |
| 14 | + raise unittest.SkipTest('Windows does not support make') |
| 15 | +if not os.path.exists(MAKEFILE) or not os.path.isfile(MAKEFILE): |
| 16 | + raise unittest.SkipTest('Makefile could not be found') |
| 17 | + |
| 18 | +try: |
| 19 | + import _testcapi |
| 20 | +except ImportError: |
| 21 | + TEST_MODULES = False |
| 22 | +else: |
| 23 | + TEST_MODULES = True |
| 24 | + |
| 25 | +@support.requires_subprocess() |
| 26 | +class TestMakefile(unittest.TestCase): |
| 27 | + def list_test_dirs(self): |
| 28 | + import subprocess |
| 29 | + return subprocess.check_output( |
| 30 | + ['make', '-C', support.REPO_ROOT, 'listtestmodules'], |
| 31 | + universal_newlines=True, |
| 32 | + encoding='utf-8', |
| 33 | + ) |
| 34 | + |
| 35 | + def check_existing_test_modules(self, result): |
| 36 | + test_dirs = result.split(' ') |
| 37 | + unique_test_dirs = set(test_dirs) |
| 38 | + self.assertEqual(len(test_dirs), len(unique_test_dirs)) |
| 39 | + |
| 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 | + with self.subTest(dirpath=dirpath): |
| 49 | + relpath = os.path.relpath(dirpath, support.STDLIB_DIR) |
| 50 | + self.assertIn(relpath, test_dirs) |
| 51 | + used.append(relpath) |
| 52 | + |
| 53 | + # Check that there are no extra entries: |
| 54 | + self.assertEqual( |
| 55 | + unique_test_dirs.symmetric_difference(set(used)), |
| 56 | + set(), |
| 57 | + ) |
| 58 | + |
| 59 | + def check_missing_test_modules(self, result): |
| 60 | + self.assertEqual(result, '') |
| 61 | + |
| 62 | + def test_makefile_test_folders(self): |
| 63 | + result = self.list_test_dirs().strip() |
| 64 | + if TEST_MODULES: |
| 65 | + self.check_existing_test_modules(result) |
| 66 | + else: |
| 67 | + self.check_missing_test_modules(result) |
0 commit comments