예제 #1
0
def test_format_string():
    col = ArgumentCollection()
    col.add(arg('foo', value='bar'))
    ret = format_string('Test: {foo} test', col)
    assert ret == 'Test: bar test'
    ret = find_argumentkeys_in_string('Test: {foo} and {bar} so on')
    assert 'foo' in ret and 'bar' in ret
예제 #2
0
def test_argument_collection():
    arg = Argument('foo').retrieve('bar')
    col = ArgumentCollection()
    assert col.isempty()
    col.add(arg)
    assert not col.isempty()
    assert col['foo'] == arg
    col = ArgumentCollection.from_dict({'test': 'ing'})
    assert col['test'].value == 'ing'
    col1 = ArgumentCollection()
    col2 = ArgumentCollection()
    col1['foo'] = 'bar'
    col2['foo'] = 'test'
    assert col1.get('foo').value == 'bar'
    assert col2.get('asdf') is None
    col1.overwrite_merge(col2)
    assert col1['foo'].value == 'test'
    assert col.value('invalid') is None
    assert col.value('test') == 'ing'