Show More
@@ -0,0 +1,83 b'' | |||
|
1 | """test line matching with some failing examples and some which warn | |
|
2 | ||
|
3 | run-test.t only checks positive matches and can not see warnings | |
|
4 | (both by design) | |
|
5 | """ | |
|
6 | ||
|
7 | ||
|
8 | import doctest, os, re | |
|
9 | run_tests = __import__('run-tests') | |
|
10 | ||
|
11 | def lm(expected, output): | |
|
12 | r"""check if output matches expected | |
|
13 | ||
|
14 | does it generally work? | |
|
15 | >>> lm('H*e (glob)\n', 'Here\n') | |
|
16 | True | |
|
17 | ||
|
18 | fail on bad test data | |
|
19 | >>> try: lm('a\n','a') | |
|
20 | ... except AssertionError, ex: print ex | |
|
21 | missing newline | |
|
22 | >>> try: lm('single backslash\n', 'single \backslash\n') | |
|
23 | ... except AssertionError, ex: print ex | |
|
24 | single backslash or unknown char | |
|
25 | """ | |
|
26 | assert expected.endswith('\n') and output.endswith('\n'), 'missing newline' | |
|
27 | assert not re.search(r'[^ \w\\/\r\n()*?]', expected + output), \ | |
|
28 | 'single backslash or unknown char' | |
|
29 | match = run_tests.linematch(expected, output) | |
|
30 | return bool(match) | |
|
31 | ||
|
32 | def wintests(): | |
|
33 | r"""test matching like running on windows | |
|
34 | ||
|
35 | enable windows matching on any os | |
|
36 | >>> _osaltsep = os.altsep | |
|
37 | >>> os.altsep = True | |
|
38 | ||
|
39 | valid match on windows | |
|
40 | >>> lm('g/a*/d (glob)\n', 'g\\abc/d\n') | |
|
41 | True | |
|
42 | ||
|
43 | direct matching, glob unnecessary | |
|
44 | >>> lm('g/b (glob)\n', 'g/b\n') | |
|
45 | <BLANKLINE> | |
|
46 | Info, unnecessary glob: g/b (glob) | |
|
47 | True | |
|
48 | ||
|
49 | missing glob | |
|
50 | >>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n') | |
|
51 | False | |
|
52 | ||
|
53 | restore os.altsep | |
|
54 | >>> os.altsep = _osaltsep | |
|
55 | """ | |
|
56 | os.altsep # for pyflakes, because it does not see os in the doctest | |
|
57 | ||
|
58 | def otherostests(): | |
|
59 | r"""test matching like running on non-windows os | |
|
60 | ||
|
61 | disable windows matching on any os | |
|
62 | >>> _osaltsep = os.altsep | |
|
63 | >>> os.altsep = False | |
|
64 | ||
|
65 | backslash does not match slash | |
|
66 | >>> lm('h/a* (glob)\n', 'h\\ab\n') | |
|
67 | False | |
|
68 | ||
|
69 | direct matching glob can not be recognized | |
|
70 | >>> lm('h/b (glob)\n', 'h/b\n') | |
|
71 | True | |
|
72 | ||
|
73 | missing glob can not not be recognized | |
|
74 | >>> lm('/h/c/df/g/\n', '\\h/c\\df/g\\\n') | |
|
75 | False | |
|
76 | ||
|
77 | restore os.altsep | |
|
78 | >>> os.altsep = _osaltsep | |
|
79 | """ | |
|
80 | pass | |
|
81 | ||
|
82 | if __name__ == '__main__': | |
|
83 | doctest.testmod() |
General Comments 0
You need to be logged in to leave comments.
Login now