| 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 | |
|---|
| 14 | import doctest |
|---|
| 15 | import unittest |
|---|
| 16 | |
|---|
| 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 | |
|---|
| 34 | |
|---|
| 35 | def suite(): |
|---|
| 36 | suite = unittest.TestSuite() |
|---|
| 37 | suite.addTest(doctest.DocTestSuite(Template.__module__)) |
|---|
| 38 | suite.addTest(unittest.makeSuite(ContextTestCase, 'test')) |
|---|
| 39 | return suite |
|---|
| 40 | |
|---|
| 41 | if __name__ == '__main__': |
|---|
| 42 | unittest.main(defaultTest='suite') |
|---|