Mercurial > hg
annotate tests/test-ui-config.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 | 5508a277bab2 |
children | d83ca854fa21 |
rev | line source |
---|---|
28681
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
1 from __future__ import absolute_import, print_function |
28680
ae606bdedc3e
py3: make test-ui-config use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25660
diff
changeset
|
2 from mercurial import ( |
ae606bdedc3e
py3: make test-ui-config use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25660
diff
changeset
|
3 dispatch, |
ae606bdedc3e
py3: make test-ui-config use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25660
diff
changeset
|
4 error, |
28776
5508a277bab2
tests: alias ui as uimod in test-ui-config
Yuya Nishihara <yuya@tcha.org>
parents:
28681
diff
changeset
|
5 ui as uimod, |
28680
ae606bdedc3e
py3: make test-ui-config use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
25660
diff
changeset
|
6 ) |
2502
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
7 |
28776
5508a277bab2
tests: alias ui as uimod in test-ui-config
Yuya Nishihara <yuya@tcha.org>
parents:
28681
diff
changeset
|
8 testui = uimod.ui() |
8137 | 9 parsed = dispatch._parseconfig(testui, [ |
2502
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
10 'values.string=string value', |
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
11 'values.bool1=true', |
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
12 'values.bool2=false', |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
13 'values.boolinvalid=foo', |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
14 'values.int1=42', |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
15 'values.int2=-42', |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
16 'values.intinvalid=foo', |
2502
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
17 'lists.list1=foo', |
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
18 'lists.list2=foo bar baz', |
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
19 'lists.list3=alice, bob', |
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
20 'lists.list4=foo bar baz alice, bob', |
10982
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
21 'lists.list5=abc d"ef"g "hij def"', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
22 'lists.list6="hello world", "how are you?"', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
23 'lists.list7=Do"Not"Separate', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
24 'lists.list8="Do"Separate', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
25 'lists.list9="Do\\"NotSeparate"', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
26 'lists.list10=string "with extraneous" quotation mark"', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
27 'lists.list11=x, y', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
28 'lists.list12="x", "y"', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
29 'lists.list13=""" key = "x", "y" """', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
30 'lists.list14=,,,, ', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
31 'lists.list15=" just with starting quotation', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
32 'lists.list16="longer quotation" with "no ending quotation', |
0a548640e012
ui: support quotes in configlist (issue2147)
Henrik Stuart <hg@hstuart.dk>
parents:
8656
diff
changeset
|
33 'lists.list17=this is \\" "not a quotation mark"', |
11309
ef7636efeb01
ui: handle leading newlines/spaces/commas in configlist
Thomas Arendsen Hein <thomas@intevation.de>
parents:
10982
diff
changeset
|
34 'lists.list18=\n \n\nding\ndong', |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
35 ]) |
2502
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
36 |
28681
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
37 print(repr(testui.configitems('values'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
38 print(repr(testui.configitems('lists'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
39 print("---") |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
40 print(repr(testui.config('values', 'string'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
41 print(repr(testui.config('values', 'bool1'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
42 print(repr(testui.config('values', 'bool2'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
43 print(repr(testui.config('values', 'unknown'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
44 print("---") |
2502
18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
45 try: |
28681
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
46 print(repr(testui.configbool('values', 'string'))) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
14171
diff
changeset
|
47 except error.ConfigError as inst: |
28681
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
48 print(inst) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
49 print(repr(testui.configbool('values', 'bool1'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
50 print(repr(testui.configbool('values', 'bool2'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
51 print(repr(testui.configbool('values', 'bool2', True))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
52 print(repr(testui.configbool('values', 'unknown'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
53 print(repr(testui.configbool('values', 'unknown', True))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
54 print("---") |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
55 print(repr(testui.configint('values', 'int1'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
56 print(repr(testui.configint('values', 'int2'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
57 print("---") |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
58 print(repr(testui.configlist('lists', 'list1'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
59 print(repr(testui.configlist('lists', 'list2'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
60 print(repr(testui.configlist('lists', 'list3'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
61 print(repr(testui.configlist('lists', 'list4'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
62 print(repr(testui.configlist('lists', 'list4', ['foo']))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
63 print(repr(testui.configlist('lists', 'list5'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
64 print(repr(testui.configlist('lists', 'list6'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
65 print(repr(testui.configlist('lists', 'list7'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
66 print(repr(testui.configlist('lists', 'list8'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
67 print(repr(testui.configlist('lists', 'list9'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
68 print(repr(testui.configlist('lists', 'list10'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
69 print(repr(testui.configlist('lists', 'list11'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
70 print(repr(testui.configlist('lists', 'list12'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
71 print(repr(testui.configlist('lists', 'list13'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
72 print(repr(testui.configlist('lists', 'list14'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
73 print(repr(testui.configlist('lists', 'list15'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
74 print(repr(testui.configlist('lists', 'list16'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
75 print(repr(testui.configlist('lists', 'list17'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
76 print(repr(testui.configlist('lists', 'list18'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
77 print(repr(testui.configlist('lists', 'unknown'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
78 print(repr(testui.configlist('lists', 'unknown', ''))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
79 print(repr(testui.configlist('lists', 'unknown', 'foo'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
80 print(repr(testui.configlist('lists', 'unknown', ['foo']))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
81 print(repr(testui.configlist('lists', 'unknown', 'foo bar'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
82 print(repr(testui.configlist('lists', 'unknown', 'foo, bar'))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
83 print(repr(testui.configlist('lists', 'unknown', ['foo bar']))) |
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
84 print(repr(testui.configlist('lists', 'unknown', ['foo', 'bar']))) |
4069
3fef134832d8
allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
85 |
28681
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
86 print(repr(testui.config('values', 'String'))) |
4069
3fef134832d8
allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
87 |
3fef134832d8
allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
88 def function(): |
3fef134832d8
allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
89 pass |
3fef134832d8
allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
90 |
3fef134832d8
allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3346
diff
changeset
|
91 # values that aren't strings should work |
8144
fca54469480e
ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents:
8137
diff
changeset
|
92 testui.setconfig('hook', 'commit', function) |
28681
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
93 print(function == testui.config('hook', 'commit')) |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
94 |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
95 # invalid values |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
96 try: |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
97 testui.configbool('values', 'boolinvalid') |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
98 except error.ConfigError: |
28681
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
99 print('boolinvalid') |
14171
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
100 try: |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
101 testui.configint('values', 'intinvalid') |
fa2b596db182
ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents:
12865
diff
changeset
|
102 except error.ConfigError: |
28681
eda8b28e3b1b
py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28680
diff
changeset
|
103 print('intinvalid') |