__init__.py 823 B

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