Mercurial > genshi > mirror
comparison genshi/template/tests/loader.py @ 699:cfe3b4f02d77 trunk
Fix for caching in template loader for templates included by templates loaded from an absolute path. Closes #193. Thanks to Waldemar Kornewald for the test case.
author | cmlenz |
---|---|
date | Thu, 27 Mar 2008 14:49:06 +0000 |
parents | 408ab81767c7 |
children | fc6d9d2a3527 |
comparison
equal
deleted
inserted
replaced
698:408ab81767c7 | 699:cfe3b4f02d77 |
---|---|
226 tmpl = loader.load(os.path.abspath(os.path.join(self.dirname, 'sub', | 226 tmpl = loader.load(os.path.abspath(os.path.join(self.dirname, 'sub', |
227 'tmpl2.html'))) | 227 'tmpl2.html'))) |
228 self.assertEqual("""<html> | 228 self.assertEqual("""<html> |
229 <div>Included from sub</div> | 229 <div>Included from sub</div> |
230 </html>""", tmpl.generate().render()) | 230 </html>""", tmpl.generate().render()) |
231 | |
232 def test_abspath_caching(self): | |
233 abspath = os.path.join(self.dirname, 'abs') | |
234 os.mkdir(abspath) | |
235 file1 = open(os.path.join(abspath, 'tmpl1.html'), 'w') | |
236 try: | |
237 file1.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> | |
238 <xi:include href="tmpl2.html" /> | |
239 </html>""") | |
240 finally: | |
241 file1.close() | |
242 | |
243 file2 = open(os.path.join(abspath, 'tmpl2.html'), 'w') | |
244 try: | |
245 file2.write("""<div>Included from abspath.</div>""") | |
246 finally: | |
247 file2.close() | |
248 | |
249 searchpath = os.path.join(self.dirname, 'searchpath') | |
250 os.mkdir(searchpath) | |
251 file3 = open(os.path.join(searchpath, 'tmpl2.html'), 'w') | |
252 try: | |
253 file3.write("""<div>Included from searchpath.</div>""") | |
254 finally: | |
255 file3.close() | |
256 | |
257 loader = TemplateLoader(searchpath) | |
258 tmpl1 = loader.load(os.path.join(abspath, 'tmpl1.html')) | |
259 self.assertEqual("""<html> | |
260 <div>Included from searchpath.</div> | |
261 </html>""", tmpl1.generate().render()) | |
262 assert 'tmpl2.html' in loader._cache | |
231 | 263 |
232 def test_load_with_default_encoding(self): | 264 def test_load_with_default_encoding(self): |
233 f = open(os.path.join(self.dirname, 'tmpl.html'), 'w') | 265 f = open(os.path.join(self.dirname, 'tmpl.html'), 'w') |
234 try: | 266 try: |
235 f.write(u'<div>\xf6</div>'.encode('iso-8859-1')) | 267 f.write(u'<div>\xf6</div>'.encode('iso-8859-1')) |