diff --git a/ckan/tests/helpers.py b/ckan/tests/helpers.py index c0e7e2752f5..c1bb355abd7 100644 --- a/ckan/tests/helpers.py +++ b/ckan/tests/helpers.py @@ -27,7 +27,6 @@ import logging import os import re -import tempfile import webtest import nose.tools @@ -666,27 +665,3 @@ def clear(self): Clear all captured log messages. ''' self.messages = collections.defaultdict(list) - - -@contextlib.contextmanager -def temp_file(*args, **kwargs): - u''' - Context manager that provides a temporary file. - - The temporary file is named and open. It is automatically deleted - when the context manager is left if it still exists at that point. - - Any arguments are passed on to - :py:func:`tempfile.NamedTemporaryFile`. - ''' - kwargs['delete'] = False - f = tempfile.NamedTemporaryFile(*args, **kwargs) - try: - yield f - finally: - f.close() - try: - os.remove(f.name) - except OSError as e: - if e.errno != errno.ENOENT: - raise diff --git a/ckan/tests/lib/test_cli.py b/ckan/tests/lib/test_cli.py index cd6e2e03b9c..7d360284082 100644 --- a/ckan/tests/lib/test_cli.py +++ b/ckan/tests/lib/test_cli.py @@ -6,6 +6,7 @@ import os.path from StringIO import StringIO import sys +import tempfile from nose.tools import (assert_raises, eq_ as eq, ok_ as ok, assert_in, assert_not_in, assert_not_equal as neq, assert_false as nok) @@ -320,7 +321,7 @@ def test_worker_default_queue(self): ''' Test ``jobs worker`` with the default queue. ''' - with helpers.temp_file() as f: + with tempfile.NamedTemporaryFile(delete=False) as f: self.enqueue(os.remove, args=[f.name]) paster(u'jobs', u'worker', u'--burst') all_jobs = self.all_jobs() @@ -331,8 +332,8 @@ def test_worker_specific_queues(self): ''' Test ``jobs worker`` with specific queues. ''' - with helpers.temp_file() as f: - with helpers.temp_file() as g: + with tempfile.NamedTemporaryFile(delete=False) as f: + with tempfile.NamedTemporaryFile(delete=False) as g: job1 = self.enqueue() job2 = self.enqueue(queue=u'q2') self.enqueue(os.remove, args=[f.name], queue=u'q3')