File: driver.py

package info (click to toggle)
mypy 0.812-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 18,596 kB
  • sloc: python: 74,869; cpp: 11,212; ansic: 3,935; makefile: 238; sh: 13
file content (41 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download
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
"""Default driver for run tests (run-*.test).

This imports the 'native' module (containing the compiled test cases)
and calls each function starting with test_, and reports any
exceptions as failures.

Test cases can provide a custom driver.py that overrides this file.
"""

import sys
import native

failures = []

for name in dir(native):
    if name.startswith('test_'):
        test_func = getattr(native, name)
        try:
            test_func()
        except Exception as e:
            failures.append(sys.exc_info())

if failures:
    from traceback import print_exception, format_tb
    import re

    def extract_line(tb):
        formatted = '\n'.join(format_tb(tb))
        m = re.search('File "native.py", line ([0-9]+), in test_', formatted)
        return m.group(1)

    # Sort failures by line number of test function.
    failures = sorted(failures, key=lambda e: extract_line(e[2]))

    # If there are multiple failures, print stack traces of all but the final failure.
    for e in failures[:-1]:
        print_exception(*e)
        print()

    # Raise exception for the last failure. Test runner will show the traceback.
    raise failures[-1][1]