test-run-tests.py
99 lines
| 2.6 KiB
| text/x-python
|
PythonLexer
/ tests / test-run-tests.py
|
r20271 | """test line matching with some failing examples and some which warn | ||
run-test.t only checks positive matches and can not see warnings | ||||
(both by design) | ||||
""" | ||||
|
r28917 | from __future__ import absolute_import, print_function | ||
|
r20271 | |||
|
r28917 | import doctest | ||
import os | ||||
import re | ||||
|
r20284 | # this is hack to make sure no escape characters are inserted into the output | ||
if 'TERM' in os.environ: | ||||
del os.environ['TERM'] | ||||
|
r20271 | run_tests = __import__('run-tests') | ||
|
r25061 | def prn(ex): | ||
m = ex.args[0] | ||||
if isinstance(m, str): | ||||
print(m) | ||||
else: | ||||
print(m.decode('utf-8')) | ||||
|
r20271 | def lm(expected, output): | ||
r"""check if output matches expected | ||||
does it generally work? | ||||
|
r25061 | >>> lm(b'H*e (glob)\n', b'Here\n') | ||
|
r20271 | True | ||
fail on bad test data | ||||
|
r25061 | >>> try: lm(b'a\n',b'a') | ||
... except AssertionError as ex: print(ex) | ||||
|
r20271 | missing newline | ||
|
r25061 | >>> try: lm(b'single backslash\n', b'single \backslash\n') | ||
... except AssertionError as ex: prn(ex) | ||||
|
r20271 | single backslash or unknown char | ||
""" | ||||
|
r25061 | assert (expected.endswith(b'\n') | ||
and output.endswith(b'\n')), 'missing newline' | ||||
assert not re.search(br'[^ \w\\/\r\n()*?]', expected + output), \ | ||||
b'single backslash or unknown char' | ||||
|
r21315 | match = run_tests.TTest.linematch(expected, output) | ||
|
r20273 | if isinstance(match, str): | ||
return 'special: ' + match | ||||
|
r25061 | elif isinstance(match, bytes): | ||
return 'special: ' + match.decode('utf-8') | ||||
|
r20273 | else: | ||
return bool(match) # do not return match object | ||||
|
r20271 | |||
def wintests(): | ||||
r"""test matching like running on windows | ||||
enable windows matching on any os | ||||
>>> _osaltsep = os.altsep | ||||
>>> os.altsep = True | ||||
valid match on windows | ||||
|
r25061 | >>> lm(b'g/a*/d (glob)\n', b'g\\abc/d\n') | ||
|
r20271 | True | ||
direct matching, glob unnecessary | ||||
|
r25061 | >>> lm(b'g/b (glob)\n', b'g/b\n') | ||
|
r20274 | 'special: -glob' | ||
|
r20271 | |||
missing glob | ||||
|
r25061 | >>> lm(b'/g/c/d/fg\n', b'\\g\\c\\d/fg\n') | ||
|
r20273 | 'special: +glob' | ||
|
r20271 | |||
restore os.altsep | ||||
>>> os.altsep = _osaltsep | ||||
""" | ||||
|
r20284 | pass | ||
|
r20271 | |||
def otherostests(): | ||||
r"""test matching like running on non-windows os | ||||
disable windows matching on any os | ||||
>>> _osaltsep = os.altsep | ||||
>>> os.altsep = False | ||||
backslash does not match slash | ||||
|
r25061 | >>> lm(b'h/a* (glob)\n', b'h\\ab\n') | ||
|
r20271 | False | ||
direct matching glob can not be recognized | ||||
|
r25061 | >>> lm(b'h/b (glob)\n', b'h/b\n') | ||
|
r20271 | True | ||
missing glob can not not be recognized | ||||
|
r25061 | >>> lm(b'/h/c/df/g/\n', b'\\h/c\\df/g\\\n') | ||
|
r20271 | False | ||
restore os.altsep | ||||
>>> os.altsep = _osaltsep | ||||
""" | ||||
pass | ||||
if __name__ == '__main__': | ||||
doctest.testmod() | ||||