def test_defaults_and_env(self): config = Config({'present': 'dp', 'absent': 'da'}) environ = {'ENV_PRESENT': '1'} config.merge(environ, { convert('ENV_PRESENT', int): 'present', convert('ENV_ABSENT', int): 'absent', }) compare(config.present, expected=1) compare(config.absent, expected='da')
def test_defaults_and_env(self): config = Config({'present': 'dp', 'absent': 'da'}) environ = {'ENV_PRESENT': '1'} config.merge( environ, { convert('ENV_PRESENT', int): 'present', convert('ENV_ABSENT', int): 'absent', }) compare(config.present, expected=1) compare(config.absent, expected='da')
def test_mapping_type_conversion(self): config = Config({'x': 0}) data = {'y': '1'} config.merge(data, mapping={ convert(source['y'], int): target['x'] }) compare(config.data, expected={'x': 1})
def test_str_nested(self): compare( str( required(convert(source['foo'].y, int)).insert(0).append().merge()), expected= ("required(convert(source['foo'].y, int)).insert(0).append().merge()" ))
def test_mapping_extensive_conversation(self): config = Config({'a': 0}) data = {'x': 2, 'y': -1} def best(possible): return max(possible.values()) config.merge(data, mapping={ convert(source, best): target['a'] }) compare(config.data, expected={'a': 2})
def test_ensure_on_convert(self): data = '1' with ShouldRaise(TypeError('Cannot use convert() as target')): store(data, convert(target, int).x, 'y')
def test_convert_not_present(self): data = {} compare(load(data, convert('x', int)), expected=NotPresent('x'))
def test_convert_string(self): data = Namespace(x='1') compare(load(data, convert('x', int)), expected=1)
def test_convert(self): data = Namespace(x='1') compare(load(data, convert(source.x, int)), expected=1)
def test_convert_no_name(self): o = object() compare(str(convert(source, o)), expected=("convert(source, {!r})".format(o)))
def test_str_nested(self): compare(str( required(convert(source['foo'].y, int)).insert(0).append().merge() ), expected=( "required(convert(source['foo'].y, int)).insert(0).append().merge()" ))
def test_convert_no_name(self): o = object() compare(str(convert(source, o)), expected=( "convert(source, {!r})".format(o) ))