| 1 |
from mercurial import ( |
| 2 |
error, |
| 3 |
pycompat, |
| 4 |
ui as uimod, |
| 5 |
) |
| 6 |
from mercurial.main_script import options as args_util |
| 7 |
from mercurial.utils import stringutil |
| 8 |
|
| 9 |
testui = uimod.ui.load() |
| 10 |
|
| 11 |
# disable the configuration registration warning |
| 12 |
# |
| 13 |
# the purpose of this test is to check the old behavior, not to validate the |
| 14 |
# behavior from registered item. so we silent warning related to unregisted |
| 15 |
# config. |
| 16 |
testui.setconfig(b'devel', b'warn-config-unknown', False, b'test') |
| 17 |
testui.setconfig(b'devel', b'all-warnings', False, b'test') |
| 18 |
|
| 19 |
parsed = args_util.parse_config_opts( |
| 20 |
testui, |
| 21 |
[ |
| 22 |
b'values.string=string value', |
| 23 |
b'values.bool1=true', |
| 24 |
b'values.bool2=false', |
| 25 |
b'values.boolinvalid=foo', |
| 26 |
b'values.int1=42', |
| 27 |
b'values.int2=-42', |
| 28 |
b'values.intinvalid=foo', |
| 29 |
b'lists.list1=foo', |
| 30 |
b'lists.list2=foo bar baz', |
| 31 |
b'lists.list3=alice, bob', |
| 32 |
b'lists.list4=foo bar baz alice, bob', |
| 33 |
b'lists.list5=abc d"ef"g "hij def"', |
| 34 |
b'lists.list6="hello world", "how are you?"', |
| 35 |
b'lists.list7=Do"Not"Separate', |
| 36 |
b'lists.list8="Do"Separate', |
| 37 |
b'lists.list9="Do\\"NotSeparate"', |
| 38 |
b'lists.list10=string "with extraneous" quotation mark"', |
| 39 |
b'lists.list11=x, y', |
| 40 |
b'lists.list12="x", "y"', |
| 41 |
b'lists.list13=""" key = "x", "y" """', |
| 42 |
b'lists.list14=,,,, ', |
| 43 |
b'lists.list15=" just with starting quotation', |
| 44 |
b'lists.list16="longer quotation" with "no ending quotation', |
| 45 |
b'lists.list17=this is \\" "not a quotation mark"', |
| 46 |
b'lists.list18=\n \n\nding\ndong', |
| 47 |
b'date.epoch=0 0', |
| 48 |
b'date.birth=2005-04-19T00:00:00', |
| 49 |
b'date.invalid=0', |
| 50 |
], |
| 51 |
) |
| 52 |
|
| 53 |
|
| 54 |
def pprint(obj): |
| 55 |
return stringutil.pprint(obj).decode('ascii') |
| 56 |
|
| 57 |
|
| 58 |
print(pprint(testui.configitems(b'values'))) |
| 59 |
print(pprint(testui.configitems(b'lists'))) |
| 60 |
print("---") |
| 61 |
print(pprint(testui.config(b'values', b'string'))) |
| 62 |
print(pprint(testui.config(b'values', b'bool1'))) |
| 63 |
print(pprint(testui.config(b'values', b'bool2'))) |
| 64 |
print(pprint(testui.config(b'values', b'unknown'))) |
| 65 |
print("---") |
| 66 |
try: |
| 67 |
print(pprint(testui.configbool(b'values', b'string'))) |
| 68 |
except error.ConfigError as inst: |
| 69 |
print(pprint(pycompat.bytestr(inst))) |
| 70 |
print(pprint(testui.configbool(b'values', b'bool1'))) |
| 71 |
print(pprint(testui.configbool(b'values', b'bool2'))) |
| 72 |
print(pprint(testui.configbool(b'values', b'bool2', True))) |
| 73 |
print(pprint(testui.configbool(b'values', b'unknown'))) |
| 74 |
print(pprint(testui.configbool(b'values', b'unknown', True))) |
| 75 |
print("---") |
| 76 |
print(pprint(testui.configint(b'values', b'int1'))) |
| 77 |
print(pprint(testui.configint(b'values', b'int2'))) |
| 78 |
print("---") |
| 79 |
print(pprint(testui.configlist(b'lists', b'list1'))) |
| 80 |
print(pprint(testui.configlist(b'lists', b'list2'))) |
| 81 |
print(pprint(testui.configlist(b'lists', b'list3'))) |
| 82 |
print(pprint(testui.configlist(b'lists', b'list4'))) |
| 83 |
print(pprint(testui.configlist(b'lists', b'list4', [b'foo']))) |
| 84 |
print(pprint(testui.configlist(b'lists', b'list5'))) |
| 85 |
print(pprint(testui.configlist(b'lists', b'list6'))) |
| 86 |
print(pprint(testui.configlist(b'lists', b'list7'))) |
| 87 |
print(pprint(testui.configlist(b'lists', b'list8'))) |
| 88 |
print(pprint(testui.configlist(b'lists', b'list9'))) |
| 89 |
print(pprint(testui.configlist(b'lists', b'list10'))) |
| 90 |
print(pprint(testui.configlist(b'lists', b'list11'))) |
| 91 |
print(pprint(testui.configlist(b'lists', b'list12'))) |
| 92 |
print(pprint(testui.configlist(b'lists', b'list13'))) |
| 93 |
print(pprint(testui.configlist(b'lists', b'list14'))) |
| 94 |
print(pprint(testui.configlist(b'lists', b'list15'))) |
| 95 |
print(pprint(testui.configlist(b'lists', b'list16'))) |
| 96 |
print(pprint(testui.configlist(b'lists', b'list17'))) |
| 97 |
print(pprint(testui.configlist(b'lists', b'list18'))) |
| 98 |
print(pprint(testui.configlist(b'lists', b'unknown'))) |
| 99 |
print(pprint(testui.configlist(b'lists', b'unknown', b''))) |
| 100 |
print(pprint(testui.configlist(b'lists', b'unknown', b'foo'))) |
| 101 |
print(pprint(testui.configlist(b'lists', b'unknown', [b'foo']))) |
| 102 |
print(pprint(testui.configlist(b'lists', b'unknown', b'foo bar'))) |
| 103 |
print(pprint(testui.configlist(b'lists', b'unknown', b'foo, bar'))) |
| 104 |
print(pprint(testui.configlist(b'lists', b'unknown', [b'foo bar']))) |
| 105 |
print(pprint(testui.configlist(b'lists', b'unknown', [b'foo', b'bar']))) |
| 106 |
print("---") |
| 107 |
print(pprint(testui.configdate(b'date', b'epoch'))) |
| 108 |
print(pprint(testui.configdate(b'date', b'birth'))) |
| 109 |
|
| 110 |
print(pprint(testui.config(b'values', b'String'))) |
| 111 |
|
| 112 |
|
| 113 |
def function(): |
| 114 |
pass |
| 115 |
|
| 116 |
|
| 117 |
# values that aren't strings should work |
| 118 |
testui.setconfig(b'hook', b'commit', function) |
| 119 |
print(function == testui.config(b'hook', b'commit')) |
| 120 |
|
| 121 |
# invalid values |
| 122 |
try: |
| 123 |
testui.configbool(b'values', b'boolinvalid') |
| 124 |
except error.ConfigError: |
| 125 |
print('boolinvalid') |
| 126 |
try: |
| 127 |
testui.configint(b'values', b'intinvalid') |
| 128 |
except error.ConfigError: |
| 129 |
print('intinvalid') |
| 130 |
try: |
| 131 |
testui.configdate(b'date', b'invalid') |
| 132 |
except error.ConfigError: |
| 133 |
print('dateinvalid') |