aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--setuptools/tests/py26compat.py12
-rw-r--r--setuptools/tests/test_easy_install.py4
2 files changed, 15 insertions, 1 deletions
diff --git a/setuptools/tests/py26compat.py b/setuptools/tests/py26compat.py
index d4fb891a..24e6dbe2 100644
--- a/setuptools/tests/py26compat.py
+++ b/setuptools/tests/py26compat.py
@@ -1,4 +1,6 @@
+import sys
import unittest
+import tarfile
try:
# provide skipIf for Python 2.4-2.6
@@ -12,3 +14,13 @@ except AttributeError:
return skip
return func
return skipper
+
+def _tarfile_open_ex(*args, **kwargs):
+ """
+ Extend result with an __exit__ to close the file.
+ """
+ res = tarfile.open(*args, **kwargs)
+ res.__exit__ = lambda self: self.close()
+ return res
+
+tarfile_open = _tarfile_open_ex if sys.version_info < (2,7) else tarfile.open
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 0bb4c22f..1abb82fd 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -26,6 +26,8 @@ from pkg_resources import Distribution as PRDistribution
import setuptools.tests.server
import pkg_resources
+from .py26compat import tarfile_open
+
class FakeDist(object):
def get_entry_map(self, group):
if group != 'console_scripts':
@@ -387,7 +389,7 @@ def make_trivial_sdist(dist_path, setup_py):
MemFile = StringIO
setup_py_bytes = MemFile(setup_py.encode('utf-8'))
setup_py_file.size = len(setup_py_bytes.getvalue())
- with tarfile.open(dist_path, 'w:gz') as dist:
+ with tarfile_open(dist_path, 'w:gz') as dist:
dist.addfile(setup_py_file, fileobj=setup_py_bytes)