1"""Tests for scripts in the Tools directory.
2
3This file contains extremely basic regression tests for the scripts found in
4the Tools directory of a Python checkout or tarball which don't have separate
5tests of their own, such as h2py.py.
6"""
7
8import os
9import sys
10import unittest
11from test import support
12
13from test.test_tools import scriptsdir, import_tool, skip_if_missing
14
15skip_if_missing()
16
17class TestSundryScripts(unittest.TestCase):
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 whitelist below.
20
21    # scripts that have independent tests.
22    whitelist = ['reindent', 'pdeps', 'gprof2html', 'md5sum']
23    # scripts that can't be imported without running
24    blacklist = ['make_ctype']
25    # scripts that use windows-only modules
26    windows_only = ['win_add2path']
27    # blacklisted for other reasons
28    other = ['analyze_dxp', '2to3']
29
30    skiplist = blacklist + whitelist + windows_only + other
31
32    def test_sundry(self):
33        old_modules = support.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            support.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
61if __name__ == '__main__':
62    unittest.main()
63