|
37 | 37 | from graphql.utilities import build_ast_schema, build_schema, print_schema, print_type
|
38 | 38 |
|
39 | 39 | from ..fixtures import big_schema_sdl # noqa: F401
|
| 40 | +from ..star_wars_schema import star_wars_schema |
40 | 41 | from ..utils import dedent, timeout_factor
|
41 | 42 |
|
42 | 43 |
|
@@ -1188,7 +1189,50 @@ def rejects_invalid_ast():
|
1188 | 1189 | build_ast_schema({}) # type: ignore
|
1189 | 1190 | assert str(exc_info.value) == "Must provide valid Document AST."
|
1190 | 1191 |
|
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 |
1192 | 1236 | @mark.timeout(20 * timeout_factor)
|
1193 | 1237 | def can_deep_copy_big_schema(big_schema_sdl): # noqa: F811
|
1194 | 1238 | # use our printing conventions
|
|
0 commit comments