Permalink
Browse files

basic basic test suite, 'mk test' to run with all pythons, add initia…

…l Python 3 support
  • Loading branch information...
1 parent 4604166 commit ab1f4131050cf36016c6e917772501d7ce251c9c @trentm committed Jul 12, 2010
Showing with 79 additions and 12 deletions.
  1. +16 −12 lib/testlib.py
  2. +7 −0 test/api.doctests
  3. +24 −0 test/test.py
  4. +32 −0 test/test_testlib.py
View
@@ -248,9 +248,11 @@ def testmods_from_testdir(testdir):
finally:
os.chdir(old_dir)
sys.path.remove(testabsdir)
- except TestSkipped, ex:
+ except TestSkipped:
+ _, ex, _ = sys.exc_info()
log.warn("'%s' module skipped: %s", testmod_name, ex)
- except Exception, ex:
+ except Exception:
+ _, ex, _ = sys.exc_info()
log.warn("could not import test module '%s': %s (skipping, "
"run with '-d' for full traceback)",
testmod_path, ex)
@@ -289,7 +291,8 @@ class TestListLoader(unittest.TestLoader):
continue
for testcase in loader.loadTestsFromTestCase(testcase_class):
yield testcase
- except Exception, ex:
+ except Exception:
+ _, ex, _ = sys.exc_info()
testmod_path = testmod.__file__
if testmod_path.endswith(".pyc"):
testmod_path = testmod_path[:-1]
@@ -442,23 +445,23 @@ def list_tests(testdir_from_ns, tags):
if log.isEnabledFor(logging.INFO): # long-form
for i, t in enumerate(tests):
if i:
- print
+ print()
testfile = t.testmod.__file__
if testfile.endswith(".pyc"):
testfile = testfile[:-1]
- print "%s:" % t.shortname()
- print " from: %s#%s.%s" \
- % (testfile, t.testcase.__class__.__name__, t.testfn_name)
+ print("%s:" % t.shortname())
+ print(" from: %s#%s.%s" % (testfile,
+ t.testcase.__class__.__name__, t.testfn_name))
wrapped = textwrap.fill(' '.join(t.tags()), WIDTH-10)
- print " tags: %s" % _indent(wrapped, 8, True)
+ print(" tags: %s" % _indent(wrapped, 8, True))
if t.doc():
- print _indent(t.doc(), width=2)
+ print(_indent(t.doc(), width=2))
else:
for t in tests:
line = t.shortname() + ' '
if t.explicit_tags():
line += '[%s]' % ' '.join(t.explicit_tags())
- print line
+ print(line)
#---- text test runner that can handle TestSkipped reasonably
@@ -696,13 +699,14 @@ def harness(testdir_from_ns={None: os.curdir}, argv=sys.argv,
logging.basicConfig()
try:
log_level, action, tags = _parse_opts(argv[1:], default_tags or [])
- except getopt.error, ex:
+ except getopt.error:
+ _, ex, _ = sys.exc_info()
log.error(str(ex) + " (did you need a '--' before a '-TAG' argument?)")
return 1
log.setLevel(log_level)
if action == "help":
- print __doc__
+ print(__doc__)
return 0
if action == "list":
return list_tests(testdir_from_ns, tags)
View
@@ -0,0 +1,7 @@
+
+>>> import testlib
+>>> hasattr(testlib, "__version__")
+True
+>>> hasattr(testlib, "__version_info__")
+True
+
View
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+# Copyright (c) 2010 ActiveState Software Inc.
+# License: MIT (http://www.opensource.org/licenses/mit-license.php)
+
+"""The testlib test suite entry point."""
+
+import os
+from os.path import exists, join, abspath, dirname, normpath
+import sys
+import logging
+
+log = logging.getLogger("test")
+
+def setup():
+ top_dir = dirname(dirname(abspath(__file__)))
+ lib_dir = join(top_dir, "lib")
+ sys.path.insert(0, lib_dir)
+
+if __name__ == "__main__":
+ logging.basicConfig()
+ setup()
+ import testlib
+ sys.exit( testlib.harness() )
+
View
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# Copyright (c) 2010 ActiveState Software Inc.
+# License: MIT (http://www.opensource.org/licenses/mit-license.php)
+
+"""Test testlib.py."""
+
+import os
+import sys
+from os.path import join, dirname, abspath, exists, splitext, basename
+import re
+from glob import glob
+from pprint import pprint
+import unittest
+import codecs
+import difflib
+import doctest
+
+from testlib import TestError, TestSkipped, tag
+
+class DocTestsTestCase(unittest.TestCase):
+ def test_api(self):
+ if sys.version_info[:2] < (2,4):
+ raise TestSkipped("no DocFileTest in Python <=2.3")
+ test = doctest.DocFileTest("api.doctests")
+ test.runTest()
+
+ def test_internal(self):
+ import testlib
+ doctest.testmod(testlib)
+
+
+

0 comments on commit ab1f413

Please sign in to comment.