blob: 83a1e0df57ab1f6d20f7a2082c530817e86b3d31 [file] [log] [blame]
Éric Araujob4656242012-02-25 16:57:04 +01001"""Tests for scripts in the Tools directory.
2
3This file contains regression tests for some of the scripts found in the
4Tools directory of a Python checkout or tarball, such as reindent.py.
5"""
6
7import os
R David Murray54ac8322012-04-04 21:28:14 -04008import sys
Éric Araujob4656242012-02-25 16:57:04 +01009import unittest
10import sysconfig
11from test import support
12from test.script_helper import assert_python_ok
13
14if not sysconfig.is_python_build():
15 # XXX some installers do contain the tools, should we detect that
16 # and run the tests in that case too?
17 raise unittest.SkipTest('test irrelevant for an installed Python')
18
19srcdir = sysconfig.get_config_var('projectbase')
20basepath = os.path.join(os.getcwd(), srcdir, 'Tools')
R David Murray54ac8322012-04-04 21:28:14 -040021scriptsdir = os.path.join(basepath, 'scripts')
Éric Araujob4656242012-02-25 16:57:04 +010022
23
24class ReindentTests(unittest.TestCase):
R David Murray54ac8322012-04-04 21:28:14 -040025 script = os.path.join(scriptsdir, 'reindent.py')
Éric Araujob4656242012-02-25 16:57:04 +010026
27 def test_noargs(self):
28 assert_python_ok(self.script)
29
30 def test_help(self):
31 rc, out, err = assert_python_ok(self.script, '-h')
32 self.assertEqual(out, b'')
33 self.assertGreater(err, b'')
34
35
R David Murray54ac8322012-04-04 21:28:14 -040036class TestSundryScripts(unittest.TestCase):
37 # At least make sure the rest don't have syntax errors. When tests are
38 # added for a script it should be added to the whitelist below.
39
40 # scripts that have independent tests.
41 whitelist = ['reindent.py']
42 # scripts that can't be imported without running
43 blacklist = ['make_ctype.py']
44 # scripts that use windows-only modules
45 windows_only = ['win_add2path.py']
46 # blacklisted for other reasons
47 other = ['analyze_dxp.py']
48
49 skiplist = blacklist + whitelist + windows_only + other
50
51 def setUp(self):
52 cm = support.DirsOnSysPath(scriptsdir)
53 cm.__enter__()
54 self.addCleanup(cm.__exit__)
55
56 def test_sundry(self):
57 for fn in os.listdir(scriptsdir):
58 if fn.endswith('.py') and fn not in self.skiplist:
59 __import__(fn[:-3])
60
61 @unittest.skipIf(sys.platform != "win32", "Windows-only test")
62 def test_sundry_windows(self):
63 for fn in self.windows_only:
64 __import__(fn[:-3])
65
R David Murrayca60b362012-04-04 22:37:50 -040066 @unittest.skipIf(not support.threading, "test requires _thread module")
R David Murray54ac8322012-04-04 21:28:14 -040067 def test_analyze_dxp_import(self):
68 if hasattr(sys, 'getdxp'):
69 import analyze_dxp
70 else:
71 with self.assertRaises(RuntimeError):
72 import analyze_dxp
73
74
Éric Araujob4656242012-02-25 16:57:04 +010075def test_main():
R David Murray54ac8322012-04-04 21:28:14 -040076 support.run_unittest(*[obj for obj in globals().values()
77 if isinstance(obj, type)])
Éric Araujob4656242012-02-25 16:57:04 +010078
79
80if __name__ == '__main__':
81 unittest.main()