Skip to content

Commit b7c095b

Browse files
committed
Move str and repr test to the appropriate files
Replicates graphql/graphql-js@2fcd55e
1 parent dc86a6e commit b7c095b

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ a query language for APIs created by Facebook.
1313
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
1414

1515
The current version 1.0.2 of GraphQL-core-next is up-to-date with GraphQL.js version
16-
14.1.1. All parts of the API are covered by an extensive test suite of currently 1726
16+
14.1.1. All parts of the API are covered by an extensive test suite of currently 1728
1717
unit tests.
1818

1919

graphql/language/source.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ def get_location(self, position: int) -> SourceLocation:
4848
line = 1
4949
column = 1
5050
return SourceLocation(line, column)
51+
52+
def __repr__(self):
53+
return f"<{self.__class__.__name__} name={self.name!r}>"

tests/language/test_source.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from graphql.language import Source
2+
3+
4+
def describe_source():
5+
def can_be_stringified():
6+
source = Source("")
7+
assert str(source) == "<Source name='GraphQL request'>"
8+
9+
source = Source("", "Custom source name")
10+
assert str(source) == "<Source name='Custom source name'>"

tests/type/test_definition.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
GraphQLFieldResolver,
1212
GraphQLInputField,
1313
GraphQLInputObjectType,
14-
GraphQLInt,
1514
GraphQLInterfaceType,
1615
GraphQLList,
1716
GraphQLNonNull,
@@ -96,21 +95,6 @@ def defines_an_object_type_with_deprecated_field():
9695
assert deprecated_field.type is GraphQLString
9796
assert deprecated_field.args == {}
9897

99-
def stringifies_simple_types():
100-
assert str(GraphQLInt) == "Int"
101-
assert str(ScalarType) == "Scalar"
102-
assert str(ObjectType) == "Object"
103-
assert str(InterfaceType) == "Interface"
104-
assert str(UnionType) == "Union"
105-
assert str(EnumType) == "Enum"
106-
assert str(InputObjectType) == "InputObject"
107-
108-
assert str(NonNullScalarType) == "Scalar!"
109-
assert str(ListOfScalarsType) == "[Scalar]"
110-
assert str(NonNullListOfScalars) == "[Scalar]!"
111-
assert str(ListOfNonNullScalarsType) == "[Scalar!]"
112-
assert str(GraphQLList(ListOfScalarsType)) == "[[Scalar]]"
113-
11498
def allows_a_thunk_for_union_member_types():
11599
union = GraphQLUnionType("ThunkUnion", lambda: [ObjectType])
116100

@@ -677,3 +661,26 @@ def rejects_a_non_type_as_nullable_type_of_non_null(type_):
677661
if isinstance(type_, GraphQLNonNull)
678662
else f"Can only create a wrapper for a GraphQLType, but got: {type_}."
679663
)
664+
665+
def describe_type_system_test_utility_methods():
666+
def stringifies_simple_types():
667+
assert str(ScalarType) == "Scalar"
668+
assert str(ObjectType) == "Object"
669+
assert str(InterfaceType) == "Interface"
670+
assert str(UnionType) == "Union"
671+
assert str(EnumType) == "Enum"
672+
assert str(InputObjectType) == "InputObject"
673+
674+
assert str(NonNullScalarType) == "Scalar!"
675+
assert str(ListOfScalarsType) == "[Scalar]"
676+
assert str(NonNullListOfScalars) == "[Scalar]!"
677+
assert str(ListOfNonNullScalarsType) == "[Scalar!]"
678+
assert str(GraphQLList(ListOfScalarsType)) == "[[Scalar]]"
679+
680+
def simple_types_have_repr():
681+
assert repr(ScalarType) == "<GraphQLScalarType(Scalar)>"
682+
assert repr(ObjectType) == "<GraphQLObjectType(Object)>"
683+
assert repr(InterfaceType) == "<GraphQLInterfaceType(Interface)>"
684+
assert repr(UnionType) == "<GraphQLUnionType(Union)>"
685+
assert repr(EnumType) == "<GraphQLEnumType(Enum)>"
686+
assert repr(InputObjectType) == "<GraphQLInputObjectType(InputObject)>"

0 commit comments

Comments
 (0)