[Config] Group.__call__() has same behaviour as Group.all() (#2018)

* Make calling groups useful

This makes config.Group.__call__ effectively an alias for Group.all(),
with the added bonus of becoming a context manager.

get_raw has been updated as well to reflect the new behaviour of
__call__.

* Fix unintended side-effects of new behaviour

* Add tests

* Add test for get_raw mixing in defaults

* Another cleanup for relying on old behaviour internally

* Fix bank relying on old behaviour

* Reformat
This commit is contained in:
Toby Harradine
2018-08-26 23:30:36 +10:00
committed by GitHub
parent 48a7a21aca
commit dbed24aaca
3 changed files with 99 additions and 29 deletions

View File

@@ -430,3 +430,39 @@ async def test_set_then_mutate(config):
list1.append("foo")
list1 = await config.list1()
assert "foo" not in list1
@pytest.mark.asyncio
async def test_call_group_fills_defaults(config):
config.register_global(subgroup={"foo": True})
subgroup = await config.subgroup()
assert "foo" in subgroup
@pytest.mark.asyncio
async def test_group_call_ctxmgr_writes(config):
config.register_global(subgroup={"foo": True})
async with config.subgroup() as subgroup:
subgroup["bar"] = False
subgroup = await config.subgroup()
assert subgroup == {"foo": True, "bar": False}
@pytest.mark.asyncio
async def test_all_works_as_ctxmgr(config):
config.register_global(subgroup={"foo": True})
async with config.subgroup.all() as subgroup:
subgroup["bar"] = False
subgroup = await config.subgroup()
assert subgroup == {"foo": True, "bar": False}
@pytest.mark.asyncio
async def test_get_raw_mixes_defaults(config):
config.register_global(subgroup={"foo": True})
await config.subgroup.set_raw("bar", value=False)
subgroup = await config.get_raw("subgroup")
assert subgroup == {"foo": True, "bar": False}