aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh <josh@halfnibble.com>2016-02-26 23:53:55 -0800
committerJosh <josh@halfnibble.com>2016-02-26 23:53:55 -0800
commit31e8590845bbc94c72eabea798e1c0ea3a5571d2 (patch)
tree75f504845863f148f6426dcd5974dc8c4721b2ad
parentd7bb07ad4468d738f5ba321ee730921f3886e5a3 (diff)
downloaddjango-wkhtmltopdf-31e8590845bbc94c72eabea798e1c0ea3a5571d2.tar.gz
django-wkhtmltopdf-31e8590845bbc94c72eabea798e1c0ea3a5571d2.tar.bz2
django-wkhtmltopdf-31e8590845bbc94c72eabea798e1c0ea3a5571d2.zip
Remove extraneous try/except. Revert test run script changes, but set DEBUG=False.
-rw-r--r--wkhtmltopdf/tests/run.py44
-rw-r--r--wkhtmltopdf/utils.py20
2 files changed, 24 insertions, 40 deletions
diff --git a/wkhtmltopdf/tests/run.py b/wkhtmltopdf/tests/run.py
index b969a29..e0021ab 100644
--- a/wkhtmltopdf/tests/run.py
+++ b/wkhtmltopdf/tests/run.py
@@ -9,28 +9,8 @@ DIRNAME = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.getcwd())
-def run_tests():
- # Utility function to executes tests.
- # Will be called twice. Once with DEBUG=True and once with DEBUG=False.
- try:
- django.setup()
- except AttributeError:
- pass # Django < 1.7; okay to ignore
-
-
- try:
- from django.test.runner import DiscoverRunner
- except ImportError:
- from discover_runner.runner import DiscoverRunner
-
-
- test_runner = DiscoverRunner(verbosity=1)
- failures = test_runner.run_tests(['wkhtmltopdf'])
- if failures:
- sys.exit(1)
-
settings.configure(
- DEBUG=True,
+ DEBUG=False,
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
@@ -49,14 +29,22 @@ settings.configure(
MEDIA_URL='/media/',
STATIC_ROOT=os.path.join(DIRNAME, 'static'),
STATIC_URL='/static/',
- WKHTMLTOPDF_DEBUG=True,
+ WKHTMLTOPDF_DEBUG=False,
)
-# Run tests with True debug settings (persistent temporary files).
-run_tests()
+try:
+ django.setup()
+except AttributeError:
+ pass # Django < 1.7; okay to ignore
+
+
+try:
+ from django.test.runner import DiscoverRunner
+except ImportError:
+ from discover_runner.runner import DiscoverRunner
-settings.DEBUG = False
-settings.WKHTMLTOPDF_DEBUG = False
-# Run tests with False debug settings to test temporary file delete operations.
-run_tests()
+test_runner = DiscoverRunner(verbosity=1)
+failures = test_runner.run_tests(['wkhtmltopdf'])
+if failures:
+ sys.exit(1)
diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py
index bfec068..94af5de 100644
--- a/wkhtmltopdf/utils.py
+++ b/wkhtmltopdf/utils.py
@@ -134,18 +134,14 @@ class RenderedFile(object):
def __init__(self, template, context, request=None):
debug = getattr(settings, 'WKHTMLTOPDF_DEBUG', settings.DEBUG)
- try:
- self.temporary_file = render_to_temporary_file(
- template=template,
- context=context,
- request=request,
- prefix='wkhtmltopdf', suffix='.html',
- delete=(not debug)
- )
- self.filename = self.temporary_file.name
- except:
- # In case something fails, return an empty filename string.
- self.filename = ''
+ self.temporary_file = render_to_temporary_file(
+ template=template,
+ context=context,
+ request=request,
+ prefix='wkhtmltopdf', suffix='.html',
+ delete=(not debug)
+ )
+ self.filename = self.temporary_file.name
def __del__(self):
# Always close the temporary_file on object destruction.