def test_builtin_converters(converter, value, customized, reset): data = {'a': value} config = DictSource(data, converters=[converter]) assert config.a == customized del config.a config.a = customized assert config._data['a'] == reset
def test_write_source_with_converters(): data = {'a': 1, 'b': {'c': 2}} converter_list = [ ('a', str, int), ('c', lambda v: 2 * v, lambda v: v / 2), ] config = DictSource(data, converters=converter_list) config.a = '1' config.b.c = 4 assert config._data == data
def test_prevent_writing_to_locked_source(): data = {'a': 1, 'b': {'c': 2, 'd': {'e': 3}}} config = DictSource(data, readonly=True) with pytest.raises(TypeError) as exc_info: config.a = 10 assert 'locked' in str(exc_info.value) with pytest.raises(TypeError) as exc_info: config.b.c = 20 assert 'locked' in str(exc_info.value)
def test_write_cached_dict_source(): config = DictSource({}, cached=True) config.a = 1 config.b = {} config.b.c = 2 config.b.d = {} config.b.d.e = 3 assert config._data == {} config.write_cache() assert config._data == {'a': 1, 'b': {'c': 2, 'd': {'e': 3}}}
def test_write_dict_source(): data = {'a': 1, 'b': {'c': 2, 'd': {'e': 3}}} config = DictSource(data) assert config.a == 1 assert config.b.c == 2 assert config.b.d == {'e': 3} config.a = 10 config.b.c = 20 del config.b.d.e assert config.a == 10 assert config.b.c == 20 with pytest.raises(AttributeError): config.b.d.e