summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-04-05 01:29:03 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-04-05 01:29:03 (GMT)
commitce9806215b82e4a0e8dd37eb9a669477161adfec (patch)
tree02073b791a0f11927d7adb5e2ecf0305e0474b47 /Lib
parenta701388de1135241b5a8e4c970e06c0e83a66dc0 (diff)
parent54ac832a24a0f40ea3278707420b191be3619c99 (diff)
downloadcpython-ce9806215b82e4a0e8dd37eb9a669477161adfec.zip
cpython-ce9806215b82e4a0e8dd37eb9a669477161adfec.tar.gz
cpython-ce9806215b82e4a0e8dd37eb9a669477161adfec.tar.bz2
Merge #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
This patch changes a few of the scripts to have __name__=='__main__' clauses so that they are importable without running. Also fixes the syntax errors revealed by the tests.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_tools.py45
1 files changed, 43 insertions, 2 deletions
diff --git a/Lib/test/test_tools.py b/Lib/test/test_tools.py
index 1682124..8c9054a 100644
--- a/Lib/test/test_tools.py
+++ b/Lib/test/test_tools.py
@@ -5,6 +5,7 @@ Tools directory of a Python checkout or tarball, such as reindent.py.
"""
import os
+import sys
import unittest
import sysconfig
from test import support
@@ -17,10 +18,11 @@ if not sysconfig.is_python_build():
srcdir = sysconfig.get_config_var('projectbase')
basepath = os.path.join(os.getcwd(), srcdir, 'Tools')
+scriptsdir = os.path.join(basepath, 'scripts')
class ReindentTests(unittest.TestCase):
- script = os.path.join(basepath, 'scripts', 'reindent.py')
+ script = os.path.join(scriptsdir, 'reindent.py')
def test_noargs(self):
assert_python_ok(self.script)
@@ -31,8 +33,47 @@ class ReindentTests(unittest.TestCase):
self.assertGreater(err, b'')
+class TestSundryScripts(unittest.TestCase):
+ # At least make sure the rest don't have syntax errors. When tests are
+ # added for a script it should be added to the whitelist below.
+
+ # scripts that have independent tests.
+ whitelist = ['reindent.py']
+ # scripts that can't be imported without running
+ blacklist = ['make_ctype.py']
+ # scripts that use windows-only modules
+ windows_only = ['win_add2path.py']
+ # blacklisted for other reasons
+ other = ['analyze_dxp.py']
+
+ skiplist = blacklist + whitelist + windows_only + other
+
+ def setUp(self):
+ cm = support.DirsOnSysPath(scriptsdir)
+ cm.__enter__()
+ self.addCleanup(cm.__exit__)
+
+ def test_sundry(self):
+ for fn in os.listdir(scriptsdir):
+ if fn.endswith('.py') and fn not in self.skiplist:
+ __import__(fn[:-3])
+
+ @unittest.skipIf(sys.platform != "win32", "Windows-only test")
+ def test_sundry_windows(self):
+ for fn in self.windows_only:
+ __import__(fn[:-3])
+
+ def test_analyze_dxp_import(self):
+ if hasattr(sys, 'getdxp'):
+ import analyze_dxp
+ else:
+ with self.assertRaises(RuntimeError):
+ import analyze_dxp
+
+
def test_main():
- support.run_unittest(ReindentTests)
+ support.run_unittest(*[obj for obj in globals().values()
+ if isinstance(obj, type)])
if __name__ == '__main__':