From 024440569c1534767e60ad9e4e7a6b1ba60deb86 Mon Sep 17 00:00:00 2001 From: Aaron Sierra Date: Tue, 10 Mar 2020 18:24:57 -0500 Subject: [PATCH] tests: Use native zipfile module Instead of using an external utility (/usr/bin/zip) and a subprocess call, use Python's own zipfile module to create temporary zip file. --- tests.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests.py b/tests.py index 980e671..6b9a12d 100644 --- a/tests.py +++ b/tests.py @@ -26,7 +26,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import os, unittest, tempfile, random, string, subprocess, sys +import os, unittest, tempfile, random, string, sys +import zipfile from libarchive import is_archive_name, is_archive from libarchive.zip import is_zipfile, ZipFile, ZipEntry @@ -34,7 +35,6 @@ from libarchive.zip import is_zipfile, ZipFile, ZipEntry PY3 = sys.version_info[0] == 3 TMPDIR = tempfile.mkdtemp(suffix='.python-libarchive') -ZIPCMD = '/usr/bin/zip' ZIPFILE = 'test.zip' ZIPPATH = os.path.join(TMPDIR, ZIPFILE) @@ -54,13 +54,10 @@ def make_temp_files(): def make_temp_archive(): - if not os.access(ZIPCMD, os.X_OK): - raise AssertionError('Cannot execute %s.' % ZIPCMD) - cmd = [ZIPCMD, ZIPFILE] make_temp_files() - cmd.extend(FILENAMES) - os.chdir(TMPDIR) - subprocess.call(cmd, stdout=subprocess.PIPE) + with zipfile.ZipFile(ZIPPATH, mode="w") as z: + for name in FILENAMES: + z.write(os.path.join(TMPDIR, name), arcname=name) class TestIsArchiveName(unittest.TestCase):