--- /dev/null
+[report]
+exclude_lines =
+ if __name__ == .__main__.:
try:
# Maybe it's in the file system
path = partials_path + '/' + name + '.' + partials_ext
- return open(path, 'r')
+ with open(path, 'r') as partial:
+ return partial.read()
+
except IOError:
# Alright I give up on you
return ''
return output
-if __name__ == '__main__':
- args = {
- 'template': open(argv[2], 'r'),
- 'data': json.load(open(argv[1], 'r')),
- }
+def main(data, template):
+ data = data
+ template = template
- output = render(**args)
- print(output)
+ with open(template, 'r') as template_file:
+ with open(data, 'r') as data_file:
+ args = {
+ 'template': template_file,
+ 'data': json.load(data_file)
+ }
+
+ return render(**args)
+
+if __name__ == '__main__':
+ print(main(argv[1], argv[2]))
--- /dev/null
+
+variable test
+===
+test
+===
+test
+===
+
+comment test
+===
+===
+===
+
+html escape test (triple brackets)
+===
+< > & "
+===
+< > & "
+===
+
+html escape test (ampersand)
+===
+< > & "
+===
+< > & "
+===
+
+html escape test (normal)
+===
+< > & "
+===
+< > & "
+===
+
+section test (truthy)
+===
+true
+===
+true
+===
+
+section test (falsy)
+===
+===
+===
+
+section test (list)
+===
+number: 1
+name: one
+---
+number: 2
+name: two
+---
+number: 3
+name: three
+---
+===
+number: 1
+name: one
+---
+number: 2
+name: two
+---
+number: 3
+name: three
+---
+===
+
+section test (scope)
+===
+test
+new test
+===
+test
+new test
+===
+
+inverted section test (truthy)
+===
+===
+===
+
+inverted section test (falsy)
+===
+false
+===
+false
+===
+
+partial test
+===
+this is a partial
+===
+this is a partial
+===
+
+delimiter test
+===
+test
+test
+===
+test
+test
+===
import os
import json
-from entei import render
+import entei
SPECS_PATH = os.path.join('spec', 'specs')
SPECS = [path for path in os.listdir(SPECS_PATH) if path.endswith('.json')]
-STACHE = render
+STACHE = entei.render
def _test_case_from_path(json_path):
spec = spec.split('.')[0]
globals()[spec] = _test_case_from_path(os.path.join(SPECS_PATH, spec))
+
+class ExpandedCoverage(unittest.TestCase):
+
+ def test_unclosed_sections(self):
+ test1 = {
+ 'template': '{{# section }} oops {{/ wrong_section }}'
+ }
+
+ test2 = {
+ 'template': '{{# section }} end of file'
+ }
+
+ self.assertRaises(entei.UnclosedSection, entei.render, **test1)
+ self.assertRaises(entei.UnclosedSection, entei.render, **test2)
+
+ def test_main(self):
+ result = entei.main('data.json', 'test.mustache')
+ with open('test.rendered', 'r') as f:
+ expected = f.read()
+
+ self.assertEqual(result, expected)
+
+
# Run unit tests from command line
if __name__ == "__main__":
unittest.main()