From 0e97c26b2d22d724550a6ce4e1097037a6b8cdd1 Mon Sep 17 00:00:00 2001 From: Flame442 <34169552+Flame442@users.noreply.github.com> Date: Thu, 29 Dec 2022 00:50:18 -0500 Subject: [PATCH] Test implicit subclass type conversion in config defaults/sets (#5874) Co-authored-by: Jakub Kuczys --- tests/core/test_config.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/core/test_config.py b/tests/core/test_config.py index 473b4da28..bef10426d 100644 --- a/tests/core/test_config.py +++ b/tests/core/test_config.py @@ -1,6 +1,7 @@ import asyncio from unittest.mock import patch import pytest +from collections import Counter # 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 +@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: from functools import reduce