[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:
Will
2018-04-02 20:47:27 -04:00
committed by palmtree5
parent 720ef38886
commit 29ce2401ca
7 changed files with 94 additions and 37 deletions

View File

@@ -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
)

View File

@@ -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)