Skip to content

Commit

Permalink
Fix warnings directly caused by test code (#3737)
Browse files Browse the repository at this point in the history
* Fix deprecated passing of types to union

* Fix use of wrong schema type in federation tests

* Fix test was leaking expected user warning

* Fix errors during pytest plugin teardown

* Fix deprecated use of argument name-based matching
  • Loading branch information
DoctorJohn authored Dec 23, 2024
1 parent ad01dc5 commit ddfc084
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 25 deletions.
4 changes: 2 additions & 2 deletions tests/benchmarks/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import AsyncIterator

import strawberry
from strawberry.directive import DirectiveLocation
from strawberry.directive import DirectiveLocation, DirectiveValue


@strawberry.type
Expand Down Expand Up @@ -80,7 +80,7 @@ async def long_running(self, count: int) -> AsyncIterator[int]:


@strawberry.directive(locations=[DirectiveLocation.FIELD])
def uppercase(value: str) -> str:
def uppercase(value: DirectiveValue[str]) -> str:
return value.upper()


Expand Down
24 changes: 22 additions & 2 deletions tests/federation/printer/test_additional_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ class Query:
}
type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
federatedType: FederatedType!
}
scalar _Any
union _Entity = FederatedType
type _Service {
sdl: String!
}
"""

schema = strawberry.Schema(
schema = strawberry.federation.Schema(
query=Query, config=StrawberryConfig(auto_camel_case=False)
)
assert schema.as_str() == textwrap.dedent(expected_type).strip()
Expand Down Expand Up @@ -72,11 +82,21 @@ class Query:
}
type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
federatedType: FederatedType!
}
scalar _Any
union _Entity = FederatedType
type _Service {
sdl: String!
}
"""

schema = strawberry.Schema(
schema = strawberry.federation.Schema(
query=Query, config=StrawberryConfig(auto_camel_case=False)
)
assert schema.as_str() == textwrap.dedent(expected_type).strip()
8 changes: 5 additions & 3 deletions tests/federation/printer/test_inaccessible.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import textwrap
from enum import Enum
from typing import Annotated
from typing import Annotated, Union

import strawberry

Expand Down Expand Up @@ -249,11 +249,13 @@ class A:
class B:
b: str

Union = strawberry.federation.union("Union", (A, B), inaccessible=True)
MyUnion = Annotated[
Union[A, B], strawberry.federation.union("Union", inaccessible=True)
]

@strawberry.federation.type
class Query:
hello: Union
hello: MyUnion

schema = strawberry.federation.Schema(query=Query, enable_federation_2=True)

Expand Down
8 changes: 5 additions & 3 deletions tests/federation/printer/test_tag.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import textwrap
from enum import Enum
from typing import Annotated
from typing import Annotated, Union

import strawberry

Expand Down Expand Up @@ -167,11 +167,13 @@ class A:
class B:
b: str

Union = strawberry.federation.union("Union", (A, B), tags=["myTag", "anotherTag"])
MyUnion = Annotated[
Union[A, B], strawberry.federation.union("Union", tags=["myTag", "anotherTag"])
]

@strawberry.federation.type
class Query:
hello: Union
hello: MyUnion

schema = strawberry.federation.Schema(query=Query, enable_federation_2=True)

Expand Down
23 changes: 9 additions & 14 deletions tests/schema/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,20 +614,6 @@ def multiple_infos(root, info1: Info, info2: Info) -> str:
pytest.param(parent_self_and_root),
pytest.param(multiple_parents),
pytest.param(multiple_infos),
pytest.param(
parent_and_self,
marks=pytest.mark.xfail(
strict=True,
reason="`self` should not raise ConflictingArgumentsError",
),
),
pytest.param(
self_and_root,
marks=pytest.mark.xfail(
strict=True,
reason="`self` should not raise ConflictingArgumentsError",
),
),
),
)
@pytest.mark.raises_strawberry_exception(
Expand All @@ -643,3 +629,12 @@ class Query:
name: str = strawberry.field(resolver=resolver)

strawberry.Schema(query=Query)


@pytest.mark.parametrize("resolver", (parent_and_self, self_and_root))
def test_self_should_not_raise_conflicting_arguments_error(resolver):
@strawberry.type
class Query:
name: str = strawberry.field(resolver=resolver)

strawberry.Schema(query=Query)
5 changes: 4 additions & 1 deletion tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class A:


def test_type_definition_is_aliased():
assert A.__strawberry_definition__ is A._type_definition
with pytest.warns(
match="_type_definition is deprecated, use __strawberry_definition__ instead"
):
assert A.__strawberry_definition__ is A._type_definition


def test_get_warns():
Expand Down

0 comments on commit ddfc084

Please sign in to comment.