diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-16 16:13:51 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-16 16:13:51 -0500 |
commit | 9e134cb7767f54763431a59467bfb92d0ef8e0c9 (patch) | |
tree | d5b77c7c49654161ffb4df2543f658eca8738d91 /test/test_template.py | |
parent | aeb822d9b4ec8e5b88901d0ff4fef9a062f743f6 (diff) | |
download | mako-9e134cb7767f54763431a59467bfb92d0ef8e0c9.tar.gz |
- [feature] Added module_writer argument to Template,
TemplateLookup, allows a callable to be passed which
takes over the writing of the template's module source
file, so that special environment-specific steps
can be taken. [ticket:181]
Diffstat (limited to 'test/test_template.py')
-rw-r--r-- | test/test_template.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_template.py b/test/test_template.py index ddab16e..769af02 100644 --- a/test/test_template.py +++ b/test/test_template.py @@ -841,6 +841,10 @@ for utf8 in (True, False): del _do_test class ModuleDirTest(TemplateTest): + def tearDown(self): + import shutil + shutil.rmtree(module_base, True) + def test_basic(self): t = self._file_template("modtest.html") t2 = self._file_template('subdir/modtest.html') @@ -874,6 +878,22 @@ class ModuleDirTest(TemplateTest): os.path.join(module_base, 'subdir', 'foo', 'modtest.html.py') ) + def test_custom_writer(self): + canary = [] + def write_module(source, outputpath): + with open(outputpath, 'wb') as f: + canary.append(outputpath) + f.write(source) + lookup = TemplateLookup(template_base, module_writer=write_module, + module_directory=module_base) + t = lookup.get_template('/modtest.html') + t2 = lookup.get_template('/subdir/modtest.html') + eq_( + canary, + [os.path.join(module_base, "modtest.html.py"), + os.path.join(module_base, "subdir/modtest.html.py")] + ) + class FilenameToURITest(TemplateTest): def test_windows_paths(self): """test that windows filenames are handled appropriately by Template.""" @@ -954,6 +974,7 @@ class FilenameToURITest(TemplateTest): t = Template("test", uri="foo/bar/../../foo.html") eq_(t.uri, "foo/bar/../../foo.html") + class ModuleTemplateTest(TemplateTest): def test_module_roundtrip(self): lookup = TemplateLookup() |