aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-03-05 18:47:56 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-03-05 18:47:56 +0000
commit89eae3cc302909811cd269bde7a9a80ac17ab747 (patch)
tree58e274158d5378c176edde9e11b1bf64725c74a2 /test
parent876c371f4e12abf9f1126420ae261c37f4b09c57 (diff)
downloadexternal_python_mako-89eae3cc302909811cd269bde7a9a80ac17ab747.tar.gz
external_python_mako-89eae3cc302909811cd269bde7a9a80ac17ab747.tar.bz2
external_python_mako-89eae3cc302909811cd269bde7a9a80ac17ab747.zip
- Windows paths are handled correctly if a Template
is passed only an absolute filename (i.e. with c: drive etc.) and no URI - the URI is converted to a forward-slash path and module_directory is treated as a windows path. [ticket:128]
Diffstat (limited to 'test')
-rw-r--r--test/test_template.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/test_template.py b/test/test_template.py
index c738012..4b5b94a 100644
--- a/test/test_template.py
+++ b/test/test_template.py
@@ -678,6 +678,69 @@ class ModuleDirTest(TemplateTest):
os.path.join(module_base, 'subdir', 'foo', 'modtest.html.py')
)
+class FilenameToURITest(TemplateTest):
+ def test_windows_paths(self):
+ """test that windows filenames are handled appropriately by Template."""
+
+ current_path = os.path
+ import ntpath
+ os.path = ntpath
+ try:
+ class NoCompileTemplate(Template):
+ def _compile_from_file(self, path, filename):
+ self.path = path
+ return Template("foo bar").module
+
+ t1 = NoCompileTemplate(
+ filename="c:\\foo\\template.html",
+ module_directory="c:\\modules\\")
+
+ eq_(t1.uri, "/foo/template.html")
+ eq_(t1.path, "c:\\modules\\foo\\template.html.py")
+
+ t1 = NoCompileTemplate(
+ filename="c:\\path\\to\\templates\\template.html",
+ uri = "/bar/template.html",
+ module_directory="c:\\modules\\")
+
+ eq_(t1.uri, "/bar/template.html")
+ eq_(t1.path, "c:\\modules\\bar\\template.html.py")
+
+ finally:
+ os.path = current_path
+
+ def test_posix_paths(self):
+ """test that posixs filenames are handled appropriately by Template."""
+
+ current_path = os.path
+ import posixpath
+ os.path = posixpath
+ try:
+ class NoCompileTemplate(Template):
+ def _compile_from_file(self, path, filename):
+ self.path = path
+ return Template("foo bar").module
+
+ t1 = NoCompileTemplate(
+ filename="/var/www/htdocs/includes/template.html",
+ module_directory="/var/lib/modules")
+
+ eq_(t1.uri, "/var/www/htdocs/includes/template.html")
+ eq_(t1.path, "/var/lib/modules/var/www/htdocs/includes/template.html.py")
+
+ t1 = NoCompileTemplate(
+ filename="/var/www/htdocs/includes/template.html",
+ uri = "/bar/template.html",
+ module_directory="/var/lib/modules")
+
+ eq_(t1.uri, "/bar/template.html")
+ eq_(t1.path, "/var/lib/modules/bar/template.html.py")
+
+ finally:
+ os.path = current_path
+
+
+
class ModuleTemplateTest(TemplateTest):
def test_module_roundtrip(self):
lookup = TemplateLookup()