def test_contains(): test_config = Config(CONFIG_NAME) test_config.config = {'x': 1, 'y': {'a': 2}} assert 'x' in test_config assert 'y.a' in test_config assert 'y.b' not in test_config
def test_contains(): test_config = Config(config_name) test_config.config = {'x': 1, 'y': {'a': 2}} assert 'x' in test_config assert 'y.a' in test_config assert 'y.b' not in test_config
def test_to_dict(): test_config = Config(CONFIG_NAME) test_config.config = {'x': 1, 'y': {'a': 2}} d = test_config.to_dict() assert d == test_config.config # make sure we copied d['z'] = 3 d['y']['b'] = 4 assert d != test_config.config assert d['y'] != test_config.config['y']
def test_get(): test_config = Config(CONFIG_NAME) test_config.config = {'x': 1, 'y': {'a': 2}} assert test_config.get('x') == 1 assert test_config['x'] == 1 assert test_config.get('y.a') == 2 assert test_config['y.a'] == 2 assert test_config.get('y.b', 123) == 123 with pytest.raises(KeyError): test_config.get('y.b') with pytest.raises(KeyError): test_config['y.b']
def test_set(): config = Config(CONFIG_NAME) with config.set(abc=123): assert config.config['abc'] == 123 with config.set(abc=456): assert config.config['abc'] == 456 assert config.config['abc'] == 123 assert 'abc' not in config.config with config.set({'abc': 123}): assert config.config['abc'] == 123 assert 'abc' not in config.config with config.set({'abc.x': 1, 'abc.y': 2, 'abc.z.a': 3}): assert config.config['abc'] == {'x': 1, 'y': 2, 'z': {'a': 3}} assert 'abc' not in config.config config.config = {} config.set({'abc.x': 123}) assert config.config['abc']['x'] == 123
def test_pprint(capsys): test_config = Config(CONFIG_NAME) test_config.config = {'x': 1, 'y': {'a': 2}} test_config.pprint() cap_out = capsys.readouterr()[0] assert cap_out == """{'x': 1, 'y': {'a': 2}}\n"""
def test_rename(): config = Config(CONFIG_NAME) aliases = {'foo_bar': 'foo.bar'} config.config = {'foo-bar': 123} config.rename(aliases) assert config.config == {'foo': {'bar': 123}}
def test_rename(): config = Config(config_name) aliases = {'foo-bar': 'foo.bar'} config.config = {'foo-bar': 123} config.rename(aliases) assert config.config == {'foo': {'bar': 123}}