mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 18:06:08 -05:00
[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:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user