1 """Tests for scripts in the Tools directory.
2
3 This file contains extremely basic regression tests for the scripts found in
4 the Tools directory of a Python checkout or tarball which don't have separate
5 tests of their own.
6 """
7
8 import os
9 import sys
10 import unittest
11 from test.support import import_helper
12
13 from test.test_tools import scriptsdir, import_tool, skip_if_missing
14
15 skip_if_missing()
16
17 class ESC[4;38;5;81mTestSundryScripts(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
18 # At least make sure the rest don't have syntax errors. When tests are
19 # added for a script it should be added to the allowlist below.
20
21 # scripts that have independent tests.
22 allowlist = ['reindent', 'pdeps', 'gprof2html', 'md5sum']
23 # scripts that can't be imported without running
24 denylist = ['make_ctype']
25 # scripts that use windows-only modules
26 windows_only = ['win_add2path']
27 # denylisted for other reasons
28 other = ['analyze_dxp', '2to3']
29
30 skiplist = denylist + allowlist + windows_only + other
31
32 def test_sundry(self):
33 old_modules = import_helper.modules_setup()
34 try:
35 for fn in os.listdir(scriptsdir):
36 if not fn.endswith('.py'):
37 continue
38
39 name = fn[:-3]
40 if name in self.skiplist:
41 continue
42
43 import_tool(name)
44 finally:
45 # Unload all modules loaded in this test
46 import_helper.modules_cleanup(*old_modules)
47
48 @unittest.skipIf(sys.platform != "win32", "Windows-only test")
49 def test_sundry_windows(self):
50 for name in self.windows_only:
51 import_tool(name)
52
53 def test_analyze_dxp_import(self):
54 if hasattr(sys, 'getdxp'):
55 import_tool('analyze_dxp')
56 else:
57 with self.assertRaises(RuntimeError):
58 import_tool('analyze_dxp')
59
60
61 if __name__ == '__main__':
62 unittest.main()