mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
Some checks are pending
Tests / tests (macos-latest, 3.10) (push) Waiting to run
Tests / tests (macos-latest, 3.11) (push) Waiting to run
Tests / tests (macos-latest, 3.12) (push) Waiting to run
Tests / tests (macos-latest, 3.13) (push) Waiting to run
Tests / tests (macos-latest, 3.9) (push) Waiting to run
Tests / tests (ubuntu-latest, 3.10) (push) Waiting to run
Tests / tests (ubuntu-latest, 3.11) (push) Waiting to run
Tests / tests (ubuntu-latest, 3.12) (push) Waiting to run
Tests / tests (ubuntu-latest, 3.13) (push) Waiting to run
Tests / tests (ubuntu-latest, 3.9) (push) Waiting to run
Tests / tests (windows-latest, 3.10) (push) Waiting to run
Tests / tests (windows-latest, 3.11) (push) Waiting to run
Tests / tests (windows-latest, 3.12) (push) Waiting to run
Tests / tests (windows-latest, 3.13) (push) Waiting to run
Tests / tests (windows-latest, 3.9) (push) Waiting to run
Tests / pypy-tests (macos-latest, pypy3.10) (push) Waiting to run
Tests / pypy-tests (macos-latest, pypy3.9) (push) Waiting to run
Tests / pypy-tests (ubuntu-latest, pypy3.10) (push) Waiting to run
Tests / pypy-tests (ubuntu-latest, pypy3.9) (push) Waiting to run
* Fix handler registration order in `Scene` Previously, `Scene` handlers were registered based on the sorted output of `inspect.getmembers`, causing incorrect execution order. Now, handlers are registered in the order they are defined in the class, ensuring reliable behavior and proper sequence when handling filters with varying specificity. Added test cases to validate the correct handler ordering. * Add dynamic dataclass and class attribute resolvers Introduced `dataclass_kwargs` to ensure compatibility with different Python versions and modular attribute handling. Added utilities for resolving class attributes dynamically, enhancing flexibility with MRO-based resolvers. Updated tests to verify new features and ensure proper functionality across various scenarios. * Update changelog
81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
import pytest
|
|
|
|
from aiogram.utils.class_attrs_resolver import (
|
|
get_reversed_mro_unique_attrs_resolver,
|
|
get_sorted_mro_attrs_resolver,
|
|
inspect_members_resolver,
|
|
)
|
|
|
|
|
|
class SimpleClass1:
|
|
def method1(self):
|
|
pass
|
|
|
|
def method2(self):
|
|
pass
|
|
|
|
|
|
class SimpleClass2:
|
|
def method2(self):
|
|
pass
|
|
|
|
def method1(self):
|
|
pass
|
|
|
|
|
|
class InheritedClass1(SimpleClass1):
|
|
def method3(self):
|
|
pass
|
|
|
|
def method4(self):
|
|
pass
|
|
|
|
|
|
class InheritedClass2(SimpleClass1):
|
|
def method2(self):
|
|
pass
|
|
|
|
def method3(self):
|
|
pass
|
|
|
|
|
|
class TestClassAttrsResolver:
|
|
@pytest.mark.parametrize(
|
|
"cls, resolver, expected",
|
|
[
|
|
# inspect_members_resolver
|
|
(SimpleClass1, inspect_members_resolver, ["method1", "method2"]),
|
|
(SimpleClass2, inspect_members_resolver, ["method1", "method2"]),
|
|
(
|
|
InheritedClass1,
|
|
inspect_members_resolver,
|
|
["method1", "method2", "method3", "method4"],
|
|
),
|
|
(InheritedClass2, inspect_members_resolver, ["method1", "method2", "method3"]),
|
|
# get_reversed_mro_unique_attrs_resolver
|
|
(SimpleClass1, get_reversed_mro_unique_attrs_resolver, ["method1", "method2"]),
|
|
(SimpleClass2, get_reversed_mro_unique_attrs_resolver, ["method2", "method1"]),
|
|
(
|
|
InheritedClass1,
|
|
get_reversed_mro_unique_attrs_resolver,
|
|
["method1", "method2", "method3", "method4"],
|
|
),
|
|
(
|
|
InheritedClass2,
|
|
get_reversed_mro_unique_attrs_resolver,
|
|
["method1", "method2", "method3"],
|
|
),
|
|
# get_sorted_mro_attrs_resolver
|
|
(SimpleClass1, get_sorted_mro_attrs_resolver, ["method1", "method2"]),
|
|
(SimpleClass2, get_sorted_mro_attrs_resolver, ["method2", "method1"]),
|
|
(
|
|
InheritedClass1,
|
|
get_sorted_mro_attrs_resolver,
|
|
["method3", "method4", "method1", "method2"],
|
|
),
|
|
(InheritedClass2, get_sorted_mro_attrs_resolver, ["method3", "method1", "method2"]),
|
|
],
|
|
)
|
|
def test_resolve_class_attrs(self, cls, resolver, expected):
|
|
names = [name for name, _ in resolver(cls) if not name.startswith("__")]
|
|
assert names == expected
|