Changeset 1172
- Timestamp:
- Sep 2, 2011, 10:20:21 PM (12 years ago)
- Location:
- trunk/genshi/template
- Files:
-
- 2 edited
-
base.py (modified) (1 diff)
-
tests/base.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/genshi/template/base.py
r1160 r1172 247 247 def pop(self): 248 248 """Pop the top-most scope from the stack.""" 249 250 def copy(self): 251 """Create a copy of this Context object.""" 252 # required to make f_locals a dict-like object 253 # See http://genshi.edgewall.org/ticket/249 for 254 # example use case in Twisted tracebacks 255 ctxt = Context() 256 ctxt.frames.pop() # pop empty dummy context 257 ctxt.frames.extend(self.frames) 258 ctxt._match_templates.extend(self._match_templates) 259 ctxt._choice_stack.extend(self._choice_stack) 260 return ctxt 249 261 250 262 -
trunk/genshi/template/tests/base.py
r500 r1172 15 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 35 def suite(): 20 36 suite = unittest.TestSuite() 21 37 suite.addTest(doctest.DocTestSuite(Template.__module__)) 38 suite.addTest(unittest.makeSuite(ContextTestCase, 'test')) 22 39 return suite 23 40
Note: See TracChangeset
for help on using the changeset viewer.
