diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2014-12-30 10:01:23 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-12-30 10:01:23 -0500 |
| commit | 7794b1b0348f2cb76317b40a5ec7931527501c94 (patch) | |
| tree | c99e1714ac7cefa33e9b436fcde3c6cb9730224d | |
| parent | 470028e10ea01e57ece6df3c953a309e0017d068 (diff) | |
| download | python-setuptools-git-7794b1b0348f2cb76317b40a5ec7931527501c94.tar.gz | |
Add compatibility shim for tarfile.open
| -rw-r--r-- | setuptools/tests/py26compat.py | 12 | ||||
| -rw-r--r-- | setuptools/tests/test_easy_install.py | 4 |
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) |
