File: test_support.py

package info (click to toggle)
python-xml 0.8.4-10.1%2Blenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,972 kB
  • ctags: 10,628
  • sloc: python: 46,730; ansic: 14,354; xml: 968; makefile: 201; sh: 20
file content (52 lines) | stat: -rw-r--r-- 1,673 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""PyUNIT-based compatibility module for the test.test_support module.

When running PyUNIT-based tests, this should be used for the
run_suite() and run_unittest() functions.
"""

from test.test_support import verbose, TestFailed

try:
    from test.test_support import run_suite, run_unittest
except ImportError:

    #=======================================================================
    # Preliminary PyUNIT integration.

    import sys
    import unittest


    class BasicTestRunner:
        def run(self, test):
            result = unittest.TestResult()
            test(result)
            return result


    def run_suite(suite, testclass=None):
        """Run tests from a unittest.TestSuite-derived class."""
        if verbose:
            runner = unittest.TextTestRunner(sys.stdout, verbosity=2)
        else:
            runner = BasicTestRunner()

        result = runner.run(suite)
        if not result.wasSuccessful():
            if len(result.errors) == 1 and not result.failures:
                err = result.errors[0][1]
            elif len(result.failures) == 1 and not result.errors:
                err = result.failures[0][1]
            else:
                if testclass is None:
                    msg = "errors occurred; run in verbose mode for details"
                else:
                    msg = "errors occurred in %s.%s" \
                          % (testclass.__module__, testclass.__name__)
                raise TestFailed(msg)
            raise TestFailed(err)


    def run_unittest(testclass):
        """Run tests from a unittest.TestCase-derived class."""
        run_suite(unittest.makeSuite(testclass), testclass)