view tests/test-ui-config.py @ 35280:8e72f9152c4d

lfs: introduce a user level cache for lfs files This is the same mechanism in place for largefiles, and solves several problems working with multiple local repositories. The existing largefiles method is reused in place, because I suspect that there are other functions that can be shared. If we wait a bit to identify more before `hg cp lfutil.py ...`, the history will be easier to trace. The push between repo14 and repo15 in test-lfs.t arguably shouldn't be uploading any files with a local push. Maybe we can revisit that when `hg push` without 'lfs.url' can upload files to the push destination. Then it would be consistent for blobs in a local push to be linked to the local destination's cache. The cache property is added to run-tests.py, the same as the largefiles property, so that test generated files don't pollute the real location. Having files available locally broke a couple existing lfs-test-server tests, so the cache is cleared in a few places to force file download.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 06 Dec 2017 22:56:15 -0500
parents 85a2db47ad50
children 3740d1abde44
line wrap: on
line source

from __future__ import absolute_import, print_function
from mercurial import (
    dispatch,
    error,
    ui as uimod,
)

testui = uimod.ui.load()

# 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.
testui.setconfig('devel', 'warn-config-unknown', False, 'test')
testui.setconfig('devel', 'all-warnings', False, 'test')

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',
    'date.epoch=0 0',
    'date.birth=2005-04-19T00:00:00',
    'date.invalid=0'
    ])

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 as 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("---")
print(repr(testui.configdate('date', 'epoch')))
print(repr(testui.configdate('date', 'birth')))

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')
try:
    testui.configdate('date', 'invalid')
except error.ConfigError:
    print('dateinvalid')