tests/test-ui-config
author Emanuele Aina <em@nerd.ocracy.org>
Wed, 28 Mar 2007 21:34:12 +0200
changeset 4307 c8919eb0f315
parent 4069 3fef134832d8
child 4549 0c61124ad877
permissions -rwxr-xr-x
purge: abort with missing files avoiding problems with name-mangling fs In a name mangling filesystem (e.g. a case insensitive one) dirstate.walk() can yield filenames different from the ones stored in the dirstate. This already confuses the status and add commands, but with purge this may cause data loss. To prevent this purge refuses to work if there are missing files and has a 'force' option if the user knows it is safe. Even with the force option purge checks if any of the missing files is still available in the working dir: if so there may be some problem with the underlying filesystem, so it unconditionally aborts.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
     1
#!/usr/bin/env python
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     2
4069
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
     3
import ConfigParser
3344
1700a103458e move the parsing of --config options to commands.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3070
diff changeset
     4
from mercurial import ui, util, commands
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
     5
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     6
testui = ui.ui()
3344
1700a103458e move the parsing of --config options to commands.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3070
diff changeset
     7
parsed = commands.parseconfig([
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
    'values.string=string value',
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     9
    'values.bool1=true',
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    10
    'values.bool2=false',
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    11
    'lists.list1=foo',
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    12
    'lists.list2=foo bar baz',
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    13
    'lists.list3=alice, bob',
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    14
    'lists.list4=foo bar baz alice, bob',
3070
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    15
    'interpolation.value1=hallo',
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    16
    'interpolation.value2=%(value1)s world',
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    17
    'interpolation.value3=%(novalue)s',
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    18
    'interpolation.value4=%(bad)1',
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    19
    'interpolation.value5=%bad2',
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
    20
])
3344
1700a103458e move the parsing of --config options to commands.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3070
diff changeset
    21
testui.updateopts(config=parsed)
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
    22
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    23
print repr(testui.configitems('values'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    24
print repr(testui.configitems('lists'))
3070
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    25
try:
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    26
    print repr(testui.configitems('interpolation'))
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    27
except util.Abort, inst:
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    28
    print inst
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
    29
print "---"
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    30
print repr(testui.config('values', 'string'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    31
print repr(testui.config('values', 'bool1'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    32
print repr(testui.config('values', 'bool2'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    33
print repr(testui.config('values', 'unknown'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    34
print "---"
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    35
try:
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    36
    print repr(testui.configbool('values', 'string'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    37
except ValueError, why:
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    38
    print why
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    39
print repr(testui.configbool('values', 'bool1'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    40
print repr(testui.configbool('values', 'bool2'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    41
print repr(testui.configbool('values', 'bool2', True))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    42
print repr(testui.configbool('values', 'unknown'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    43
print repr(testui.configbool('values', 'unknown', True))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    44
print "---"
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    45
print repr(testui.configlist('lists', 'list1'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    46
print repr(testui.configlist('lists', 'list2'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    47
print repr(testui.configlist('lists', 'list3'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    48
print repr(testui.configlist('lists', 'list4'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    49
print repr(testui.configlist('lists', 'list4', ['foo']))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    50
print repr(testui.configlist('lists', 'unknown'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    51
print repr(testui.configlist('lists', 'unknown', ''))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    52
print repr(testui.configlist('lists', 'unknown', 'foo'))
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
print repr(testui.configlist('lists', 'unknown', ['foo']))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    54
print repr(testui.configlist('lists', 'unknown', 'foo bar'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    55
print repr(testui.configlist('lists', 'unknown', 'foo, bar'))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    56
print repr(testui.configlist('lists', 'unknown', ['foo bar']))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    57
print repr(testui.configlist('lists', 'unknown', ['foo', 'bar']))
18cf95ad3666 Allow using default values with ui.configlist, too, and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    58
print "---"
3070
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    59
print repr(testui.config('interpolation', 'value1'))
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    60
print repr(testui.config('interpolation', 'value2'))
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    61
try:
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    62
    print repr(testui.config('interpolation', 'value3'))
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    63
except util.Abort, inst:
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    64
    print inst
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    65
try:
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    66
    print repr(testui.config('interpolation', 'value4'))
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    67
except util.Abort, inst:
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    68
    print inst
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    69
try:
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    70
    print repr(testui.config('interpolation', 'value5'))
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    71
except util.Abort, inst:
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    72
    print inst
24c1db20990c Include section name and parameter name (if available) in config errors.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2502
diff changeset
    73
print "---"
4069
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    74
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    75
cp = util.configparser()
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    76
cp.add_section('foo')
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    77
cp.set('foo', 'bar', 'baz')
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    78
try:
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    79
    # should fail - keys are case-sensitive
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    80
    cp.get('foo', 'Bar')
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    81
except ConfigParser.NoOptionError, inst:
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    82
    print inst
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    83
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    84
def function():
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    85
    pass
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    86
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    87
cp.add_section('hook')
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    88
# values that aren't strings should work
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    89
cp.set('hook', 'commit', function)
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    90
f = cp.get('hook', 'commit')
3fef134832d8 allow values that aren't strings in util.configparser
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3344
diff changeset
    91
print "f %s= function" % (f == function and '=' or '!')