mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 09:56:05 -05:00
[V3 Config] Fix unloading and implement singleton driver (#1458)
* Add the identifier as an initialization parameter * Remove config object singleton and opt for a shared JSON datastore * Fix bot unloading to deal with memory leaks * Fix tests * Fix clear all bug
This commit is contained in:
@@ -38,6 +38,7 @@ def json_driver(tmpdir_factory):
|
||||
path = Path(str(tmpdir_factory.mktemp(rand)))
|
||||
driver = red_json.JSON(
|
||||
"PyTest",
|
||||
identifier=str(uuid.uuid4()),
|
||||
data_path_override=path
|
||||
)
|
||||
return driver
|
||||
@@ -45,10 +46,9 @@ def json_driver(tmpdir_factory):
|
||||
|
||||
@pytest.fixture()
|
||||
def config(json_driver):
|
||||
import uuid
|
||||
conf = Config(
|
||||
cog_name="PyTest",
|
||||
unique_identifier=str(uuid.uuid4()),
|
||||
unique_identifier=json_driver.unique_cog_identifier,
|
||||
driver=json_driver)
|
||||
yield conf
|
||||
conf._defaults = {}
|
||||
@@ -59,10 +59,9 @@ def config_fr(json_driver):
|
||||
"""
|
||||
Mocked config object with force_register enabled.
|
||||
"""
|
||||
import uuid
|
||||
conf = Config(
|
||||
cog_name="PyTest",
|
||||
unique_identifier=str(uuid.uuid4()),
|
||||
unique_identifier=json_driver.unique_cog_identifier,
|
||||
driver=json_driver,
|
||||
force_registration=True
|
||||
)
|
||||
|
||||
@@ -298,6 +298,16 @@ async def test_member_clear_all(config, member_factory):
|
||||
assert len(await config.all_members()) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_clear_all(config):
|
||||
await config.foo.set(True)
|
||||
assert await config.foo() is True
|
||||
|
||||
await config.clear_all()
|
||||
with pytest.raises(KeyError):
|
||||
await config.get_raw('foo')
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_clear_value(config):
|
||||
await config.foo.set(True)
|
||||
|
||||
Reference in New Issue
Block a user