comparison genshi/template/tests/text.py @ 995:59a4949b4a39 stable-0.7.x

Merge r1217 from trunk (fix text template tests that were failing on Windows).
author hodgestar
date Sat, 26 Jan 2013 16:42:20 +0000
parents 1adf86694e01
children 7d4414a4a5d0
comparison
equal deleted inserted replaced
993:8e3a5fd43370 995:59a4949b4a39
92 * 2 92 * 2
93 93
94 """, tmpl.generate(items=range(3)).render(encoding=None)) 94 """, tmpl.generate(items=range(3)).render(encoding=None))
95 95
96 def test_include(self): 96 def test_include(self):
97 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'w') 97 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'wb')
98 try: 98 try:
99 file1.write("Included\n") 99 file1.write(u"Included\n".encode("utf-8"))
100 finally: 100 finally:
101 file1.close() 101 file1.close()
102 102
103 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'w') 103 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'wb')
104 try: 104 try:
105 file2.write("""----- Included data below this line ----- 105 file2.write(u"""----- Included data below this line -----
106 #include tmpl1.txt 106 #include tmpl1.txt
107 ----- Included data above this line -----""") 107 ----- Included data above this line -----""".encode("utf-8"))
108 finally: 108 finally:
109 file2.close() 109 file2.close()
110 110
111 loader = TemplateLoader([self.dirname]) 111 loader = TemplateLoader([self.dirname])
112 tmpl = loader.load('tmpl2.txt', cls=OldTextTemplate) 112 tmpl = loader.load('tmpl2.txt', cls=OldTextTemplate)
217 self.assertEqual(""" 217 self.assertEqual("""
218 42 218 42
219 """, tmpl.generate().render(encoding=None)) 219 """, tmpl.generate().render(encoding=None))
220 220
221 def test_include(self): 221 def test_include(self):
222 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'w') 222 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'wb')
223 try: 223 try:
224 file1.write("Included") 224 file1.write(u"Included".encode("utf-8"))
225 finally: 225 finally:
226 file1.close() 226 file1.close()
227 227
228 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'w') 228 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'wb')
229 try: 229 try:
230 file2.write("""----- Included data below this line ----- 230 file2.write(u"""----- Included data below this line -----
231 {% include tmpl1.txt %} 231 {% include tmpl1.txt %}
232 ----- Included data above this line -----""") 232 ----- Included data above this line -----""".encode("utf-8"))
233 finally: 233 finally:
234 file2.close() 234 file2.close()
235 235
236 loader = TemplateLoader([self.dirname]) 236 loader = TemplateLoader([self.dirname])
237 tmpl = loader.load('tmpl2.txt', cls=NewTextTemplate) 237 tmpl = loader.load('tmpl2.txt', cls=NewTextTemplate)
239 Included 239 Included
240 ----- Included data above this line -----""", 240 ----- Included data above this line -----""",
241 tmpl.generate().render(encoding=None)) 241 tmpl.generate().render(encoding=None))
242 242
243 def test_include_expr(self): 243 def test_include_expr(self):
244 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'w') 244 file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'wb')
245 try: 245 try:
246 file1.write("Included") 246 file1.write(u"Included".encode("utf-8"))
247 finally: 247 finally:
248 file1.close() 248 file1.close()
249 249
250 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'w') 250 file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'wb')
251 try: 251 try:
252 file2.write("""----- Included data below this line ----- 252 file2.write(u"""----- Included data below this line -----
253 {% include ${'%s.txt' % ('tmpl1',)} %} 253 {% include ${'%s.txt' % ('tmpl1',)} %}
254 ----- Included data above this line -----""") 254 ----- Included data above this line -----""".encode("utf-8"))
255 finally: 255 finally:
256 file2.close() 256 file2.close()
257 257
258 loader = TemplateLoader([self.dirname]) 258 loader = TemplateLoader([self.dirname])
259 tmpl = loader.load('tmpl2.txt', cls=NewTextTemplate) 259 tmpl = loader.load('tmpl2.txt', cls=NewTextTemplate)
Copyright (C) 2012-2017 Edgewall Software