mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Feature/eq method for default (#1789)
* Add changelog for #1707 * Add __eq__ and __hash__ methods to the Default class * Add tests for the eq and hash methods to the TestDefault
This commit is contained in:
parent
9f49c0413f
commit
875f37f780
3 changed files with 18 additions and 0 deletions
1
CHANGES/1707.feature.rst
Normal file
1
CHANGES/1707.feature.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Added `__eq__` and `__hash__` methods to the `Default` class.
|
||||
|
|
@ -28,6 +28,14 @@ class Default:
|
|||
def __repr__(self) -> str:
|
||||
return f"<{self}>"
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, Default):
|
||||
return NotImplemented
|
||||
return self._name == other._name
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(self._name)
|
||||
|
||||
|
||||
@dataclass(**dataclass_kwargs(slots=True, kw_only=True))
|
||||
class DefaultBotProperties:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,15 @@ class TestDefault:
|
|||
default = Default("test")
|
||||
assert repr(default) == "<Default('test')>"
|
||||
|
||||
def test_eq_same_name(self):
|
||||
assert Default("test") == Default("test")
|
||||
|
||||
def test_eq_different_name(self):
|
||||
assert Default("foo") != Default("bar")
|
||||
|
||||
def test_hash(self):
|
||||
assert hash(Default("test")) == hash(Default("test"))
|
||||
|
||||
|
||||
class TestDefaultBotProperties:
|
||||
def test_post_init_empty(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue