mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 01:46:05 -05:00
[V3 JSON] Drivers deepcopy input/output data (#1855)
* [V3 JSON] Return deepcopy in JSON driver * Add a test * foo not bar * Add a test for setting and then mutating * Resolve issue for setting and mutating as well * Reformat
This commit is contained in:
@@ -379,13 +379,9 @@ async def test_value_ctxmgr_saves(config):
|
||||
async def test_value_ctxmgr_immutable(config):
|
||||
config.register_global(foo=True)
|
||||
|
||||
try:
|
||||
with pytest.raises(TypeError):
|
||||
async with config.foo() as foo:
|
||||
foo = False
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError
|
||||
|
||||
foo = await config.foo()
|
||||
assert foo is True
|
||||
@@ -401,3 +397,25 @@ async def test_ctxmgr_no_shared_default(config, member_factory):
|
||||
foo.append(1)
|
||||
|
||||
assert 1 not in await config.member(m2).foo()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_then_mutate(config):
|
||||
"""Tests that mutating an object after getting it as a value doesn't mutate the data store."""
|
||||
config.register_global(list1=[])
|
||||
await config.list1.set([])
|
||||
list1 = await config.list1()
|
||||
list1.append("foo")
|
||||
list1 = await config.list1()
|
||||
assert "foo" not in list1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_then_mutate(config):
|
||||
"""Tests that mutating an object after setting it as a value doesn't mutate the data store."""
|
||||
config.register_global(list1=[])
|
||||
list1 = []
|
||||
await config.list1.set(list1)
|
||||
list1.append("foo")
|
||||
list1 = await config.list1()
|
||||
assert "foo" not in list1
|
||||
|
||||
Reference in New Issue
Block a user