From 9a3680ded74ab86e3c27fe37396d1e0fdfbe3b24 Mon Sep 17 00:00:00 2001 From: Vadim Lebedev Date: Tue, 9 Aug 2022 22:54:47 +0200 Subject: [PATCH] Fix tests to wokr in python2 and Python3 environments --- tests.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index f984bc7..8dbb753 100644 --- a/tests.py +++ b/tests.py @@ -33,8 +33,7 @@ import io from libarchive import Archive, is_archive_name, is_archive from libarchive.zip import is_zipfile, ZipFile, ZipEntry -# PY3 = sys.version_info[0] == 3 -PY3 = True +PY3 = sys.version_info[0] == 3 TMPDIR = tempfile.mkdtemp(suffix='.python-libarchive') ZIPFILE = 'test.zip' @@ -250,6 +249,15 @@ class TestZipWrite(unittest.TestCase): import base64 +# ZIP_CONTENT is base64 encoded password protected zip file with password: 'pwd' and following contents: +# unzip -l /tmp/zzz.zip +#Archive: /tmp/zzz.zip +# Length Date Time Name +#--------- ---------- ----- ---- +# 9 08-09-2022 19:29 test.txt +#--------- ------- +# 9 1 file + ZIP_CONTENT='UEsDBAoACQAAAKubCVVjZ7b1FQAAAAkAAAAIABwAdGVzdC50eHRVVAkAA5K18mKStfJid' + \ 'XgLAAEEAAAAAAQAAAAA5ryoP1rrRK5apjO41YMAPjpkWdU3UEsHCGNntvUVAAAACQAAAF' + \ 'BLAQIeAwoACQAAAKubCVVjZ7b1FQAAAAkAAAAIABgAAAAAAAEAAACkgQAAAAB0ZXN0LnR' + \ @@ -262,7 +270,11 @@ ITEM_NAME='test.txt' class TestPasswordProtection(unittest.TestCase): def setUp(self): with open(ZIPPATH, mode='w') as f: - f.write(base64.b64decode(ZIP_CONTENT)) + if PY3: + f.write(base64.b64decode(ZIP_CONTENT).decode('utf-8')) + else: + f.write(base64.b64decode(ZIP_CONTENT)) + def tearDown(self): os.remove(ZIPPATH)