blob: 61f6687575585e8347c9c613d036cb2f77fae7a5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import sys
from jmespath import ast
import unittest
import json
from collections import OrderedDict
# Helper method used to create an s-expression
# of the AST to make unit test assertions easier.
# You get a nice string diff on assert failures.
def as_s_expression(node):
parts = []
_as_s_expression(node, parts)
return ''.join(parts)
def _as_s_expression(node, parts):
parts.append("(%s" % (node.__class__.__name__.lower()))
if isinstance(node, ast.Field):
parts.append(" %s" % node.name)
elif isinstance(node, ast.FunctionExpression):
parts.append(" %s" % node.name)
elif isinstance(node, ast.KeyValPair):
parts.append(" %s" % node.key_name)
for child in node.children:
parts.append(" ")
_as_s_expression(child, parts)
parts.append(")")
|