view tests/test-ui-config.py @ 23167:a3c2d9211294 stable

templater: don't overwrite the keyword mapping in runsymbol() (issue4362) This keyword remapping was introduced in e06e9fd2d99f as part of converting generator based iterators into list based iterators, mentioning "undesired behavior in template" when a generator is exhausted, but doesn't say what and introduces no tests. The problem with the remapping was that it corrupted the output for keywords like 'extras', 'file_copies' and 'file_copies_switch' in templates such as: $ hg log -r 142b5d5ec9cc --template "{file_copies % ' File: {file_copy}\n'}" File: mercurial/changelog.py (mercurial/hg.py) File: mercurial/changelog.py (mercurial/hg.py) File: mercurial/changelog.py (mercurial/hg.py) File: mercurial/changelog.py (mercurial/hg.py) File: mercurial/changelog.py (mercurial/hg.py) File: mercurial/changelog.py (mercurial/hg.py) File: mercurial/changelog.py (mercurial/hg.py) File: mercurial/changelog.py (mercurial/hg.py) What was happening was that in the first call to runtemplate() inside runmap(), 'lm' mapped the keyword (e.g. file_copies) to the appropriate showxxx() method. On each subsequent call to runtemplate() in that loop however, the keyword was mapped to a list of the first item's pieces, e.g.: 'file_copy': ['mercurial/changelog.py', ' (', 'mercurial/hg.py', ')'] Therefore, the dict for the second and any subsequent items were not processed through the corresponding showxxx() method, and the first item's data was reused. The 'extras' keyword regressed in de7e6c489412, and 'file_copies' regressed in 0b241d7a8c62 for other reasons. The common thread of things fixed by this seems to be when a list of dicts are passed to the templatekw._hybrid class.
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 03 Nov 2014 12:08:03 -0500
parents fa2b596db182
children 328739ea70c3
line wrap: on
line source

from mercurial import ui, dispatch, error

testui = ui.ui()
parsed = dispatch._parseconfig(testui, [
    'values.string=string value',
    'values.bool1=true',
    'values.bool2=false',
    'values.boolinvalid=foo',
    'values.int1=42',
    'values.int2=-42',
    'values.intinvalid=foo',
    'lists.list1=foo',
    'lists.list2=foo bar baz',
    'lists.list3=alice, bob',
    'lists.list4=foo bar baz alice, bob',
    'lists.list5=abc d"ef"g "hij def"',
    'lists.list6="hello world", "how are you?"',
    'lists.list7=Do"Not"Separate',
    'lists.list8="Do"Separate',
    'lists.list9="Do\\"NotSeparate"',
    'lists.list10=string "with extraneous" quotation mark"',
    'lists.list11=x, y',
    'lists.list12="x", "y"',
    'lists.list13=""" key = "x", "y" """',
    'lists.list14=,,,,     ',
    'lists.list15=" just with starting quotation',
    'lists.list16="longer quotation" with "no ending quotation',
    'lists.list17=this is \\" "not a quotation mark"',
    'lists.list18=\n \n\nding\ndong',
    ])

print repr(testui.configitems('values'))
print repr(testui.configitems('lists'))
print "---"
print repr(testui.config('values', 'string'))
print repr(testui.config('values', 'bool1'))
print repr(testui.config('values', 'bool2'))
print repr(testui.config('values', 'unknown'))
print "---"
try:
    print repr(testui.configbool('values', 'string'))
except error.ConfigError, inst:
    print inst
print repr(testui.configbool('values', 'bool1'))
print repr(testui.configbool('values', 'bool2'))
print repr(testui.configbool('values', 'bool2', True))
print repr(testui.configbool('values', 'unknown'))
print repr(testui.configbool('values', 'unknown', True))
print "---"
print repr(testui.configint('values', 'int1'))
print repr(testui.configint('values', 'int2'))
print "---"
print repr(testui.configlist('lists', 'list1'))
print repr(testui.configlist('lists', 'list2'))
print repr(testui.configlist('lists', 'list3'))
print repr(testui.configlist('lists', 'list4'))
print repr(testui.configlist('lists', 'list4', ['foo']))
print repr(testui.configlist('lists', 'list5'))
print repr(testui.configlist('lists', 'list6'))
print repr(testui.configlist('lists', 'list7'))
print repr(testui.configlist('lists', 'list8'))
print repr(testui.configlist('lists', 'list9'))
print repr(testui.configlist('lists', 'list10'))
print repr(testui.configlist('lists', 'list11'))
print repr(testui.configlist('lists', 'list12'))
print repr(testui.configlist('lists', 'list13'))
print repr(testui.configlist('lists', 'list14'))
print repr(testui.configlist('lists', 'list15'))
print repr(testui.configlist('lists', 'list16'))
print repr(testui.configlist('lists', 'list17'))
print repr(testui.configlist('lists', 'list18'))
print repr(testui.configlist('lists', 'unknown'))
print repr(testui.configlist('lists', 'unknown', ''))
print repr(testui.configlist('lists', 'unknown', 'foo'))
print repr(testui.configlist('lists', 'unknown', ['foo']))
print repr(testui.configlist('lists', 'unknown', 'foo bar'))
print repr(testui.configlist('lists', 'unknown', 'foo, bar'))
print repr(testui.configlist('lists', 'unknown', ['foo bar']))
print repr(testui.configlist('lists', 'unknown', ['foo', 'bar']))

print repr(testui.config('values', 'String'))

def function():
    pass

# values that aren't strings should work
testui.setconfig('hook', 'commit', function)
print function == testui.config('hook', 'commit')

# invalid values
try:
    testui.configbool('values', 'boolinvalid')
except error.ConfigError:
    print 'boolinvalid'
try:
    testui.configint('values', 'intinvalid')
except error.ConfigError:
    print 'intinvalid'