예제 #1
0
 def test_push(self):
     ctx = stencil.Context({'a': 1})
     self.assertEqual(ctx['a'], 1)
     self.assertIsNone(ctx['None'])
     with ctx:
         ctx.update({'a': 2})
         self.assertEqual(ctx['a'], 2)
     self.assertEqual(ctx['a'], 1)
예제 #2
0
    def assert_output(self, base):
        try:
            t = self.loader.load('%s.tpl' % base)
        except:
            assert False, '[%s]\n%s' % (base, ''.join(traceback.format_exc()))

        out = self.read_text_data(base)
        data = self.read_json_data(base)

        c = stencil.Context(data)
        result = t.render(c)

        assert result == out, 'Mismatched output for %r\n%r\n%r' % (base, out,
                                                                    result)
예제 #3
0
filters = {
    'title': unicode.title,
}

loader = stencil.TemplateLoader(['tmpl/'])

for fn in sorted(glob.glob('tmpl/*.tpl')):
    print fn,
    base, ext = os.path.splitext(fn)

    try:
        t = loader.load(os.path.basename(fn))
    except:
        import traceback
        traceback.print_exc()
        print "FAIL"
        continue

    with open(base + '.out', 'r') as fin:
        out = fin.read()

    with open(base + '.json', 'r') as fin:
        data = json.load(fin)

    c = stencil.Context(data, filters)
    result = t.render(c)

    assert result == out, "Mismatched output for %r\n%r\n%r" % (fn, out,
                                                                result)
    print "OK"
예제 #4
0
파일: test.py 프로젝트: luzfcb/stencil
stencil.FILTERS.update({
    'title': unicode.title,
})

loader = stencil.TemplateLoader(['tmpl/'])

for fn in sorted(glob.glob('tmpl/*.tpl')):
    print fn,
    base, ext = os.path.splitext(fn)

    try:
        t = loader.load(os.path.basename(fn))
    except:
        import traceback
        traceback.print_exc()
        print "FAIL"
        continue

    with open(base + '.out', 'r') as fin:
        out = fin.read()

    with open(base + '.json', 'r') as fin:
        data = json.load(fin)

    c = stencil.Context(data)
    result = t.render(c)

    assert result == out, "Mismatched output for %r\n%r\n%r" % (fn, out,
                                                                result)
    print "OK"