Crow/tests/template/test.py

31 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2014-08-06 19:46:28 +00:00
from __future__ import print_function
import glob
import json
import os
import subprocess
for testfile in glob.glob("*.json"):
testdoc = json.load(open(testfile))
for test in testdoc["tests"]:
if "lambda" in test["data"]:
continue
open('data', 'w').write(json.dumps(test["data"]))
open('template', 'w').write(test["template"])
2014-08-02 01:46:00 +00:00
if "partials" in test:
open('partials', 'w').write(json.dumps(test["partials"]))
else:
open('partials', 'w').write("{}")
2014-08-06 19:46:28 +00:00
ret = subprocess.check_output("./mustachetest").decode('utf8')
print(testfile, test["name"])
if ret != test["expected"]:
2014-08-02 01:46:00 +00:00
if 'partials' in test:
2014-08-06 19:46:28 +00:00
print('partials:', json.dumps(test["partials"]))
print(json.dumps(test["data"]))
print(test["template"])
print('Expected:',repr(test["expected"]))
print('Actual:',repr(ret))
assert ret == test["expected"]
os.unlink('data')
os.unlink('template')
2014-08-02 01:46:00 +00:00
os.unlink('partials')