annotate tests/test-run-tests.py @ 20271:4453d08a616a

tests: new test for line matching functions in run-tests Test for failing matches and warnings. (The existing test-run-tests.t can not do both by design.) And simulate matching on other os.
author Simon Heimberg <simohe@besonet.ch>
date Thu, 16 Jan 2014 19:07:18 +0100
parents
children d9d6cbbeef0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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)
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
30 return bool(match)
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
31
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
32 def wintests():
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
33 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
34
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
35 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
36 >>> _osaltsep = os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
37 >>> os.altsep = True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
38
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
39 valid match on windows
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
40 >>> 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
41 True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
42
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
43 direct matching, glob unnecessary
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
44 >>> 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
45 <BLANKLINE>
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
46 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
47 True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
48
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
49 missing glob
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
50 >>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
51 False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
52
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
53 restore os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
54 >>> os.altsep = _osaltsep
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 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
57
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
58 def otherostests():
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
59 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
60
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
61 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
62 >>> _osaltsep = os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
63 >>> os.altsep = False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
64
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
65 backslash does not match slash
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
66 >>> 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
67 False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
68
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
69 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
70 >>> 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
71 True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
72
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
73 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
74 >>> 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
75 False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
76
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
77 restore os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
78 >>> os.altsep = _osaltsep
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 pass
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
81
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
82 if __name__ == '__main__':
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
83 doctest.testmod()