view tests/test-ui-config @ 4359:2e3c54fb79a3

actually port simplemerge to hg - use bdiff instead of patiencediff; this is a larger change, since bdiff works on 2 multi-line strings, while patiencediff works on 2 lists; - rename the main class from Merge3 to Merge3Text and add a Merge3 class that derives from Merge3Text. This new Merge3 class has the same interface from the original class, so that the tests still work; - Merge3 uses util.binary to detect binary data and raises util.Abort instead of a specific exception; - don't use the @decorator syntax, to keep python2.3 compatibility; - the test uses unittest, which likes to print how long it took to run. This obviously doesn't play too well with hg's test suite, so we override time.time to fool unittest; - one test has a different (but still valid) output because of the different diff algorithm used; - the TestCase class used by bzr has some extras to help debugging. test-merge3.py used 2 of them: - log method to log some data - assertEqualDiff method to ease viewing diffs of diffs We add a dummy log method and use regular assertEquals instead of assertEqualDiff. - make simplemerge executable and add "#!/usr/bin/env python" header
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 16 Apr 2007 20:17:39 -0300
parents 3fef134832d8
children 0c61124ad877
line wrap: on
line source

#!/usr/bin/env python

import ConfigParser
from mercurial import ui, util, commands

testui = ui.ui()
parsed = commands.parseconfig([
    'values.string=string value',
    'values.bool1=true',
    'values.bool2=false',
    'lists.list1=foo',
    'lists.list2=foo bar baz',
    'lists.list3=alice, bob',
    'lists.list4=foo bar baz alice, bob',
    'interpolation.value1=hallo',
    'interpolation.value2=%(value1)s world',
    'interpolation.value3=%(novalue)s',
    'interpolation.value4=%(bad)1',
    'interpolation.value5=%bad2',
])
testui.updateopts(config=parsed)

print repr(testui.configitems('values'))
print repr(testui.configitems('lists'))
try:
    print repr(testui.configitems('interpolation'))
except util.Abort, inst:
    print inst
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 ValueError, why:
    print why
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.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', '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 "---"
print repr(testui.config('interpolation', 'value1'))
print repr(testui.config('interpolation', 'value2'))
try:
    print repr(testui.config('interpolation', 'value3'))
except util.Abort, inst:
    print inst
try:
    print repr(testui.config('interpolation', 'value4'))
except util.Abort, inst:
    print inst
try:
    print repr(testui.config('interpolation', 'value5'))
except util.Abort, inst:
    print inst
print "---"

cp = util.configparser()
cp.add_section('foo')
cp.set('foo', 'bar', 'baz')
try:
    # should fail - keys are case-sensitive
    cp.get('foo', 'Bar')
except ConfigParser.NoOptionError, inst:
    print inst

def function():
    pass

cp.add_section('hook')
# values that aren't strings should work
cp.set('hook', 'commit', function)
f = cp.get('hook', 'commit')
print "f %s= function" % (f == function and '=' or '!')