Edgewall Software

source: trunk/genshi/template/tests/base.py

Last change on this file was 1172, checked in by hodgestar, 12 years ago

Add .copy() function to Context objects. Fixes #249.

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2006-2007 Edgewall Software
4# All rights reserved.
5#
6# This software is licensed as described in the file COPYING, which
7# you should have received as part of this distribution. The terms
8# are also available at http://genshi.edgewall.org/wiki/License.
9#
10# This software consists of voluntary contributions made by many
11# individuals. For the exact contribution history, see the revision
12# history and logs, available at http://genshi.edgewall.org/log/.
13
14import doctest
15import unittest
16
17from genshi.template.base import Template, Context
18
19
20class 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
34
35def suite():
36    suite = unittest.TestSuite()
37    suite.addTest(doctest.DocTestSuite(Template.__module__))
38    suite.addTest(unittest.makeSuite(ContextTestCase, 'test'))
39    return suite
40
41if __name__ == '__main__':
42    unittest.main(defaultTest='suite')
Note: See TracBrowser for help on using the repository browser.