invoke tests on argv[0] interpreter-from-argv
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 12 Nov 2020 12:20:54 +0000 (13:20 +0100)
committerPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 12 Nov 2020 12:28:51 +0000 (13:28 +0100)
Avoid hard-coding the interpreter as this will fail if the
scripts are run say with a pathfix-adjusted shebang.

testing/test_concat_compress.py
testing/test_deltatar.py
testing/test_encryption.py

index b2539b9..3541577 100644 (file)
@@ -15,7 +15,7 @@
 # <http://www.gnu.org/licenses/lgpl-3.0.html>
 
 
-import os, unittest, hashlib, string
+import os, unittest, hashlib, string, sys
 
 from deltatar.tarfile import TarFile, GNU_FORMAT, GZ_MAGIC_BYTES
 
@@ -373,7 +373,8 @@ class ConcatCompressTest(BaseTest):
         os.unlink("small2")
 
         # extract using the command line this time
-        os.system("python3 filesplit.py -s $'\\x1f\\x8b' -p sample.tar.gz. sample.tar.gz")
+        os.system("'%s' filesplit.py -s $'\\x1f\\x8b' -p sample.tar.gz. sample.tar.gz"
+                  % sys.executable)
 
         assert os.path.exists("sample.tar.gz.0") # first file
         assert os.path.exists("sample.tar.gz.1") # second file
index 4fac62f..a879ad0 100644 (file)
@@ -24,6 +24,7 @@ import shutil
 import logging
 import binascii
 import json
+import sys
 from datetime import datetime
 from functools import partial
 from unittest import skip, SkipTest
@@ -170,8 +171,9 @@ class DeltaTarTest(BaseTest):
 
         # split the resulting archive into its constituents without
         # decrypting
-        ret = os.system("python3 ./deltatar/crypto.py process -D -S -i - "
-                        "-o backup_dir/split <\'%s\'" % backup_path)
+        ret = os.system("'%s' ./deltatar/crypto.py process -D -S -i - "
+                        "-o backup_dir/split <\'%s\'"
+                        % (sys.executable, backup_path))
 
         assert os.path.exists ("backup_dir/split")
 
index fee7b41..d6de1b8 100644 (file)
@@ -20,6 +20,7 @@ import hashlib
 import json
 import os
 import subprocess
+import sys
 
 from deltatar import crypto
 from deltatar.tarfile import TarFile, GNU_FORMAT
@@ -74,8 +75,9 @@ class EncryptionTest(BaseTest):
 
         # decrypt outer archive layer with crypto.py
         assert os.path.exists("sample.tar.gz.pdtcrypt")
-        ret = os.system("python3 ./deltatar/crypto.py process -p '%s' "
-                        "<sample.tar.gz.pdtcrypt >sample.tar.gz" % pw)
+        ret = os.system("'%s' ./deltatar/crypto.py process -p '%s' "
+                        "<sample.tar.gz.pdtcrypt >sample.tar.gz"
+                        % (sys.executable, pw))
         assert ret == 0
         assert os.path.exists("sample.tar.gz")
 
@@ -113,9 +115,9 @@ class EncryptionTest(BaseTest):
 
         # decrypt outer archive layer with crypto.py
         assert os.path.exists("sample.tar.gz.pdtcrypt")
-        ret = os.system("python3 ./deltatar/crypto.py process -k '%s' "
+        ret = os.system("'%s' ./deltatar/crypto.py process -k '%s' "
                         "<sample.tar.gz.pdtcrypt >sample.tar.gz"
-                        % binascii.hexlify (key).decode ())
+                        % (sys.executable, binascii.hexlify (key).decode ()))
         assert ret == 0
         assert os.path.exists("sample.tar.gz")
 
@@ -153,9 +155,9 @@ class EncryptionTest(BaseTest):
 
         # decrypt outer archive layer with crypto.py
         assert os.path.exists("sample.tar.gz.pdtcrypt")
-        ret = os.system("PDTCRYPT_KEY='%s' python3 ./deltatar/crypto.py process "
+        ret = os.system("PDTCRYPT_KEY='%s' '%s' ./deltatar/crypto.py process "
                         "<sample.tar.gz.pdtcrypt >sample.tar.gz"
-                        % binascii.hexlify (key).decode ())
+                        % (binascii.hexlify (key).decode (), sys.executable))
         assert ret == 0
         assert os.path.exists("sample.tar.gz")
 
@@ -193,7 +195,7 @@ class EncryptionTest(BaseTest):
 
         # decrypt outer archive layer with crypto.py
         assert os.path.exists("sample.tar.gz.pdtcrypt")
-        with subprocess.Popen ( [ "python3", "./deltatar/crypto.py", "scrypt"
+        with subprocess.Popen ( [ sys.executable, "./deltatar/crypto.py", "scrypt"
                                 , "-f", "params"
                                 , "-i", "sample.tar.gz.pdtcrypt" ]
                               , env={ "PDTCRYPT_PASSWORD" : pw }
@@ -242,8 +244,8 @@ class EncryptionTest(BaseTest):
             os.unlink(k)
 
         assert os.path.exists("sample.tar.gz.pdtcrypt")
-        ret = os.system("python3 ./deltatar/crypto.py process -p '%s' -s --split "
-                        "-i sample.tar.gz.pdtcrypt -o ." % pw)
+        ret = os.system("'%s' ./deltatar/crypto.py process -p '%s' -s --split "
+                        "-i sample.tar.gz.pdtcrypt -o ." % (sys.executable, pw))
         assert ret == 0
         for i in range (len (hash)):
             fname = "pdtcrypt-object-%d.bin" % (i + 1)
@@ -290,9 +292,9 @@ class EncryptionTest(BaseTest):
             os.unlink(k)
 
         assert os.path.exists("sample.tar.gz.pdtcrypt")
-        ret = os.system("PDTCRYPT_PASSWORD='%s' python3 ./deltatar/crypto.py "
+        ret = os.system("PDTCRYPT_PASSWORD='%s' '%s' ./deltatar/crypto.py "
                         "process -s --split -i sample.tar.gz.pdtcrypt -o ."
-                        % pw)
+                        % (pw, sys.executable))
         assert ret == 0
         for i in range (len (hash)):
             fname = "pdtcrypt-object-%d.bin" % (i + 1)