comparison genshi/template/tests/base.py @ 947:0f9fe59dfa00 trunk

Add .copy() function to Context objects. Fixes #249.
author hodgestar
date Fri, 02 Sep 2011 20:20:21 +0000
parents 4675d5cf6c67
children
comparison
equal deleted inserted replaced
945:d1edb246cc61 947:0f9fe59dfa00
12 # history and logs, available at http://genshi.edgewall.org/log/. 12 # history and logs, available at http://genshi.edgewall.org/log/.
13 13
14 import doctest 14 import doctest
15 import unittest 15 import unittest
16 16
17 from genshi.template.base import Template 17 from genshi.template.base import Template, Context
18
19
20 class ContextTestCase(unittest.TestCase):
21 def test_copy(self):
22 # create a non-trivial context with some dummy
23 # frames, match templates and py:choice stacks.
24 orig_ctxt = Context(a=5, b=6)
25 orig_ctxt.push({'c': 7})
26 orig_ctxt._match_templates.append(object())
27 orig_ctxt._choice_stack.append(object())
28 ctxt = orig_ctxt.copy()
29 self.assertNotEqual(id(orig_ctxt), id(ctxt))
30 self.assertEqual(repr(orig_ctxt), repr(ctxt))
31 self.assertEqual(orig_ctxt._match_templates, ctxt._match_templates)
32 self.assertEqual(orig_ctxt._choice_stack, ctxt._choice_stack)
33
18 34
19 def suite(): 35 def suite():
20 suite = unittest.TestSuite() 36 suite = unittest.TestSuite()
21 suite.addTest(doctest.DocTestSuite(Template.__module__)) 37 suite.addTest(doctest.DocTestSuite(Template.__module__))
38 suite.addTest(unittest.makeSuite(ContextTestCase, 'test'))
22 return suite 39 return suite
23 40
24 if __name__ == '__main__': 41 if __name__ == '__main__':
25 unittest.main(defaultTest='suite') 42 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software