def test_del_key(string_io): config = Config() config['x'] = 10 config['sub'] = {'y': 20} config['sub']['sub1'] = {'z': 30, 'w': 40} config['sub']['sub2'] = {'z': 30, 'w': 40} del_key(config, "x") with pytest.raises(KeyError) as exc_info: del_key(config, "x") assert str(exc_info.value) == "'x'" del_key(config, "x", ignore_errors=True) with pytest.raises(KeyError) as exc_info: del_key(config, "sub.sub3.xx") assert str(exc_info.value) == "'sub3'" del_key(config, "sub.sub1") del_key(config, "sub.sub2.z") config.dump(string_io) assert string_io.getvalue() == """\
def test_del_key_ignore_errors(): config = Config() del_key(config, "a.x", ignore_errors=True)
def test_del_key_ignore_error(): config = Config() with pytest.raises(KeyError): del_key(config, "a.x", ignore_errors=False)
def test_del_key_all(keyall): config = Config() config['x'] = 10 config['y'] = 10 del_key(config, keyall) assert not config