Mercurial > genshi > genshi-test
annotate genshi/template/tests/loader.py @ 935:705727288d7e
Merge r1143 from py3k:
add support for python 3 to remaining genshi.template components:
* minor changes to track encoding=None API change in core genshi modules.
* genshi/template/directives:
* slightly odd syntax changes to make the 2to3 .next() fixer pick up *stream.next()
* minor test fix for change in behaviour of division (/) in Python 3.
* genshi/template/loader:
* add 'b' to file modes to ensure it's loaded as bytes in Python 3.
* use not isinstance(s, unicode) instead of isinstance(s, str) since the former is correctly converted by 2to3.
author | hodgestar |
---|---|
date | Fri, 18 Mar 2011 09:17:52 +0000 |
parents | 85e4678337cf |
children |
rev | line source |
---|---|
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
2 # |
897 | 3 # Copyright (C) 2006-2010 Edgewall Software |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
5 # |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
8 # are also available at http://genshi.edgewall.org/wiki/License. |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
9 # |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
12 # history and logs, available at http://genshi.edgewall.org/log/. |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
13 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
14 import doctest |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
15 import os |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
16 import shutil |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
17 import tempfile |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
18 import unittest |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
19 |
439
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
20 from genshi.core import TEXT |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
21 from genshi.template.loader import TemplateLoader |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
22 from genshi.template.markup import MarkupTemplate |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
23 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
24 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
25 class TemplateLoaderTestCase(unittest.TestCase): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
26 """Tests for the template loader.""" |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
27 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
28 def setUp(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
29 self.dirname = tempfile.mkdtemp(suffix='markup_test') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
30 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
31 def tearDown(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
32 shutil.rmtree(self.dirname) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
33 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
34 def test_search_path_empty(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
35 loader = TemplateLoader() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
36 self.assertEqual([], loader.search_path) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
37 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
38 def test_search_path_as_string(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
39 loader = TemplateLoader(self.dirname) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
40 self.assertEqual([self.dirname], loader.search_path) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
41 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
42 def test_relative_include_samedir(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
43 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
44 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
45 file1.write("""<div>Included</div>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
46 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
47 file1.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
48 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
49 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
50 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
51 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
52 <xi:include href="tmpl1.html" /> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
53 </html>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
54 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
55 file2.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
56 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
57 loader = TemplateLoader([self.dirname]) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
58 tmpl = loader.load('tmpl2.html') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
59 self.assertEqual("""<html> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
60 <div>Included</div> |
865 | 61 </html>""", tmpl.generate().render(encoding=None)) |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
62 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
63 def test_relative_include_subdir(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
64 os.mkdir(os.path.join(self.dirname, 'sub')) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
65 file1 = open(os.path.join(self.dirname, 'sub', 'tmpl1.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
66 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
67 file1.write("""<div>Included</div>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
68 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
69 file1.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
70 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
71 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
72 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
73 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
74 <xi:include href="sub/tmpl1.html" /> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
75 </html>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
76 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
77 file2.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
78 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
79 loader = TemplateLoader([self.dirname]) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
80 tmpl = loader.load('tmpl2.html') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
81 self.assertEqual("""<html> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
82 <div>Included</div> |
865 | 83 </html>""", tmpl.generate().render(encoding=None)) |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
84 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
85 def test_relative_include_parentdir(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
86 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
87 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
88 file1.write("""<div>Included</div>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
89 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
90 file1.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
91 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
92 os.mkdir(os.path.join(self.dirname, 'sub')) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
93 file2 = open(os.path.join(self.dirname, 'sub', 'tmpl2.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
94 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
95 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
96 <xi:include href="../tmpl1.html" /> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
97 </html>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
98 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
99 file2.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
100 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
101 loader = TemplateLoader([self.dirname]) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
102 tmpl = loader.load('sub/tmpl2.html') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
103 self.assertEqual("""<html> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
104 <div>Included</div> |
865 | 105 </html>""", tmpl.generate().render(encoding=None)) |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
106 |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
107 def test_relative_include_samesubdir(self): |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
108 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
109 try: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
110 file1.write("""<div>Included tmpl1.html</div>""") |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
111 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
112 file1.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
113 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
114 os.mkdir(os.path.join(self.dirname, 'sub')) |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
115 file2 = open(os.path.join(self.dirname, 'sub', 'tmpl1.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
116 try: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
117 file2.write("""<div>Included sub/tmpl1.html</div>""") |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
118 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
119 file2.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
120 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
121 file3 = open(os.path.join(self.dirname, 'sub', 'tmpl2.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
122 try: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
123 file3.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
124 <xi:include href="tmpl1.html" /> |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
125 </html>""") |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
126 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
127 file3.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
128 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
129 loader = TemplateLoader([self.dirname]) |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
130 tmpl = loader.load('sub/tmpl2.html') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
131 self.assertEqual("""<html> |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
132 <div>Included sub/tmpl1.html</div> |
865 | 133 </html>""", tmpl.generate().render(encoding=None)) |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
134 |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
135 def test_relative_include_without_search_path(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
136 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
137 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
138 file1.write("""<div>Included</div>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
139 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
140 file1.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
141 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
142 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
143 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
144 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
145 <xi:include href="tmpl1.html" /> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
146 </html>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
147 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
148 file2.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
149 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
150 loader = TemplateLoader() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
151 tmpl = loader.load(os.path.join(self.dirname, 'tmpl2.html')) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
152 self.assertEqual("""<html> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
153 <div>Included</div> |
865 | 154 </html>""", tmpl.generate().render(encoding=None)) |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
155 |
876
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
156 def test_relative_include_without_loader(self): |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
157 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
158 try: |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
159 file1.write("""<div>Included</div>""") |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
160 finally: |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
161 file1.close() |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
162 |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
163 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
164 try: |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
165 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
166 <xi:include href="tmpl1.html" /> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
167 </html>""") |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
168 finally: |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
169 file2.close() |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
170 |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
171 tmpl = MarkupTemplate("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
172 <xi:include href="tmpl1.html" /> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
173 </html>""", os.path.join(self.dirname, 'tmpl2.html'), 'tmpl2.html') |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
174 self.assertEqual("""<html> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
175 <div>Included</div> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
176 </html>""", tmpl.generate().render(encoding=None)) |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
177 |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
178 def test_relative_include_without_loader_relative(self): |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
179 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
180 try: |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
181 file1.write("""<div>Included</div>""") |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
182 finally: |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
183 file1.close() |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
184 |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
185 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
186 try: |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
187 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
188 <xi:include href="tmpl1.html" /> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
189 </html>""") |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
190 finally: |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
191 file2.close() |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
192 |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
193 tmpl = MarkupTemplate("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
194 <xi:include href="tmpl1.html" /> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
195 </html>""", filename=os.path.join(self.dirname, 'tmpl2.html')) |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
196 self.assertEqual("""<html> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
197 <div>Included</div> |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
198 </html>""", tmpl.generate().render(encoding=None)) |
52d7d6b7b6c1
Templates instantiated without a loader now get an implicit loader based on their file path, or the current directory as a fallback. Closes #320.
cmlenz
parents:
865
diff
changeset
|
199 |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
200 def test_relative_include_without_search_path_nested(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
201 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
202 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
203 file1.write("""<div>Included</div>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
204 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
205 file1.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
206 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
207 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
208 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
209 file2.write("""<div xmlns:xi="http://www.w3.org/2001/XInclude"> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
210 <xi:include href="tmpl1.html" /> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
211 </div>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
212 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
213 file2.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
214 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
215 file3 = open(os.path.join(self.dirname, 'tmpl3.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
216 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
217 file3.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
218 <xi:include href="tmpl2.html" /> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
219 </html>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
220 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
221 file3.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
222 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
223 loader = TemplateLoader() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
224 tmpl = loader.load(os.path.join(self.dirname, 'tmpl3.html')) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
225 self.assertEqual("""<html> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
226 <div> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
227 <div>Included</div> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
228 </div> |
865 | 229 </html>""", tmpl.generate().render(encoding=None)) |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
230 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
231 def test_relative_include_from_inmemory_template(self): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
232 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
233 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
234 file1.write("""<div>Included</div>""") |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
235 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
236 file1.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
237 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
238 loader = TemplateLoader([self.dirname]) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
239 tmpl2 = MarkupTemplate("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
240 <xi:include href="../tmpl1.html" /> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
241 </html>""", filename='subdir/tmpl2.html', loader=loader) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
242 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
243 self.assertEqual("""<html> |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
244 <div>Included</div> |
865 | 245 </html>""", tmpl2.generate().render(encoding=None)) |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
246 |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
247 def test_relative_absolute_template_preferred(self): |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
248 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
249 try: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
250 file1.write("""<div>Included</div>""") |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
251 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
252 file1.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
253 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
254 os.mkdir(os.path.join(self.dirname, 'sub')) |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
255 file2 = open(os.path.join(self.dirname, 'sub', 'tmpl1.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
256 try: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
257 file2.write("""<div>Included from sub</div>""") |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
258 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
259 file2.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
260 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
261 file3 = open(os.path.join(self.dirname, 'sub', 'tmpl2.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
262 try: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
263 file3.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
264 <xi:include href="tmpl1.html" /> |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
265 </html>""") |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
266 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
267 file3.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
268 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
269 loader = TemplateLoader() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
270 tmpl = loader.load(os.path.abspath(os.path.join(self.dirname, 'sub', |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
271 'tmpl2.html'))) |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
272 self.assertEqual("""<html> |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
273 <div>Included from sub</div> |
865 | 274 </html>""", tmpl.generate().render(encoding=None)) |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
275 |
699
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
276 def test_abspath_caching(self): |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
277 abspath = os.path.join(self.dirname, 'abs') |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
278 os.mkdir(abspath) |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
279 file1 = open(os.path.join(abspath, 'tmpl1.html'), 'w') |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
280 try: |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
281 file1.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
282 <xi:include href="tmpl2.html" /> |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
283 </html>""") |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
284 finally: |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
285 file1.close() |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
286 |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
287 file2 = open(os.path.join(abspath, 'tmpl2.html'), 'w') |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
288 try: |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
289 file2.write("""<div>Included from abspath.</div>""") |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
290 finally: |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
291 file2.close() |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
292 |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
293 searchpath = os.path.join(self.dirname, 'searchpath') |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
294 os.mkdir(searchpath) |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
295 file3 = open(os.path.join(searchpath, 'tmpl2.html'), 'w') |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
296 try: |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
297 file3.write("""<div>Included from searchpath.</div>""") |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
298 finally: |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
299 file3.close() |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
300 |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
301 loader = TemplateLoader(searchpath) |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
302 tmpl1 = loader.load(os.path.join(abspath, 'tmpl1.html')) |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
303 self.assertEqual("""<html> |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
304 <div>Included from searchpath.</div> |
865 | 305 </html>""", tmpl1.generate().render(encoding=None)) |
699
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
306 assert 'tmpl2.html' in loader._cache |
1f08da62e8fd
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.
cmlenz
parents:
698
diff
changeset
|
307 |
769
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
308 def test_abspath_include_caching_without_search_path(self): |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
309 file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
310 try: |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
311 file1.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
312 <xi:include href="tmpl2.html" /> |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
313 </html>""") |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
314 finally: |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
315 file1.close() |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
316 |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
317 file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
318 try: |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
319 file2.write("""<div>Included</div>""") |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
320 finally: |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
321 file2.close() |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
322 |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
323 os.mkdir(os.path.join(self.dirname, 'sub')) |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
324 file3 = open(os.path.join(self.dirname, 'sub', 'tmpl1.html'), 'w') |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
325 try: |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
326 file3.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
327 <xi:include href="tmpl2.html" /> |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
328 </html>""") |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
329 finally: |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
330 file3.close() |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
331 |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
332 file4 = open(os.path.join(self.dirname, 'sub', 'tmpl2.html'), 'w') |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
333 try: |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
334 file4.write("""<div>Included from sub</div>""") |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
335 finally: |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
336 file4.close() |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
337 |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
338 loader = TemplateLoader() |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
339 tmpl1 = loader.load(os.path.join(self.dirname, 'tmpl1.html')) |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
340 self.assertEqual("""<html> |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
341 <div>Included</div> |
865 | 342 </html>""", tmpl1.generate().render(encoding=None)) |
769
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
343 tmpl2 = loader.load(os.path.join(self.dirname, 'sub', 'tmpl1.html')) |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
344 self.assertEqual("""<html> |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
345 <div>Included from sub</div> |
865 | 346 </html>""", tmpl2.generate().render(encoding=None)) |
769
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
347 assert 'tmpl2.html' not in loader._cache |
834e8fd2d822
Includes from templates loaded via an absolute path now include the correct file in nested directories as long if no search path has been configured. Closes #240.
cmlenz
parents:
714
diff
changeset
|
348 |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
349 def test_load_with_default_encoding(self): |
935 | 350 f = open(os.path.join(self.dirname, 'tmpl.html'), 'wb') |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
351 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
352 f.write(u'<div>\xf6</div>'.encode('iso-8859-1')) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
353 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
354 f.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
355 loader = TemplateLoader([self.dirname], default_encoding='iso-8859-1') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
356 loader.load('tmpl.html') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
357 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
358 def test_load_with_explicit_encoding(self): |
935 | 359 f = open(os.path.join(self.dirname, 'tmpl.html'), 'wb') |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
360 try: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
361 f.write(u'<div>\xf6</div>'.encode('iso-8859-1')) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
362 finally: |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
363 f.close() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
364 loader = TemplateLoader([self.dirname], default_encoding='utf-8') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
365 loader.load('tmpl.html', encoding='iso-8859-1') |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
366 |
439
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
367 def test_load_with_callback(self): |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
368 fileobj = open(os.path.join(self.dirname, 'tmpl.html'), 'w') |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
369 try: |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
370 fileobj.write("""<html> |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
371 <p>Hello</p> |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
372 </html>""") |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
373 finally: |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
374 fileobj.close() |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
375 |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
376 def template_loaded(template): |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
377 def my_filter(stream, ctxt): |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
378 for kind, data, pos in stream: |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
379 if kind is TEXT and data.strip(): |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
380 data = ', '.join([data, data.lower()]) |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
381 yield kind, data, pos |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
382 template.filters.insert(0, my_filter) |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
383 |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
384 loader = TemplateLoader([self.dirname], callback=template_loaded) |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
385 tmpl = loader.load('tmpl.html') |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
386 self.assertEqual("""<html> |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
387 <p>Hello, hello</p> |
865 | 388 </html>""", tmpl.generate().render(encoding=None)) |
439
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
389 |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
390 # Make sure the filter is only added once |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
391 tmpl = loader.load('tmpl.html') |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
392 self.assertEqual("""<html> |
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
393 <p>Hello, hello</p> |
865 | 394 </html>""", tmpl.generate().render(encoding=None)) |
439
b84c11a49ad2
Add support for adding custom template filters by passing a custom callback function to the `TemplateLoader`. Closes #89 (see added unit test).
cmlenz
parents:
336
diff
changeset
|
395 |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
396 def test_prefix_delegation_to_directories(self): |
698
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
397 """ |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
398 Test prefix delegation with the following layout: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
399 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
400 templates/foo.html |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
401 sub1/templates/tmpl1.html |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
402 sub2/templates/tmpl2.html |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
403 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
404 Where sub1 and sub2 are prefixes, and both tmpl1.html and tmpl2.html |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
405 incldue foo.html. |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
406 """ |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
407 dir1 = os.path.join(self.dirname, 'templates') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
408 os.mkdir(dir1) |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
409 file1 = open(os.path.join(dir1, 'foo.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
410 try: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
411 file1.write("""<div>Included foo</div>""") |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
412 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
413 file1.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
414 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
415 dir2 = os.path.join(self.dirname, 'sub1', 'templates') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
416 os.makedirs(dir2) |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
417 file2 = open(os.path.join(dir2, 'tmpl1.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
418 try: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
419 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
698
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
420 <xi:include href="../foo.html" /> from sub1 |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
421 </html>""") |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
422 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
423 file2.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
424 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
425 dir3 = os.path.join(self.dirname, 'sub2', 'templates') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
426 os.makedirs(dir3) |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
427 file3 = open(os.path.join(dir3, 'tmpl2.html'), 'w') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
428 try: |
698
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
429 file3.write("""<div>tmpl2</div>""") |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
430 finally: |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
431 file3.close() |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
432 |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
433 loader = TemplateLoader([dir1, TemplateLoader.prefixed( |
714
7e6496bde18a
The `Template` class and its subclasses, as well as the interpolation API, now take an `filepath` parameter instead of `basedir`. Closes #207. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
699
diff
changeset
|
434 sub1 = dir2, |
7e6496bde18a
The `Template` class and its subclasses, as well as the interpolation API, now take an `filepath` parameter instead of `basedir`. Closes #207. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
699
diff
changeset
|
435 sub2 = dir3 |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
436 )]) |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
437 tmpl = loader.load('sub1/tmpl1.html') |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
438 self.assertEqual("""<html> |
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
439 <div>Included foo</div> from sub1 |
865 | 440 </html>""", tmpl.generate().render(encoding=None)) |
696
87b8e23610d4
More flexible template loader allowing for loading from package data and dispatching to different template directories based on path prefix. Can be easily extended for using custom template loading. Closes #182.
cmlenz
parents:
439
diff
changeset
|
441 |
698
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
442 def test_prefix_delegation_to_directories_with_subdirs(self): |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
443 """ |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
444 Test prefix delegation with the following layout: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
445 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
446 templates/foo.html |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
447 sub1/templates/tmpl1.html |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
448 sub1/templates/tmpl2.html |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
449 sub1/templates/bar/tmpl3.html |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
450 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
451 Where sub1 is a prefix, and tmpl1.html includes all the others. |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
452 """ |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
453 dir1 = os.path.join(self.dirname, 'templates') |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
454 os.mkdir(dir1) |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
455 file1 = open(os.path.join(dir1, 'foo.html'), 'w') |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
456 try: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
457 file1.write("""<div>Included foo</div>""") |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
458 finally: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
459 file1.close() |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
460 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
461 dir2 = os.path.join(self.dirname, 'sub1', 'templates') |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
462 os.makedirs(dir2) |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
463 file2 = open(os.path.join(dir2, 'tmpl1.html'), 'w') |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
464 try: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
465 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
466 <xi:include href="../foo.html" /> from sub1 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
467 <xi:include href="tmpl2.html" /> from sub1 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
468 <xi:include href="bar/tmpl3.html" /> from sub1 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
469 </html>""") |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
470 finally: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
471 file2.close() |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
472 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
473 file3 = open(os.path.join(dir2, 'tmpl2.html'), 'w') |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
474 try: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
475 file3.write("""<div>tmpl2</div>""") |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
476 finally: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
477 file3.close() |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
478 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
479 dir3 = os.path.join(self.dirname, 'sub1', 'templates', 'bar') |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
480 os.makedirs(dir3) |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
481 file4 = open(os.path.join(dir3, 'tmpl3.html'), 'w') |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
482 try: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
483 file4.write("""<div>bar/tmpl3</div>""") |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
484 finally: |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
485 file4.close() |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
486 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
487 loader = TemplateLoader([dir1, TemplateLoader.prefixed( |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
488 sub1 = os.path.join(dir2), |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
489 sub2 = os.path.join(dir3) |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
490 )]) |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
491 tmpl = loader.load('sub1/tmpl1.html') |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
492 self.assertEqual("""<html> |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
493 <div>Included foo</div> from sub1 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
494 <div>tmpl2</div> from sub1 |
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
495 <div>bar/tmpl3</div> from sub1 |
865 | 496 </html>""", tmpl.generate().render(encoding=None)) |
698
654e1d1b3953
Fix for prefix-dispatched template loading. Closes #206. Thanks to Waldemar Kornewald for the patch.
cmlenz
parents:
696
diff
changeset
|
497 |
336
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
498 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
499 def suite(): |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
500 suite = unittest.TestSuite() |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
501 suite.addTest(doctest.DocTestSuite(TemplateLoader.__module__)) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
502 suite.addTest(unittest.makeSuite(TemplateLoaderTestCase, 'test')) |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
503 return suite |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
504 |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
505 if __name__ == '__main__': |
5f2c7782cd8a
Refactoring: `genshi.template` is now a package, it was getting way to crowded in that file.
cmlenz
parents:
diff
changeset
|
506 unittest.main(defaultTest='suite') |