mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-06 17:32:31 -05:00
Make some dependency changes, support Python 3.10 and 3.11 (#5611)
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
@@ -5,7 +5,6 @@ from collections import Counter
|
||||
|
||||
|
||||
# region Register Tests
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_register_global(config):
|
||||
config.register_global(enabled=False)
|
||||
assert config.defaults["GLOBAL"]["enabled"] is False
|
||||
@@ -17,7 +16,6 @@ def test_config_register_global_badvalues(config):
|
||||
config.register_global(**{"invalid var name": True})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_register_guild(config, empty_guild):
|
||||
config.register_guild(enabled=False, some_list=[], some_dict={})
|
||||
assert config.defaults[config.GUILD]["enabled"] is False
|
||||
@@ -29,35 +27,30 @@ async def test_config_register_guild(config, empty_guild):
|
||||
assert await config.guild(empty_guild).some_dict() == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_register_channel(config, empty_channel):
|
||||
config.register_channel(enabled=False)
|
||||
assert config.defaults[config.CHANNEL]["enabled"] is False
|
||||
assert await config.channel(empty_channel).enabled() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_register_role(config, empty_role):
|
||||
config.register_role(enabled=False)
|
||||
assert config.defaults[config.ROLE]["enabled"] is False
|
||||
assert await config.role(empty_role).enabled() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_register_member(config, empty_member):
|
||||
config.register_member(some_number=-1)
|
||||
assert config.defaults[config.MEMBER]["some_number"] == -1
|
||||
assert await config.member(empty_member).some_number() == -1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_register_user(config, empty_user):
|
||||
config.register_user(some_value=None)
|
||||
assert config.defaults[config.USER]["some_value"] is None
|
||||
assert await config.user(empty_user).some_value() is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_force_register_global(config_fr):
|
||||
with pytest.raises(AttributeError):
|
||||
await config_fr.enabled()
|
||||
@@ -70,13 +63,11 @@ async def test_config_force_register_global(config_fr):
|
||||
|
||||
|
||||
# Test nested registration
|
||||
@pytest.mark.asyncio
|
||||
async def test_nested_registration(config):
|
||||
config.register_global(foo__bar__baz=False)
|
||||
assert await config.foo.bar.baz() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nested_registration_asdict(config):
|
||||
defaults = {"bar": {"baz": False}}
|
||||
config.register_global(foo=defaults)
|
||||
@@ -84,7 +75,6 @@ async def test_nested_registration_asdict(config):
|
||||
assert await config.foo.bar.baz() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nested_registration_and_changing(config):
|
||||
defaults = {"bar": {"baz": False}}
|
||||
config.register_global(foo=defaults)
|
||||
@@ -95,7 +85,6 @@ async def test_nested_registration_and_changing(config):
|
||||
await config.foo.set(True)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_doubleset_default(config):
|
||||
config.register_global(foo=True)
|
||||
config.register_global(foo=False)
|
||||
@@ -103,7 +92,6 @@ async def test_doubleset_default(config):
|
||||
assert await config.foo() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nested_registration_multidict(config):
|
||||
defaults = {"foo": {"bar": {"baz": True}}, "blah": True}
|
||||
config.register_global(**defaults)
|
||||
@@ -118,7 +106,6 @@ def test_nested_group_value_badreg(config):
|
||||
config.register_global(foo__bar=False)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nested_toplevel_reg(config):
|
||||
defaults = {"bar": True, "baz": False}
|
||||
config.register_global(foo=defaults)
|
||||
@@ -127,7 +114,6 @@ async def test_nested_toplevel_reg(config):
|
||||
assert await config.foo.baz() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nested_overlapping(config):
|
||||
config.register_global(foo__bar=True)
|
||||
config.register_global(foo__baz=False)
|
||||
@@ -136,7 +122,6 @@ async def test_nested_overlapping(config):
|
||||
assert await config.foo.baz() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nesting_nofr(config):
|
||||
config.register_global(foo={})
|
||||
assert await config.foo.bar() is None
|
||||
@@ -144,38 +129,31 @@ async def test_nesting_nofr(config):
|
||||
|
||||
|
||||
# region Default Value Overrides
|
||||
@pytest.mark.asyncio
|
||||
async def test_global_default_override(config):
|
||||
assert await config.enabled(True) is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_global_default_nofr(config):
|
||||
assert await config.nofr() is None
|
||||
assert await config.nofr(True) is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_guild_default_override(config, empty_guild):
|
||||
assert await config.guild(empty_guild).enabled(True) is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_channel_default_override(config, empty_channel):
|
||||
assert await config.channel(empty_channel).enabled(True) is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_role_default_override(config, empty_role):
|
||||
assert await config.role(empty_role).enabled(True) is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_member_default_override(config, empty_member):
|
||||
assert await config.member(empty_member).enabled(True) is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_user_default_override(config, empty_user):
|
||||
assert await config.user(empty_user).some_value(True) is True
|
||||
|
||||
@@ -184,13 +162,11 @@ async def test_user_default_override(config, empty_user):
|
||||
|
||||
|
||||
# region Setting Values
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_global(config):
|
||||
await config.enabled.set(True)
|
||||
assert await config.enabled() is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_guild(config, empty_guild):
|
||||
await config.guild(empty_guild).enabled.set(True)
|
||||
assert await config.guild(empty_guild).enabled() is True
|
||||
@@ -203,13 +179,11 @@ async def test_set_guild(config, empty_guild):
|
||||
assert await config.guild(empty_guild).some_list() == curr_list
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_channel(config, empty_channel):
|
||||
await config.channel(empty_channel).enabled.set(True)
|
||||
assert await config.channel(empty_channel).enabled() is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_channel_no_register(config, empty_channel):
|
||||
await config.channel(empty_channel).no_register.set(True)
|
||||
assert await config.channel(empty_channel).no_register() is True
|
||||
@@ -219,14 +193,12 @@ async def test_set_channel_no_register(config, empty_channel):
|
||||
|
||||
|
||||
# Dynamic attribute testing
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_dynamic_attr(config):
|
||||
await config.set_raw("foobar", value=True)
|
||||
|
||||
assert await config.foobar() is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_clear_dynamic_attr(config):
|
||||
await config.foo.set(True)
|
||||
await config.clear_raw("foo")
|
||||
@@ -235,13 +207,11 @@ async def test_clear_dynamic_attr(config):
|
||||
await config.get_raw("foo")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_dynamic_attr(config):
|
||||
assert await config.get_raw("foobaz", default=True) is True
|
||||
|
||||
|
||||
# Member Group testing
|
||||
@pytest.mark.asyncio
|
||||
async def test_membergroup_allguilds(config, empty_member):
|
||||
await config.member(empty_member).foo.set(False)
|
||||
|
||||
@@ -249,7 +219,6 @@ async def test_membergroup_allguilds(config, empty_member):
|
||||
assert empty_member.guild.id in all_servers
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_membergroup_allmembers(config, empty_member):
|
||||
await config.member(empty_member).foo.set(False)
|
||||
|
||||
@@ -258,7 +227,6 @@ async def test_membergroup_allmembers(config, empty_member):
|
||||
|
||||
|
||||
# Clearing testing
|
||||
@pytest.mark.asyncio
|
||||
async def test_global_clear(config):
|
||||
config.register_global(foo=True, bar=False)
|
||||
|
||||
@@ -274,7 +242,6 @@ async def test_global_clear(config):
|
||||
assert await config.bar() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_member_clear(config, member_factory):
|
||||
config.register_member(foo=True)
|
||||
|
||||
@@ -293,7 +260,6 @@ async def test_member_clear(config, member_factory):
|
||||
assert await config.member(m2).foo() is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_member_clear_all(config, member_factory):
|
||||
server_ids = []
|
||||
for _ in range(5):
|
||||
@@ -309,7 +275,6 @@ 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
|
||||
@@ -319,7 +284,6 @@ async def test_clear_all(config):
|
||||
await config.get_raw("foo")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_clear_value(config):
|
||||
await config.foo.set(True)
|
||||
await config.foo.clear()
|
||||
@@ -329,7 +293,6 @@ async def test_clear_value(config):
|
||||
|
||||
|
||||
# Get All testing
|
||||
@pytest.mark.asyncio
|
||||
async def test_user_get_all_from_kind(config, user_factory):
|
||||
config.register_user(foo=False, bar=True)
|
||||
for _ in range(5):
|
||||
@@ -345,7 +308,6 @@ async def test_user_get_all_from_kind(config, user_factory):
|
||||
assert v["bar"] is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_user_getalldata(config, user_factory):
|
||||
user = user_factory.get()
|
||||
config.register_user(foo=True, bar=False)
|
||||
@@ -359,7 +321,6 @@ async def test_user_getalldata(config, user_factory):
|
||||
assert config.user(user).defaults["foo"] is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_value_ctxmgr(config):
|
||||
config.register_global(foo_list=[])
|
||||
|
||||
@@ -371,7 +332,6 @@ async def test_value_ctxmgr(config):
|
||||
assert "foo" in foo_list
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_value_ctxmgr_saves(config):
|
||||
config.register_global(bar_list=[])
|
||||
|
||||
@@ -387,7 +347,6 @@ async def test_value_ctxmgr_saves(config):
|
||||
assert "bar" in bar_list
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_value_ctxmgr_immutable(config):
|
||||
config.register_global(foo=True)
|
||||
|
||||
@@ -399,7 +358,6 @@ async def test_value_ctxmgr_immutable(config):
|
||||
assert foo is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ctxmgr_no_shared_default(config, member_factory):
|
||||
config.register_member(foo=[])
|
||||
m1 = member_factory.get()
|
||||
@@ -411,7 +369,6 @@ 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
|
||||
@@ -421,7 +378,6 @@ async def test_ctxmgr_no_unnecessary_write(config):
|
||||
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."""
|
||||
config.register_global(list1=[])
|
||||
@@ -432,7 +388,6 @@ async def test_get_then_mutate(config):
|
||||
assert "foo" not in list1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_then_mutate(config):
|
||||
"""Tests that mutating an object after setting it as a value doesn't mutate the data store."""
|
||||
config.register_global(list1=[])
|
||||
@@ -443,14 +398,12 @@ async def test_set_then_mutate(config):
|
||||
assert "foo" not in list1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_call_group_fills_defaults(config):
|
||||
config.register_global(subgroup={"foo": True})
|
||||
subgroup = await config.subgroup()
|
||||
assert "foo" in subgroup
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_group_call_ctxmgr_writes(config):
|
||||
config.register_global(subgroup={"foo": True})
|
||||
async with config.subgroup() as subgroup:
|
||||
@@ -460,7 +413,6 @@ async def test_group_call_ctxmgr_writes(config):
|
||||
assert subgroup == {"foo": True, "bar": False}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_all_works_as_ctxmgr(config):
|
||||
config.register_global(subgroup={"foo": True})
|
||||
async with config.subgroup.all() as subgroup:
|
||||
@@ -470,7 +422,6 @@ async def test_all_works_as_ctxmgr(config):
|
||||
assert subgroup == {"foo": True, "bar": False}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_raw_mixes_defaults(config):
|
||||
config.register_global(subgroup={"foo": True})
|
||||
await config.subgroup.set_raw("bar", value=False)
|
||||
@@ -479,7 +430,6 @@ async def test_get_raw_mixes_defaults(config):
|
||||
assert subgroup == {"foo": True, "bar": False}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cast_str_raw(config):
|
||||
await config.set_raw(123, 456, value=True)
|
||||
assert await config.get_raw(123, 456) is True
|
||||
@@ -487,7 +437,6 @@ async def test_cast_str_raw(config):
|
||||
await config.clear_raw("123", 456)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_cast_str_nested(config):
|
||||
config.register_global(foo={})
|
||||
await config.foo.set({123: True, 456: {789: False}})
|
||||
@@ -510,7 +459,6 @@ def test_config_custom_doubleinit(config):
|
||||
config.init_custom("TEST", 2)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_locks_cache(config, empty_guild):
|
||||
lock1 = config.foo.get_lock()
|
||||
assert lock1 is config.foo.get_lock()
|
||||
@@ -519,7 +467,6 @@ async def test_config_locks_cache(config, empty_guild):
|
||||
assert lock1 is not lock2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_value_atomicity(config):
|
||||
config.register_global(foo=[])
|
||||
tasks = []
|
||||
@@ -539,7 +486,6 @@ async def test_config_value_atomicity(config):
|
||||
assert len(await config.foo()) == 15
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_ctxmgr_atomicity(config):
|
||||
config.register_global(foo=[])
|
||||
tasks = []
|
||||
@@ -557,7 +503,6 @@ async def test_config_ctxmgr_atomicity(config):
|
||||
assert len(await config.foo()) == 15
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_with_partial_primary_keys(config):
|
||||
config.init_custom("CUSTOM", 3)
|
||||
await config.custom("CUSTOM", "1").set({"11": {"111": {"foo": "bar"}}})
|
||||
@@ -585,7 +530,6 @@ async def test_set_with_partial_primary_keys(config):
|
||||
assert await config.custom("CUSTOM", "2", "33", "222").foo() == "biz"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_raw_with_partial_primary_keys(config):
|
||||
config.init_custom("CUSTOM", 1)
|
||||
await config.custom("CUSTOM").set_raw("primary_key", "identifier", value=True)
|
||||
@@ -654,7 +598,6 @@ PARAMS = [
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pkeys, raw_args, result", PARAMS)
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_custom_partial_pkeys_get(config, pkeys, raw_args, result):
|
||||
# setup
|
||||
config.init_custom("TEST", 3)
|
||||
@@ -666,7 +609,6 @@ async def test_config_custom_partial_pkeys_get(config, pkeys, raw_args, result):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pkeys, raw_args, result", PARAMS)
|
||||
@pytest.mark.asyncio
|
||||
async def test_config_custom_partial_pkeys_set(config, pkeys, raw_args, result):
|
||||
# setup
|
||||
config.init_custom("TEST", 3)
|
||||
|
||||
Reference in New Issue
Block a user