Skip to content

Commit 0244405

Browse files
author
Aaron Sierra
committed
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.
1 parent a9aaf24 commit 0244405

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

tests.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2727
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
import os, unittest, tempfile, random, string, subprocess, sys
29+
import os, unittest, tempfile, random, string, sys
30+
import zipfile
3031

3132
from libarchive import is_archive_name, is_archive
3233
from libarchive.zip import is_zipfile, ZipFile, ZipEntry
3334

3435
PY3 = sys.version_info[0] == 3
3536

3637
TMPDIR = tempfile.mkdtemp(suffix='.python-libarchive')
37-
ZIPCMD = '/usr/bin/zip'
3838
ZIPFILE = 'test.zip'
3939
ZIPPATH = os.path.join(TMPDIR, ZIPFILE)
4040

@@ -54,13 +54,10 @@ def make_temp_files():
5454

5555

5656
def make_temp_archive():
57-
if not os.access(ZIPCMD, os.X_OK):
58-
raise AssertionError('Cannot execute %s.' % ZIPCMD)
59-
cmd = [ZIPCMD, ZIPFILE]
6057
make_temp_files()
61-
cmd.extend(FILENAMES)
62-
os.chdir(TMPDIR)
63-
subprocess.call(cmd, stdout=subprocess.PIPE)
58+
with zipfile.ZipFile(ZIPPATH, mode="w") as z:
59+
for name in FILENAMES:
60+
z.write(os.path.join(TMPDIR, name), arcname=name)
6461

6562

6663
class TestIsArchiveName(unittest.TestCase):

0 commit comments

Comments
 (0)