Mercurial > hg
annotate tests/test-run-tests.py @ 30435:b86a448a2965
zstd: vendor python-zstandard 0.5.0
As the commit message for the previous changeset says, we wish
for zstd to be a 1st class citizen in Mercurial. To make that
happen, we need to enable Python to talk to the zstd C API. And
that requires bindings.
This commit vendors a copy of existing Python bindings. Why do we
need to vendor? As the commit message of the previous commit says,
relying on systems in the wild to have the bindings or zstd present
is a losing proposition. By distributing the zstd and bindings with
Mercurial, we significantly increase our chances that zstd will
work. Since zstd will deliver a better end-user experience by
achieving better performance, this benefits our users. Another
reason is that the Python bindings still aren't stable and the
API is somewhat fluid. While Mercurial could be coded to target
multiple versions of the Python bindings, it is safer to bundle
an explicit, known working version.
The added Python bindings are mostly a fully-featured interface
to the zstd C API. They allow one-shot operations, streaming,
reading and writing from objects implements the file object
protocol, dictionary compression, control over low-level compression
parameters, and more. The Python bindings work on Python 2.6,
2.7, and 3.3+ and have been tested on Linux and Windows. There are
CFFI bindings, but they are lacking compared to the C extension.
Upstream work will be needed before we can support zstd with PyPy.
But it will be possible.
The files added in this commit come from Git commit
e637c1b214d5f869cf8116c550dcae23ec13b677 from
https://github.com/indygreg/python-zstandard and are added without
modifications. Some files from the upstream repository have been
omitted, namely files related to continuous integration.
In the spirit of full disclosure, I'm the maintainer of the
"python-zstandard" project and have authored 100% of the code
added in this commit. Unfortunately, the Python bindings have
not been formally code reviewed by anyone. While I've tested
much of the code thoroughly (I even have tests that fuzz APIs),
there's a good chance there are bugs, memory leaks, not well
thought out APIs, etc. If someone wants to review the code and
send feedback to the GitHub project, it would be greatly
appreciated.
Despite my involvement with both projects, my opinions of code
style differ from Mercurial's. The code in this commit introduces
numerous code style violations in Mercurial's linters. So, the code
is excluded from most lints. However, some violations I agree with.
These have been added to the known violations ignore list for now.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 10 Nov 2016 22:15:58 -0800 |
parents | f798ffe7cb08 |
children | eeed23508383 |
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 """ |
28917
f798ffe7cb08
tests: make test-run-tests use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25061
diff
changeset
|
6 from __future__ import absolute_import, print_function |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
7 |
28917
f798ffe7cb08
tests: make test-run-tests use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25061
diff
changeset
|
8 import doctest |
f798ffe7cb08
tests: make test-run-tests use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25061
diff
changeset
|
9 import os |
f798ffe7cb08
tests: make test-run-tests use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25061
diff
changeset
|
10 import re |
20284
e1e6ddaef299
tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents:
20274
diff
changeset
|
11 # this is hack to make sure no escape characters are inserted into the output |
e1e6ddaef299
tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents:
20274
diff
changeset
|
12 if 'TERM' in os.environ: |
e1e6ddaef299
tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents:
20274
diff
changeset
|
13 del os.environ['TERM'] |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
14 run_tests = __import__('run-tests') |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
15 |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
16 def prn(ex): |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
17 m = ex.args[0] |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
18 if isinstance(m, str): |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
19 print(m) |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
20 else: |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
21 print(m.decode('utf-8')) |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
22 |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
23 def lm(expected, output): |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
24 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
|
25 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
26 does it generally work? |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
27 >>> lm(b'H*e (glob)\n', b'Here\n') |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
28 True |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
29 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
30 fail on bad test data |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
31 >>> try: lm(b'a\n',b'a') |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
32 ... except AssertionError as ex: print(ex) |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
33 missing newline |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
34 >>> try: lm(b'single backslash\n', b'single \backslash\n') |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
35 ... except AssertionError as ex: prn(ex) |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
36 single backslash or unknown char |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
37 """ |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
38 assert (expected.endswith(b'\n') |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
39 and output.endswith(b'\n')), 'missing newline' |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
40 assert not re.search(br'[^ \w\\/\r\n()*?]', expected + output), \ |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
41 b'single backslash or unknown char' |
21315
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20284
diff
changeset
|
42 match = run_tests.TTest.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
|
43 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
|
44 return 'special: ' + match |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
45 elif isinstance(match, bytes): |
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
46 return 'special: ' + match.decode('utf-8') |
20273
d9d6cbbeef0d
run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents:
20271
diff
changeset
|
47 else: |
d9d6cbbeef0d
run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents:
20271
diff
changeset
|
48 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
|
49 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
50 def wintests(): |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
51 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
|
52 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
53 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
|
54 >>> _osaltsep = os.altsep |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
55 >>> os.altsep = True |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
56 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
57 valid match on windows |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
58 >>> lm(b'g/a*/d (glob)\n', b'g\\abc/d\n') |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
59 True |
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 direct matching, glob unnecessary |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
62 >>> lm(b'g/b (glob)\n', b'g/b\n') |
20274
7a259dfe24f7
run-tests: print more information on unnecessary glob matching
Simon Heimberg <simohe@besonet.ch>
parents:
20273
diff
changeset
|
63 'special: -glob' |
20271
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 missing glob |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
66 >>> lm(b'/g/c/d/fg\n', b'\\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
|
67 'special: +glob' |
20271
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 restore os.altsep |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
70 >>> os.altsep = _osaltsep |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
71 """ |
20284
e1e6ddaef299
tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents:
20274
diff
changeset
|
72 pass |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
73 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
74 def otherostests(): |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
75 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
|
76 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
77 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
|
78 >>> _osaltsep = os.altsep |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
79 >>> os.altsep = False |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
80 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
81 backslash does not match slash |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
82 >>> lm(b'h/a* (glob)\n', b'h\\ab\n') |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
83 False |
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 direct matching glob can not be recognized |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
86 >>> lm(b'h/b (glob)\n', b'h/b\n') |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
87 True |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
88 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
89 missing glob can not not be recognized |
25061
625dd917f04f
test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents:
21315
diff
changeset
|
90 >>> lm(b'/h/c/df/g/\n', b'\\h/c\\df/g\\\n') |
20271
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
91 False |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
92 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
93 restore os.altsep |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
94 >>> os.altsep = _osaltsep |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
95 """ |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
96 pass |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
97 |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
98 if __name__ == '__main__': |
4453d08a616a
tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff
changeset
|
99 doctest.testmod() |