Exemplo n.º 1
0
def test_recursive_update5(basic_config_dict):
    current = basic_config_dict
    current['a'] = {'c': None}
    new = {'a': {'c': {'d': {42: 'test'}}}}
    # run
    OptionsHandler._recursive_update(current, new)
    expected = basic_config_dict
    expected['a']['c']['d'] = {42: 'test'}
    assert current == expected
Exemplo n.º 2
0
def test_add_sub_command1(reference_default_config):
    cmd_opts = {'a': ValidOption(type=str, default='uiae'),
                'b': ValidOption(type=int, default=42),
                'c': {'d': ValidOption(type=int, default=1337)}}
    oh = OptionsHandler()
    oh.add_sub_command('test_cmd', cmd_opts, cmd_aliases=['tc'])
    result = oh.get_defaults()
    assert result == {'test_cmd': {'a': 'uiae', 'b': 42, 'c': {'d': 1337}},
                      **reference_default_config}
Exemplo n.º 3
0
def test_recursive_update4(basic_config_dict):
    current = basic_config_dict
    new = {'a': {'c': {'d': {42: 'test'}}}}
    # run
    OptionsHandler._recursive_update(current, new)
    # check
    expected = basic_config_dict
    expected['a']['c']['d'] = {42: 'test'}
    assert repr(current) == repr(expected)
Exemplo n.º 4
0
def test_recursive_update3(basic_config_dict):
    current = basic_config_dict
    new = {'a': {'c': None}}
    # run
    OptionsHandler._recursive_update(current, new)
    # check
    expected = basic_config_dict
    expected['a']['c'] = None
    assert repr(current) == repr(expected)
Exemplo n.º 5
0
def test_recursive_update2(basic_config_dict):
    current = basic_config_dict
    new = {'a': {'c': {'c': {'f': 'blub'}}}}
    # run
    OptionsHandler._recursive_update(current, new)
    # check
    expected = basic_config_dict
    expected['a']['c']['c']['f'] = 'blub'
    assert repr(current) == repr(expected)
Exemplo n.º 6
0
def test_recursive_update0(basic_config_dict):
    current = basic_config_dict
    new = {'a': 5}
    # run
    OptionsHandler._recursive_update(current, new)
    # check
    expected = basic_config_dict
    expected['a'] = 5
    assert repr(current) == repr(expected)
Exemplo n.º 7
0
def opt_handler_two_commands():
    cmd_opts1 = {'a': ValidOption(type=str, default='uiae'),
                 'b': ValidOption(type=int, default=42),
                 'c': {'d': ValidOption(type=int, default=1337)}}
    cmd_opts2 = {'one': ValidOption(type=str, default='uiae')}
    oh = OptionsHandler()
    oh.add_sub_command('test_cmd', cmd_opts1, ['t', 'tc'])
    oh.add_sub_command('other_cmd', cmd_opts2, ['oc'])
    return oh
Exemplo n.º 8
0
def test_get_defaults(reference_default_config):
    oh = OptionsHandler()
    result = oh.get_defaults()
    assert result == reference_default_config
Exemplo n.º 9
0
def test_recursive_update6(basic_config_dict):
    current = basic_config_dict
    new = {'x': {'c': {'d': {42: 'test'}}}}
    # run
    with pytest.raises(KeyError):
        OptionsHandler._recursive_update(current, new)