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