Mercurial > genshi > genshi-test
comparison genshi/template/tests/text.py @ 500:0742f421caba experimental-inline
Merged revisions 487-603 via svnmerge from
http://svn.edgewall.org/repos/genshi/trunk
author | cmlenz |
---|---|
date | Fri, 01 Jun 2007 17:21:47 +0000 |
parents | 55cf81951686 |
children | 1837f39efd6f |
comparison
equal
deleted
inserted
replaced
499:869b7885a516 | 500:0742f421caba |
---|---|
10 # This software consists of voluntary contributions made by many | 10 # This software consists of voluntary contributions made by many |
11 # individuals. For the exact contribution history, see the revision | 11 # individuals. For the exact contribution history, see the revision |
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 os | |
16 import shutil | |
17 import tempfile | |
15 import unittest | 18 import unittest |
16 | 19 |
20 from genshi.template.loader import TemplateLoader | |
17 from genshi.template.text import TextTemplate | 21 from genshi.template.text import TextTemplate |
18 | 22 |
19 | 23 |
20 class TextTemplateTestCase(unittest.TestCase): | 24 class TextTemplateTestCase(unittest.TestCase): |
21 """Tests for text template processing.""" | 25 """Tests for text template processing.""" |
26 | |
27 def setUp(self): | |
28 self.dirname = tempfile.mkdtemp(suffix='markup_test') | |
29 | |
30 def tearDown(self): | |
31 shutil.rmtree(self.dirname) | |
22 | 32 |
23 def test_escaping(self): | 33 def test_escaping(self): |
24 tmpl = TextTemplate('\\#escaped') | 34 tmpl = TextTemplate('\\#escaped') |
25 self.assertEqual('#escaped', str(tmpl.generate())) | 35 self.assertEqual('#escaped', str(tmpl.generate())) |
26 | 36 |
35 def test_end_with_args(self): | 45 def test_end_with_args(self): |
36 tmpl = TextTemplate(""" | 46 tmpl = TextTemplate(""" |
37 #if foo | 47 #if foo |
38 bar | 48 bar |
39 #end 'if foo'""") | 49 #end 'if foo'""") |
40 self.assertEqual('\n', str(tmpl.generate())) | 50 self.assertEqual('\n', str(tmpl.generate(foo=False))) |
41 | 51 |
42 def test_latin1_encoded(self): | 52 def test_latin1_encoded(self): |
43 text = u'$foo\xf6$bar'.encode('iso-8859-1') | 53 text = u'$foo\xf6$bar'.encode('iso-8859-1') |
44 tmpl = TextTemplate(text, encoding='iso-8859-1') | 54 tmpl = TextTemplate(text, encoding='iso-8859-1') |
45 self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y'))) | 55 self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y'))) |
72 | 82 |
73 * 2 | 83 * 2 |
74 | 84 |
75 """, tmpl.generate(items=range(3)).render('text')) | 85 """, tmpl.generate(items=range(3)).render('text')) |
76 | 86 |
87 def test_include(self): | |
88 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'w') | |
89 try: | |
90 file1.write("Included\n") | |
91 finally: | |
92 file1.close() | |
77 | 93 |
94 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'w') | |
95 try: | |
96 file2.write("""----- Included data below this line ----- | |
97 #include tmpl1.txt | |
98 ----- Included data above this line -----""") | |
99 finally: | |
100 file2.close() | |
101 | |
102 loader = TemplateLoader([self.dirname]) | |
103 tmpl = loader.load('tmpl2.txt', cls=TextTemplate) | |
104 self.assertEqual("""----- Included data below this line ----- | |
105 Included | |
106 ----- Included data above this line -----""", | |
107 tmpl.generate().render()) | |
108 | |
78 def suite(): | 109 def suite(): |
79 suite = unittest.TestSuite() | 110 suite = unittest.TestSuite() |
80 suite.addTest(doctest.DocTestSuite(TextTemplate.__module__)) | 111 suite.addTest(doctest.DocTestSuite(TextTemplate.__module__)) |
81 suite.addTest(unittest.makeSuite(TextTemplateTestCase, 'test')) | 112 suite.addTest(unittest.makeSuite(TextTemplateTestCase, 'test')) |
82 return suite | 113 return suite |