예제 #1
0
def test_load_args():
    """Can args override config and default."""
    config = io.BytesIO("bar.baz:   12.34")
    args = {'bar.baz': "7.8", 'foo': '9.0'}
    values = settings.load(args, config, DEFINITIONS)
    assert values['foo'] == 9.0
    assert values['bar.baz'] == 7.8
예제 #2
0
def test_load_key_error_arg():
    """Throw SettingKeyError if arg contains a key without a definition."""
    args = {'foobar': '1'}
    with pytest.raises(settings.SettingKeyError):
        settings.load(args, None, DEFINITIONS)
예제 #3
0
def test_load_key_error_config():
    """Throw SettingKeyError if a setting in the config file is not defined."""
    config = io.BytesIO("foobar: 1")
    with pytest.raises(settings.SettingKeyError):
        settings.load(None, config, DEFINITIONS)
예제 #4
0
def test_load_syntax_error():
    """Throw ConfigSyntaxError if config's syntax is invalid."""
    config = io.BytesIO("foobar")
    with pytest.raises(settings.ConfigSyntaxError):
        settings.load(None, config, DEFINITIONS)
예제 #5
0
def test_load_config():
    """Can load settings from config file."""
    config = io.BytesIO("bar.baz:   1234.56")
    values = settings.load(None, config, DEFINITIONS)
    assert values['foo'] == float(DEFAULT_FOO)
    assert values['bar.baz'] == 1234.56
예제 #6
0
def test_load_default_values():
    """Can load default values."""
    values = settings.load(None, None, DEFINITIONS)
    assert len(values) == 2
    assert values['foo'] == float(DEFAULT_FOO)
    assert values['bar.baz'] == float(DEFAULT_BAZ)