Skip to content

Commit

Permalink
Add test for typing.NewType
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirVondukr committed Jan 13, 2024
1 parent 012fa21 commit 6c9277e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tests/test_inject.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Annotated
from typing import Annotated, NewType

import pytest

from aioinject import Container, Inject, inject, providers
from aioinject import Container, Inject, Object, Scoped, inject, providers
from aioinject.context import container_var
from aioinject.decorators import InjectMethod

Expand Down Expand Up @@ -96,3 +96,24 @@ async def injectee(service: Annotated[_Service, Inject]) -> _Service:
coro = injectee() # type: ignore[call-arg]
assert isinstance(await coro, _Service)
container_var.reset(token)


@pytest.mark.anyio
async def test_new_type() -> None:
A = NewType("A", int)
B = NewType("B", int)

class Service:
def __init__(self, a: A, b: B) -> None:
self.a = a
self.b = b

container = Container()
container.register(Object(1, type_=A))
container.register(Object(2, type_=B))
container.register(Scoped(Service))

async with container.context() as ctx:
service = await ctx.resolve(Service)
assert service.a == 1
assert service.b == 2 # noqa: PLR2004

0 comments on commit 6c9277e

Please sign in to comment.