annotate tests/test-ui-config.py @ 51467:68ed56baabf5 stable

rust-index: don't use mutable borrow to computed filtered heads This does not need to mutate the index. This is the prime suspect for some RuntimeError raised during some pushes.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 05 Mar 2024 15:07:47 +0100
parents 6000f5b25c9b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28680
ae606bdedc3e py3: make test-ui-config use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 25660
diff changeset
1 from mercurial import (
ae606bdedc3e py3: make test-ui-config use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 25660
diff changeset
2 dispatch,
ae606bdedc3e py3: make test-ui-config use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 25660
diff changeset
3 error,
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
4 pycompat,
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 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
7 from mercurial.utils import stringutil
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
8
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28776
diff changeset
9 testui = uimod.ui.load()
34858
85a2db47ad50 configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents: 32449
diff changeset
10
85a2db47ad50 configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents: 32449
diff changeset
11 # disable the configuration registration warning
85a2db47ad50 configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents: 32449
diff changeset
12 #
85a2db47ad50 configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents: 32449
diff changeset
13 # the purpose of this test is to check the old behavior, not to validate the
85a2db47ad50 configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents: 32449
diff changeset
14 # behavior from registered item. so we silent warning related to unregisted
85a2db47ad50 configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents: 32449
diff changeset
15 # config.
37519
3740d1abde44 py3: add b'' prefixes in tests/test-ui-config.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34858
diff changeset
16 testui.setconfig(b'devel', b'warn-config-unknown', False, b'test')
3740d1abde44 py3: add b'' prefixes in tests/test-ui-config.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34858
diff changeset
17 testui.setconfig(b'devel', b'all-warnings', False, b'test')
34858
85a2db47ad50 configitems: adds a developer warning when accessing undeclared configuration
Boris Feld <boris.feld@octobus.net>
parents: 32449
diff changeset
18
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
19 parsed = dispatch._parseconfig(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
20 testui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
21 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
22 b'values.string=string value',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
23 b'values.bool1=true',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
24 b'values.bool2=false',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
25 b'values.boolinvalid=foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
26 b'values.int1=42',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
27 b'values.int2=-42',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
28 b'values.intinvalid=foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
29 b'lists.list1=foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
30 b'lists.list2=foo bar baz',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
31 b'lists.list3=alice, bob',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
32 b'lists.list4=foo bar baz alice, bob',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
33 b'lists.list5=abc d"ef"g "hij def"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
34 b'lists.list6="hello world", "how are you?"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
35 b'lists.list7=Do"Not"Separate',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
36 b'lists.list8="Do"Separate',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
37 b'lists.list9="Do\\"NotSeparate"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
38 b'lists.list10=string "with extraneous" quotation mark"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
39 b'lists.list11=x, y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
40 b'lists.list12="x", "y"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
41 b'lists.list13=""" key = "x", "y" """',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
42 b'lists.list14=,,,, ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
43 b'lists.list15=" just with starting quotation',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
44 b'lists.list16="longer quotation" with "no ending quotation',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
45 b'lists.list17=this is \\" "not a quotation mark"',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
46 b'lists.list18=\n \n\nding\ndong',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
47 b'date.epoch=0 0',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
48 b'date.birth=2005-04-19T00:00:00',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
49 b'date.invalid=0',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
50 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
51 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
52
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
53
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
54 def pprint(obj):
37942
32bc3815efae stringutil: flip the default of pprint() to bprefix=False
Yuya Nishihara <yuya@tcha.org>
parents: 37937
diff changeset
55 return stringutil.pprint(obj).decode('ascii')
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
56
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
57
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
58 print(pprint(testui.configitems(b'values')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
59 print(pprint(testui.configitems(b'lists')))
28681
eda8b28e3b1b py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28680
diff changeset
60 print("---")
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
61 print(pprint(testui.config(b'values', b'string')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
62 print(pprint(testui.config(b'values', b'bool1')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
63 print(pprint(testui.config(b'values', b'bool2')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
64 print(pprint(testui.config(b'values', b'unknown')))
28681
eda8b28e3b1b py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28680
diff changeset
65 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
66 try:
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
67 print(pprint(testui.configbool(b'values', b'string')))
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 14171
diff changeset
68 except error.ConfigError as inst:
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
69 print(pprint(pycompat.bytestr(inst)))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
70 print(pprint(testui.configbool(b'values', b'bool1')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
71 print(pprint(testui.configbool(b'values', b'bool2')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
72 print(pprint(testui.configbool(b'values', b'bool2', True)))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
73 print(pprint(testui.configbool(b'values', b'unknown')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
74 print(pprint(testui.configbool(b'values', b'unknown', True)))
28681
eda8b28e3b1b py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28680
diff changeset
75 print("---")
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
76 print(pprint(testui.configint(b'values', b'int1')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
77 print(pprint(testui.configint(b'values', b'int2')))
28681
eda8b28e3b1b py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28680
diff changeset
78 print("---")
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
79 print(pprint(testui.configlist(b'lists', b'list1')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
80 print(pprint(testui.configlist(b'lists', b'list2')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
81 print(pprint(testui.configlist(b'lists', b'list3')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
82 print(pprint(testui.configlist(b'lists', b'list4')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
83 print(pprint(testui.configlist(b'lists', b'list4', [b'foo'])))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
84 print(pprint(testui.configlist(b'lists', b'list5')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
85 print(pprint(testui.configlist(b'lists', b'list6')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
86 print(pprint(testui.configlist(b'lists', b'list7')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
87 print(pprint(testui.configlist(b'lists', b'list8')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
88 print(pprint(testui.configlist(b'lists', b'list9')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
89 print(pprint(testui.configlist(b'lists', b'list10')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
90 print(pprint(testui.configlist(b'lists', b'list11')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
91 print(pprint(testui.configlist(b'lists', b'list12')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
92 print(pprint(testui.configlist(b'lists', b'list13')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
93 print(pprint(testui.configlist(b'lists', b'list14')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
94 print(pprint(testui.configlist(b'lists', b'list15')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
95 print(pprint(testui.configlist(b'lists', b'list16')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
96 print(pprint(testui.configlist(b'lists', b'list17')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
97 print(pprint(testui.configlist(b'lists', b'list18')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
98 print(pprint(testui.configlist(b'lists', b'unknown')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
99 print(pprint(testui.configlist(b'lists', b'unknown', b'')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
100 print(pprint(testui.configlist(b'lists', b'unknown', b'foo')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
101 print(pprint(testui.configlist(b'lists', b'unknown', [b'foo'])))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
102 print(pprint(testui.configlist(b'lists', b'unknown', b'foo bar')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
103 print(pprint(testui.configlist(b'lists', b'unknown', b'foo, bar')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
104 print(pprint(testui.configlist(b'lists', b'unknown', [b'foo bar'])))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
105 print(pprint(testui.configlist(b'lists', b'unknown', [b'foo', b'bar'])))
32449
0ed730f3301c ui: fix ui.configdate for invalid dates
Boris Feld <boris.feld@octobus.net>
parents: 30559
diff changeset
106 print("---")
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
107 print(pprint(testui.configdate(b'date', b'epoch')))
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
108 print(pprint(testui.configdate(b'date', b'birth')))
4069
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3346
diff changeset
109
37937
a2cfea193040 tests: port test-ui-config to Python 3
Augie Fackler <augie@google.com>
parents: 37519
diff changeset
110 print(pprint(testui.config(b'values', b'String')))
4069
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3346
diff changeset
111
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
112
4069
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3346
diff changeset
113 def function():
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3346
diff changeset
114 pass
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3346
diff changeset
115
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37942
diff changeset
116
4069
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3346
diff changeset
117 # values that aren't strings should work
37519
3740d1abde44 py3: add b'' prefixes in tests/test-ui-config.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34858
diff changeset
118 testui.setconfig(b'hook', b'commit', function)
3740d1abde44 py3: add b'' prefixes in tests/test-ui-config.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34858
diff changeset
119 print(function == testui.config(b'hook', b'commit'))
14171
fa2b596db182 ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents: 12865
diff changeset
120
fa2b596db182 ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents: 12865
diff changeset
121 # invalid values
fa2b596db182 ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents: 12865
diff changeset
122 try:
37519
3740d1abde44 py3: add b'' prefixes in tests/test-ui-config.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34858
diff changeset
123 testui.configbool(b'values', b'boolinvalid')
14171
fa2b596db182 ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents: 12865
diff changeset
124 except error.ConfigError:
28681
eda8b28e3b1b py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28680
diff changeset
125 print('boolinvalid')
14171
fa2b596db182 ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents: 12865
diff changeset
126 try:
37519
3740d1abde44 py3: add b'' prefixes in tests/test-ui-config.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34858
diff changeset
127 testui.configint(b'values', b'intinvalid')
14171
fa2b596db182 ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents: 12865
diff changeset
128 except error.ConfigError:
28681
eda8b28e3b1b py3: make test-ui-config use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28680
diff changeset
129 print('intinvalid')
32449
0ed730f3301c ui: fix ui.configdate for invalid dates
Boris Feld <boris.feld@octobus.net>
parents: 30559
diff changeset
130 try:
37519
3740d1abde44 py3: add b'' prefixes in tests/test-ui-config.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34858
diff changeset
131 testui.configdate(b'date', b'invalid')
32449
0ed730f3301c ui: fix ui.configdate for invalid dates
Boris Feld <boris.feld@octobus.net>
parents: 30559
diff changeset
132 except error.ConfigError:
0ed730f3301c ui: fix ui.configdate for invalid dates
Boris Feld <boris.feld@octobus.net>
parents: 30559
diff changeset
133 print('dateinvalid')