1 # -*- coding: utf-8 -*-
6 Tests utilities jinja uses.
8 :copyright: (c) 2010 by the Jinja Team.
9 :license: BSD, see LICENSE for more details.
16 from jinja2 import Environment, Undefined, DebugUndefined, \
17 StrictUndefined, UndefinedError, Template, meta
18 from jinja2.utils import LRUCache
21 class LRUCacheTestCase(JinjaTestCase):
23 def test_simple(self):
31 assert 'a' in d and 'c' in d and 'd' in d and 'b' not in d
33 def test_pickleable(self):
39 for protocol in range(3):
40 copy = pickle.loads(pickle.dumps(cache, protocol))
41 assert copy.capacity == cache.capacity
42 assert copy._mapping == cache._mapping
43 assert copy._queue == cache._queue
46 class MarkupLeakTestCase(JinjaTestCase):
48 def test_markup_leaks(self):
50 for count in xrange(20):
51 for item in xrange(1000):
56 counts.add(len(gc.get_objects()))
57 assert len(counts) == 1, 'ouch, c extension seems to leak objects'
61 suite = unittest.TestSuite()
62 suite.addTest(unittest.makeSuite(LRUCacheTestCase))
64 # this test only tests the c extension
65 if not hasattr(escape, 'func_code'):
66 suite.addTest(unittest.makeSuite(MarkupLeakTestCase))