test-ui-config.py
134 lines
| 4.8 KiB
| text/x-python
|
PythonLexer
/ tests / test-ui-config.py
|
r28681 | from __future__ import absolute_import, print_function | ||
|
r28680 | from mercurial import ( | ||
dispatch, | ||||
error, | ||||
|
r37956 | pycompat, | ||
|
r28776 | ui as uimod, | ||
|
r28680 | ) | ||
|
r43346 | from mercurial.utils import stringutil | ||
|
r8449 | |||
|
r30559 | testui = uimod.ui.load() | ||
|
r34859 | |||
# disable the configuration registration warning | ||||
# | ||||
# the purpose of this test is to check the old behavior, not to validate the | ||||
# behavior from registered item. so we silent warning related to unregisted | ||||
# config. | ||||
|
r37537 | testui.setconfig(b'devel', b'warn-config-unknown', False, b'test') | ||
testui.setconfig(b'devel', b'all-warnings', False, b'test') | ||||
|
r34859 | |||
|
r43346 | parsed = dispatch._parseconfig( | ||
testui, | ||||
[ | ||||
b'values.string=string value', | ||||
b'values.bool1=true', | ||||
b'values.bool2=false', | ||||
b'values.boolinvalid=foo', | ||||
b'values.int1=42', | ||||
b'values.int2=-42', | ||||
b'values.intinvalid=foo', | ||||
b'lists.list1=foo', | ||||
b'lists.list2=foo bar baz', | ||||
b'lists.list3=alice, bob', | ||||
b'lists.list4=foo bar baz alice, bob', | ||||
b'lists.list5=abc d"ef"g "hij def"', | ||||
b'lists.list6="hello world", "how are you?"', | ||||
b'lists.list7=Do"Not"Separate', | ||||
b'lists.list8="Do"Separate', | ||||
b'lists.list9="Do\\"NotSeparate"', | ||||
b'lists.list10=string "with extraneous" quotation mark"', | ||||
b'lists.list11=x, y', | ||||
b'lists.list12="x", "y"', | ||||
b'lists.list13=""" key = "x", "y" """', | ||||
b'lists.list14=,,,, ', | ||||
b'lists.list15=" just with starting quotation', | ||||
b'lists.list16="longer quotation" with "no ending quotation', | ||||
b'lists.list17=this is \\" "not a quotation mark"', | ||||
b'lists.list18=\n \n\nding\ndong', | ||||
b'date.epoch=0 0', | ||||
b'date.birth=2005-04-19T00:00:00', | ||||
b'date.invalid=0', | ||||
], | ||||
) | ||||
|
r8449 | |||
|
r37956 | def pprint(obj): | ||
|
r37961 | return stringutil.pprint(obj).decode('ascii') | ||
|
r37956 | |||
|
r43346 | |||
|
r37956 | print(pprint(testui.configitems(b'values'))) | ||
print(pprint(testui.configitems(b'lists'))) | ||||
|
r28681 | print("---") | ||
|
r37956 | print(pprint(testui.config(b'values', b'string'))) | ||
print(pprint(testui.config(b'values', b'bool1'))) | ||||
print(pprint(testui.config(b'values', b'bool2'))) | ||||
print(pprint(testui.config(b'values', b'unknown'))) | ||||
|
r28681 | print("---") | ||
|
r8449 | try: | ||
|
r37956 | print(pprint(testui.configbool(b'values', b'string'))) | ||
|
r25660 | except error.ConfigError as inst: | ||
|
r37956 | print(pprint(pycompat.bytestr(inst))) | ||
print(pprint(testui.configbool(b'values', b'bool1'))) | ||||
print(pprint(testui.configbool(b'values', b'bool2'))) | ||||
print(pprint(testui.configbool(b'values', b'bool2', True))) | ||||
print(pprint(testui.configbool(b'values', b'unknown'))) | ||||
print(pprint(testui.configbool(b'values', b'unknown', True))) | ||||
|
r28681 | print("---") | ||
|
r37956 | print(pprint(testui.configint(b'values', b'int1'))) | ||
print(pprint(testui.configint(b'values', b'int2'))) | ||||
|
r28681 | print("---") | ||
|
r37956 | print(pprint(testui.configlist(b'lists', b'list1'))) | ||
print(pprint(testui.configlist(b'lists', b'list2'))) | ||||
print(pprint(testui.configlist(b'lists', b'list3'))) | ||||
print(pprint(testui.configlist(b'lists', b'list4'))) | ||||
print(pprint(testui.configlist(b'lists', b'list4', [b'foo']))) | ||||
print(pprint(testui.configlist(b'lists', b'list5'))) | ||||
print(pprint(testui.configlist(b'lists', b'list6'))) | ||||
print(pprint(testui.configlist(b'lists', b'list7'))) | ||||
print(pprint(testui.configlist(b'lists', b'list8'))) | ||||
print(pprint(testui.configlist(b'lists', b'list9'))) | ||||
print(pprint(testui.configlist(b'lists', b'list10'))) | ||||
print(pprint(testui.configlist(b'lists', b'list11'))) | ||||
print(pprint(testui.configlist(b'lists', b'list12'))) | ||||
print(pprint(testui.configlist(b'lists', b'list13'))) | ||||
print(pprint(testui.configlist(b'lists', b'list14'))) | ||||
print(pprint(testui.configlist(b'lists', b'list15'))) | ||||
print(pprint(testui.configlist(b'lists', b'list16'))) | ||||
print(pprint(testui.configlist(b'lists', b'list17'))) | ||||
print(pprint(testui.configlist(b'lists', b'list18'))) | ||||
print(pprint(testui.configlist(b'lists', b'unknown'))) | ||||
print(pprint(testui.configlist(b'lists', b'unknown', b''))) | ||||
print(pprint(testui.configlist(b'lists', b'unknown', b'foo'))) | ||||
print(pprint(testui.configlist(b'lists', b'unknown', [b'foo']))) | ||||
print(pprint(testui.configlist(b'lists', b'unknown', b'foo bar'))) | ||||
print(pprint(testui.configlist(b'lists', b'unknown', b'foo, bar'))) | ||||
print(pprint(testui.configlist(b'lists', b'unknown', [b'foo bar']))) | ||||
print(pprint(testui.configlist(b'lists', b'unknown', [b'foo', b'bar']))) | ||||
|
r32449 | print("---") | ||
|
r37956 | print(pprint(testui.configdate(b'date', b'epoch'))) | ||
print(pprint(testui.configdate(b'date', b'birth'))) | ||||
|
r8449 | |||
|
r37956 | print(pprint(testui.config(b'values', b'String'))) | ||
|
r8449 | |||
|
r43346 | |||
|
r8449 | def function(): | ||
pass | ||||
|
r43346 | |||
|
r8449 | # values that aren't strings should work | ||
|
r37537 | testui.setconfig(b'hook', b'commit', function) | ||
print(function == testui.config(b'hook', b'commit')) | ||||
|
r14171 | |||
# invalid values | ||||
try: | ||||
|
r37537 | testui.configbool(b'values', b'boolinvalid') | ||
|
r14171 | except error.ConfigError: | ||
|
r28681 | print('boolinvalid') | ||
|
r14171 | try: | ||
|
r37537 | testui.configint(b'values', b'intinvalid') | ||
|
r14171 | except error.ConfigError: | ||
|
r28681 | print('intinvalid') | ||
|
r32449 | try: | ||
|
r37537 | testui.configdate(b'date', b'invalid') | ||
|
r32449 | except error.ConfigError: | ||
print('dateinvalid') | ||||