Mercurial > public > mercurial-scm > hg
comparison tests/test-run-tests.py @ 25061:625dd917f04f
test-run-tests: fix for Python 3.5
This test now passes in both 3.5 and 2.6.
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 14 Apr 2015 10:57:15 -0400 |
parents | 56610da39b48 |
children | f798ffe7cb08 |
comparison
equal
deleted
inserted
replaced
25060:29e54fe22a3f | 25061:625dd917f04f |
---|---|
1 """test line matching with some failing examples and some which warn | 1 """test line matching with some failing examples and some which warn |
2 | 2 |
3 run-test.t only checks positive matches and can not see warnings | 3 run-test.t only checks positive matches and can not see warnings |
4 (both by design) | 4 (both by design) |
5 """ | 5 """ |
6 from __future__ import print_function | |
6 | 7 |
7 import os, re | 8 import os, re |
8 # this is hack to make sure no escape characters are inserted into the output | 9 # this is hack to make sure no escape characters are inserted into the output |
9 if 'TERM' in os.environ: | 10 if 'TERM' in os.environ: |
10 del os.environ['TERM'] | 11 del os.environ['TERM'] |
11 import doctest | 12 import doctest |
12 run_tests = __import__('run-tests') | 13 run_tests = __import__('run-tests') |
13 | 14 |
15 def prn(ex): | |
16 m = ex.args[0] | |
17 if isinstance(m, str): | |
18 print(m) | |
19 else: | |
20 print(m.decode('utf-8')) | |
21 | |
14 def lm(expected, output): | 22 def lm(expected, output): |
15 r"""check if output matches expected | 23 r"""check if output matches expected |
16 | 24 |
17 does it generally work? | 25 does it generally work? |
18 >>> lm('H*e (glob)\n', 'Here\n') | 26 >>> lm(b'H*e (glob)\n', b'Here\n') |
19 True | 27 True |
20 | 28 |
21 fail on bad test data | 29 fail on bad test data |
22 >>> try: lm('a\n','a') | 30 >>> try: lm(b'a\n',b'a') |
23 ... except AssertionError, ex: print ex | 31 ... except AssertionError as ex: print(ex) |
24 missing newline | 32 missing newline |
25 >>> try: lm('single backslash\n', 'single \backslash\n') | 33 >>> try: lm(b'single backslash\n', b'single \backslash\n') |
26 ... except AssertionError, ex: print ex | 34 ... except AssertionError as ex: prn(ex) |
27 single backslash or unknown char | 35 single backslash or unknown char |
28 """ | 36 """ |
29 assert expected.endswith('\n') and output.endswith('\n'), 'missing newline' | 37 assert (expected.endswith(b'\n') |
30 assert not re.search(r'[^ \w\\/\r\n()*?]', expected + output), \ | 38 and output.endswith(b'\n')), 'missing newline' |
31 'single backslash or unknown char' | 39 assert not re.search(br'[^ \w\\/\r\n()*?]', expected + output), \ |
40 b'single backslash or unknown char' | |
32 match = run_tests.TTest.linematch(expected, output) | 41 match = run_tests.TTest.linematch(expected, output) |
33 if isinstance(match, str): | 42 if isinstance(match, str): |
34 return 'special: ' + match | 43 return 'special: ' + match |
44 elif isinstance(match, bytes): | |
45 return 'special: ' + match.decode('utf-8') | |
35 else: | 46 else: |
36 return bool(match) # do not return match object | 47 return bool(match) # do not return match object |
37 | 48 |
38 def wintests(): | 49 def wintests(): |
39 r"""test matching like running on windows | 50 r"""test matching like running on windows |
41 enable windows matching on any os | 52 enable windows matching on any os |
42 >>> _osaltsep = os.altsep | 53 >>> _osaltsep = os.altsep |
43 >>> os.altsep = True | 54 >>> os.altsep = True |
44 | 55 |
45 valid match on windows | 56 valid match on windows |
46 >>> lm('g/a*/d (glob)\n', 'g\\abc/d\n') | 57 >>> lm(b'g/a*/d (glob)\n', b'g\\abc/d\n') |
47 True | 58 True |
48 | 59 |
49 direct matching, glob unnecessary | 60 direct matching, glob unnecessary |
50 >>> lm('g/b (glob)\n', 'g/b\n') | 61 >>> lm(b'g/b (glob)\n', b'g/b\n') |
51 'special: -glob' | 62 'special: -glob' |
52 | 63 |
53 missing glob | 64 missing glob |
54 >>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n') | 65 >>> lm(b'/g/c/d/fg\n', b'\\g\\c\\d/fg\n') |
55 'special: +glob' | 66 'special: +glob' |
56 | 67 |
57 restore os.altsep | 68 restore os.altsep |
58 >>> os.altsep = _osaltsep | 69 >>> os.altsep = _osaltsep |
59 """ | 70 """ |
65 disable windows matching on any os | 76 disable windows matching on any os |
66 >>> _osaltsep = os.altsep | 77 >>> _osaltsep = os.altsep |
67 >>> os.altsep = False | 78 >>> os.altsep = False |
68 | 79 |
69 backslash does not match slash | 80 backslash does not match slash |
70 >>> lm('h/a* (glob)\n', 'h\\ab\n') | 81 >>> lm(b'h/a* (glob)\n', b'h\\ab\n') |
71 False | 82 False |
72 | 83 |
73 direct matching glob can not be recognized | 84 direct matching glob can not be recognized |
74 >>> lm('h/b (glob)\n', 'h/b\n') | 85 >>> lm(b'h/b (glob)\n', b'h/b\n') |
75 True | 86 True |
76 | 87 |
77 missing glob can not not be recognized | 88 missing glob can not not be recognized |
78 >>> lm('/h/c/df/g/\n', '\\h/c\\df/g\\\n') | 89 >>> lm(b'/h/c/df/g/\n', b'\\h/c\\df/g\\\n') |
79 False | 90 False |
80 | 91 |
81 restore os.altsep | 92 restore os.altsep |
82 >>> os.altsep = _osaltsep | 93 >>> os.altsep = _osaltsep |
83 """ | 94 """ |