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)
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)
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"
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"