|
| 1 | +import pickle |
1 | 2 | from collections import namedtuple
|
| 3 | +from copy import deepcopy |
2 | 4 | from typing import Union
|
3 | 5 |
|
4 | 6 | from pytest import raises
|
@@ -1186,30 +1188,51 @@ def rejects_invalid_ast():
|
1186 | 1188 | build_ast_schema({}) # type: ignore
|
1187 | 1189 | assert str(exc_info.value) == "Must provide valid Document AST."
|
1188 | 1190 |
|
1189 |
| - def can_pickle_and_unpickle_big_schema( |
1190 |
| - big_schema_sdl, # noqa: F811 |
1191 |
| - ): # pragma: no cover |
1192 |
| - import pickle |
1193 |
| - |
1194 |
| - # use our printing conventions |
1195 |
| - big_schema_sdl = cycle_sdl(big_schema_sdl) |
1196 |
| - |
1197 |
| - # create a schema from the kitchen sink SDL |
1198 |
| - schema = build_schema(big_schema_sdl, assume_valid_sdl=True) |
1199 |
| - # check that the schema can be pickled |
1200 |
| - # (particularly, there should be no recursion error, |
1201 |
| - # or errors because of trying to pickle lambdas or local functions) |
1202 |
| - dumped = pickle.dumps(schema) |
1203 |
| - |
1204 |
| - # check that the pickle size is reasonable |
1205 |
| - assert len(dumped) < 25 * len(big_schema_sdl) |
1206 |
| - loaded = pickle.loads(dumped) |
1207 |
| - |
1208 |
| - # check that printing the unpickled schema gives the same SDL |
1209 |
| - assert print_schema(loaded) == big_schema_sdl |
1210 |
| - |
1211 |
| - # check that pickling again creates the same result |
1212 |
| - dumped = pickle.dumps(schema) |
1213 |
| - assert len(dumped) < 25 * len(big_schema_sdl) |
1214 |
| - loaded = pickle.loads(dumped) |
1215 |
| - assert print_schema(loaded) == big_schema_sdl |
| 1191 | + def describe_deepcopy_and_pickle(): |
| 1192 | + def can_deep_copy_big_schema(big_schema_sdl): # noqa: F811 |
| 1193 | + # use our printing conventions |
| 1194 | + big_schema_sdl = cycle_sdl(big_schema_sdl) |
| 1195 | + |
| 1196 | + # create a schema from the kitchen sink SDL |
| 1197 | + schema = build_schema(big_schema_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) == big_schema_sdl |
| 1202 | + |
| 1203 | + def can_pickle_and_unpickle_big_schema(big_schema_sdl): # noqa: F811 |
| 1204 | + # use our printing conventions |
| 1205 | + big_schema_sdl = cycle_sdl(big_schema_sdl) |
| 1206 | + |
| 1207 | + # create a schema from the kitchen sink SDL |
| 1208 | + schema = build_schema(big_schema_sdl, assume_valid_sdl=True) |
| 1209 | + # check that the schema can be pickled |
| 1210 | + # (particularly, there should be no recursion error, |
| 1211 | + # or errors because of trying to pickle lambdas or local functions) |
| 1212 | + dumped = pickle.dumps(schema) |
| 1213 | + |
| 1214 | + # check that the pickle size is reasonable |
| 1215 | + assert len(dumped) < 25 * len(big_schema_sdl) |
| 1216 | + loaded = pickle.loads(dumped) |
| 1217 | + |
| 1218 | + # check that printing the unpickled schema gives the same SDL |
| 1219 | + assert print_schema(loaded) == big_schema_sdl |
| 1220 | + |
| 1221 | + # check that pickling again creates the same result |
| 1222 | + dumped = pickle.dumps(schema) |
| 1223 | + assert len(dumped) < 25 * len(big_schema_sdl) |
| 1224 | + loaded = pickle.loads(dumped) |
| 1225 | + assert print_schema(loaded) == big_schema_sdl |
| 1226 | + |
| 1227 | + def can_deep_copy_pickled_big_schema(big_schema_sdl): # noqa: F811 |
| 1228 | + # use our printing conventions |
| 1229 | + big_schema_sdl = cycle_sdl(big_schema_sdl) |
| 1230 | + |
| 1231 | + # create a schema from the kitchen sink SDL |
| 1232 | + schema = build_schema(big_schema_sdl, assume_valid_sdl=True) |
| 1233 | + # pickle and unpickle the schema |
| 1234 | + loaded = pickle.loads(pickle.dumps(schema)) |
| 1235 | + # create a deepcopy of the unpickled schema |
| 1236 | + copied = deepcopy(loaded) |
| 1237 | + # check that printing the copied schema gives the same SDL |
| 1238 | + assert print_schema(copied) == big_schema_sdl |
0 commit comments