Skip to content

Commit b0c6973

Browse files
committed
Test with big schema only in slow lane
1 parent 4e01d51 commit b0c6973

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

tests/type/test_definition.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pickle
12
from enum import Enum
23
from math import isnan, nan
34
from typing import Dict, cast
@@ -261,6 +262,17 @@ def rejects_a_scalar_type_with_incorrect_extension_ast_nodes():
261262
" as a collection of ScalarTypeExtensionNode instances."
262263
)
263264

265+
def pickles_a_custom_scalar_type():
266+
foo_type = GraphQLScalarType("Foo")
267+
cycled_foo_type = pickle.loads(pickle.dumps(foo_type))
268+
assert cycled_foo_type.name == foo_type.name
269+
assert cycled_foo_type is not foo_type
270+
271+
def pickles_a_specified_scalar_type():
272+
cycled_int_type = pickle.loads(pickle.dumps(GraphQLInt))
273+
assert cycled_int_type.name == "Int"
274+
assert cycled_int_type is GraphQLInt
275+
264276

265277
def describe_type_system_fields():
266278
def defines_a_field():

tests/utilities/test_build_ast_schema.py

+45-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from graphql.utilities import build_ast_schema, build_schema, print_schema, print_type
3838

3939
from ..fixtures import big_schema_sdl # noqa: F401
40+
from ..star_wars_schema import star_wars_schema
4041
from ..utils import dedent, timeout_factor
4142

4243

@@ -1188,7 +1189,50 @@ def rejects_invalid_ast():
11881189
build_ast_schema({}) # type: ignore
11891190
assert str(exc_info.value) == "Must provide valid Document AST."
11901191

1191-
def describe_deepcopy_and_pickle():
1192+
def describe_deepcopy_and_pickle(): # pragma: no cover
1193+
star_wars_sdl = print_schema(star_wars_schema)
1194+
1195+
def can_deep_copy_star_wars_schema():
1196+
# create a schema from the star wars SDL
1197+
schema = build_schema(star_wars_sdl, assume_valid_sdl=True)
1198+
# create a deepcopy of the schema
1199+
copied = deepcopy(schema)
1200+
# check that printing the copied schema gives the same SDL
1201+
assert print_schema(copied) == star_wars_sdl
1202+
1203+
def can_pickle_and_unpickle_star_wars_schema():
1204+
# create a schema from the star wars SDL
1205+
schema = build_schema(star_wars_sdl, assume_valid_sdl=True)
1206+
# check that the schema can be pickled
1207+
# (particularly, there should be no recursion error,
1208+
# or errors because of trying to pickle lambdas or local functions)
1209+
dumped = pickle.dumps(schema)
1210+
1211+
# check that the pickle size is reasonable
1212+
assert len(dumped) < 25 * len(star_wars_sdl)
1213+
loaded = pickle.loads(dumped)
1214+
1215+
# check that printing the unpickled schema gives the same SDL
1216+
assert print_schema(loaded) == star_wars_sdl
1217+
1218+
# check that pickling again creates the same result
1219+
dumped = pickle.dumps(schema)
1220+
assert len(dumped) < 25 * len(star_wars_sdl)
1221+
loaded = pickle.loads(dumped)
1222+
assert print_schema(loaded) == star_wars_sdl
1223+
1224+
def can_deep_copy_pickled_star_wars_schema():
1225+
# create a schema from the star wars SDL
1226+
schema = build_schema(star_wars_sdl, assume_valid_sdl=True)
1227+
# pickle and unpickle the schema
1228+
loaded = pickle.loads(pickle.dumps(schema))
1229+
# create a deepcopy of the unpickled schema
1230+
copied = deepcopy(loaded)
1231+
# check that printing the copied schema gives the same SDL
1232+
assert print_schema(copied) == star_wars_sdl
1233+
1234+
@mark.slow
1235+
def describe_deepcopy_and_pickle_big(): # pragma: no cover
11921236
@mark.timeout(20 * timeout_factor)
11931237
def can_deep_copy_big_schema(big_schema_sdl): # noqa: F811
11941238
# use our printing conventions

0 commit comments

Comments
 (0)