Skip to content

Commit

Permalink
chore: refactored unittest for comparison of EMPTY with custom objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ahumbert committed Sep 24, 2024
1 parent 134e681 commit 998b236
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 96 deletions.
69 changes: 0 additions & 69 deletions examples/e12_custom_context.py

This file was deleted.

27 changes: 0 additions & 27 deletions tests/examples/test_e12_custom_context.py

This file was deleted.

26 changes: 26 additions & 0 deletions tests/utils/context/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,29 @@ def use(

assert use(1) == [1]
assert use(2) == [1, 2]


@pytest.mark.asyncio
async def test_context_with_custom_object_implementing_comparison(context: ContextRepo):
class User:
def __init__(self, user_id: int):
self.user_id = user_id

def __eq__(self, other):
if not isinstance(other, User):
return NotImplemented
return self.user_id == other.user_id

def __ne__(self, other):
return not self.__eq__(other)

@apply_types
async def use(
key1=Context("user1"),
key2=Context("user2", default=User(user_id=2)),
key3=Context("user3", default=User(user_id=3))
):
return key1 == User(user_id=1) and key2 == User(user_id=2) and key3 == User(user_id=4)

with context.scope("user1", User(user_id=1)), context.scope("user3", User(user_id=4)):
assert await use()

0 comments on commit 998b236

Please sign in to comment.