blob: 354afd784008e5b0d4cd67f09f9465b86dd16cd8 [file]
from mako.template import Template
import unittest
from util import result_lines
class CacheTest(unittest.TestCase):
def test_component(self):
t = Template("""
<%!
callcount = [0]
%>
<%def name="foo" cached="True">
this is foo
<%
callcount[0] += 1
%>
</%def>
${foo()}
${foo()}
${foo()}
callcount: ${callcount}
""")
assert result_lines(t.render()) == [
'this is foo',
'this is foo',
'this is foo',
'callcount: [1]',
]
def test_page(self):
t = Template("""
<%!
callcount = [0]
%>
<%page cached="True"/>
this is foo
<%
callcount[0] += 1
%>
callcount: ${callcount}
""")
t.render()
t.render()
assert result_lines(t.render()) == [
"this is foo",
"callcount: [1]"
]
if __name__ == '__main__':
unittest.main()