|
1 | 1 | from copy import copy |
2 | 2 |
|
3 | | -from pytest import fail |
4 | | - |
5 | 3 | from graphql.language import ( |
6 | 4 | Node, |
7 | 5 | FieldNode, |
@@ -420,22 +418,31 @@ def leave(self, *args): |
420 | 418 | def visits_kitchen_sink(kitchen_sink_query): # noqa: F811 |
421 | 419 | ast = parse(kitchen_sink_query) |
422 | 420 | visited = [] |
| 421 | + record = visited.append |
| 422 | + arg_stack = [] |
| 423 | + push = arg_stack.append |
| 424 | + pop = arg_stack.pop |
423 | 425 |
|
424 | 426 | # noinspection PyMethodMayBeStatic |
425 | 427 | class TestVisitor(Visitor): |
426 | 428 | def enter(self, *args): |
427 | | - check_visitor_fn_args(ast, *args) |
428 | 429 | node, key, parent = args[:3] |
429 | 430 | parent_kind = parent.kind if isinstance(parent, Node) else None |
430 | | - visited.append(["enter", node.kind, key, parent_kind]) |
| 431 | + record(["enter", node.kind, key, parent_kind]) |
431 | 432 |
|
432 | | - def leave(self, *args): |
433 | 433 | check_visitor_fn_args(ast, *args) |
| 434 | + push(args[:]) |
| 435 | + |
| 436 | + def leave(self, *args): |
434 | 437 | node, key, parent = args[:3] |
435 | 438 | parent_kind = parent.kind if isinstance(parent, Node) else None |
436 | | - visited.append(["leave", node.kind, key, parent_kind]) |
| 439 | + record(["leave", node.kind, key, parent_kind]) |
| 440 | + |
| 441 | + assert pop() == args |
437 | 442 |
|
438 | 443 | visit(ast, TestVisitor()) |
| 444 | + |
| 445 | + assert arg_stack == [] |
439 | 446 | assert visited == [ |
440 | 447 | ["enter", "document", None, None], |
441 | 448 | ["enter", "operation_definition", 0, None], |
|
0 commit comments