Test implicit subclass type conversion in config defaults/sets (#5874)

Co-authored-by: Jakub Kuczys <me@jacken.men>
This commit is contained in:
Flame442 2022-12-29 00:50:18 -05:00 committed by GitHub
parent 19ebd02595
commit 0e97c26b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import asyncio import asyncio
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from collections import Counter
# region Register Tests # region Register Tests
@ -593,6 +594,21 @@ async def test_raw_with_partial_primary_keys(config):
assert await config.custom("CUSTOM", "primary_key").identifier() is False assert await config.custom("CUSTOM", "primary_key").identifier() is False
@pytest.mark.asyncio
async def test_cast_subclass_default(config):
# regression test for GH-5557/GH-5585
config.register_global(foo=Counter({}))
assert type(config.defaults["GLOBAL"]["foo"]) is dict
assert config.defaults["GLOBAL"]["foo"] == {}
stored_value = await config.foo()
assert type(stored_value) is dict
assert stored_value == {}
await config.foo.set(Counter({"bar": 1}))
stored_value = await config.foo()
assert type(stored_value) is dict
assert stored_value == {"bar": 1}
""" """
Following PARAMS can be generated with: Following PARAMS can be generated with:
from functools import reduce from functools import reduce