diff options
author | Simon Law <simon.law@ecometrica.com> | 2012-07-20 14:17:59 -0400 |
---|---|---|
committer | Simon Law <simon.law@ecometrica.com> | 2012-07-20 14:17:59 -0400 |
commit | 10680259b0843d3688dbae241f8abb5c366ea4c5 (patch) | |
tree | 4fb197b41babf1552f80a58639fc016edf75fa49 | |
parent | fab23c4fc12d667575064835c82146eb8f88f896 (diff) | |
download | django-wkhtmltopdf-10680259b0843d3688dbae241f8abb5c366ea4c5.tar.gz django-wkhtmltopdf-10680259b0843d3688dbae241f8abb5c366ea4c5.tar.bz2 django-wkhtmltopdf-10680259b0843d3688dbae241f8abb5c366ea4c5.zip |
test_template_to_temp_file tries to clean up after itself.
-rw-r--r-- | wkhtmltopdf/tests.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/wkhtmltopdf/tests.py b/wkhtmltopdf/tests.py index 5eb733f..0249cb5 100644 --- a/wkhtmltopdf/tests.py +++ b/wkhtmltopdf/tests.py @@ -1,13 +1,21 @@ +from __future__ import absolute_import + +import os + from django.test import TestCase -from utils import template_to_temp_file +from .utils import template_to_temp_file + class TestUtils(TestCase): def test_template_to_temp_file(self): """Should render a template to a temporary file.""" title = 'A test template.' temp_file = template_to_temp_file('sample.html', {'title': title}) - with open(temp_file, 'r') as f: - saved_content = f.read() - self.assertTrue(title in saved_content) - + try: + with open(temp_file, 'r') as f: + saved_content = f.read() + self.assertTrue(title in saved_content) + finally: + if os.path.exists(temp_file): + os.remove(temp_file) |