mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 18:06:08 -05:00
[V3 Config] Fix for unnecessary writes on context mgr exit (#1859)
* Fix for #1857 * And copy it so we don't have mutability issues * Add a test
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from unittest.mock import patch
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -399,6 +400,16 @@ async def test_ctxmgr_no_shared_default(config, member_factory):
|
||||
assert 1 not in await config.member(m2).foo()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ctxmgr_no_unnecessary_write(config):
|
||||
config.register_global(foo=[])
|
||||
foo_value_obj = config.foo
|
||||
with patch.object(foo_value_obj, "set") as set_method:
|
||||
async with foo_value_obj() as foo:
|
||||
pass
|
||||
set_method.assert_not_called()
|
||||
|
||||
|
||||
@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."""
|
||||
|
||||
Reference in New Issue
Block a user