Commit fe84cb12 by Chris Jerdonek

Merge 'issue_71' into development: closing issue #71 (spec tests)

This brings the spec tests into the nosetest/unittest run.
parents a2be08fd f8a5be7e
[submodule "ext/spec"]
path = ext/spec
url = http://github.com/mustache/spec.git
......@@ -67,6 +67,11 @@ nose_ works great! ::
cd pystache
nosetests --with-doctest
To include tests from the mustache spec_ in your test runs: ::
git submodule init
git submodule update
Mailing List
==================
......@@ -91,3 +96,4 @@ Author
.. _Mustache: http://defunkt.github.com/mustache/
.. _mustache(5): http://mustache.github.com/mustache.5.html
.. _nose: http://somethingaboutorange.com/mrl/projects/nose/0.11.1/testing.html
.. _spec: https://github.com/mustache/spec
Subproject commit 62871926ab5789ab6c55f5a1deda359ba5f7b2fa
# coding: utf-8
"""
Tests the mustache spec test cases.
"""
import glob
import os.path
import unittest
import yaml
from pystache.renderer import Renderer
def code_constructor(loader, node):
value = loader.construct_mapping(node)
return eval(value['python'], {})
yaml.add_constructor(u'!code', code_constructor)
specs = os.path.join(os.path.dirname(__file__), '..', 'ext', 'spec', 'specs')
specs = glob.glob(os.path.join(specs, '*.yml'))
class MustacheSpec(unittest.TestCase):
pass
def buildTest(testData, spec_filename):
name = testData['name']
description = testData['desc']
test_name = "%s (%s)" % (name, spec_filename)
def test(self):
template = testData['template']
partials = testData.has_key('partials') and testData['partials'] or {}
expected = testData['expected']
data = testData['data']
renderer = Renderer(loader=partials)
actual = renderer.render(template, data).encode('utf-8')
message = """%s
Template: \"""%s\"""
Expected: %s
Actual: %s""" % (description, template, repr(expected), repr(actual))
self.assertEquals(actual, expected, message)
# The name must begin with "test" for nosetests test discovery to work.
test.__name__ = 'test: "%s"' % test_name
return test
for spec in specs:
file_name = os.path.basename(spec)
for test in yaml.load(open(spec))['tests']:
test = buildTest(test, file_name)
setattr(MustacheSpec, test.__name__, test)
# Prevent this variable from being interpreted as another test.
del(test)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment