test.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import glob
  4. import json
  5. import os
  6. import subprocess
  7. for testfile in glob.glob("*.json"):
  8. testdoc = json.load(open(testfile))
  9. for test in testdoc["tests"]:
  10. if "lambda" in test["data"]:
  11. continue
  12. open('data', 'w').write(json.dumps(test["data"]))
  13. open('template', 'w').write(test["template"])
  14. if "partials" in test:
  15. open('partials', 'w').write(json.dumps(test["partials"]))
  16. else:
  17. open('partials', 'w').write("{}")
  18. ret = subprocess.check_output("./mustachetest").decode('utf8')
  19. print(testfile, test["name"])
  20. if ret != test["expected"]:
  21. if 'partials' in test:
  22. print('partials:', json.dumps(test["partials"]))
  23. print(json.dumps(test["data"]))
  24. print(test["template"])
  25. print('Expected:',repr(test["expected"]))
  26. print('Actual:',repr(ret))
  27. assert ret == test["expected"]
  28. os.unlink('data')
  29. os.unlink('template')
  30. os.unlink('partials')