aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorCosimo Lupo <cosimo.lupo@daltonmaag.com>2015-03-23 12:09:42 +0000
committerCosimo Lupo <cosimo.lupo@daltonmaag.com>2015-03-23 12:09:42 +0000
commit17866801d655c530db84839df743f1ee92eb8c68 (patch)
tree4eb8400911e0e8e1eb47049362f8426c56d28f00 /python
parent203fe326d477b44460f03eaae9cc773b44b07dcd (diff)
downloadbrotli-17866801d655c530db84839df743f1ee92eb8c68.zip
brotli-17866801d655c530db84839df743f1ee92eb8c68.tar.gz
brotli-17866801d655c530db84839df743f1ee92eb8c68.tar.bz2
[python] fix calling python script as subprocess on Windows
Diffstat (limited to 'python')
-rwxr-xr-xpython/tests/compatibility_test.py13
-rwxr-xr-xpython/tests/roundtrip_test.py18
2 files changed, 12 insertions, 19 deletions
diff --git a/python/tests/compatibility_test.py b/python/tests/compatibility_test.py
index 500eeed..81e305e 100755
--- a/python/tests/compatibility_test.py
+++ b/python/tests/compatibility_test.py
@@ -2,7 +2,7 @@
from __future__ import print_function
import sys
import os
-from subprocess import call, Popen, PIPE
+from subprocess import check_call
import filecmp
@@ -14,6 +14,7 @@ def diff_q(first_file, second_file):
return 0
+PYTHON = sys.executable or "python"
BRO = os.path.abspath("../bro.py")
INPUTS = """\
@@ -42,15 +43,11 @@ for filename in INPUTS.splitlines():
print('Testing decompression of file "%s"' % os.path.basename(filename))
uncompressed = os.path.splitext(filename)[0] + ".uncompressed"
expected = os.path.splitext(filename)[0]
- call('"%s" -f -d -i "%s" -o "%s"' % (BRO, filename, uncompressed),
- shell=True)
+ check_call([PYTHON, BRO, "-f", "-d", "-i", filename, "-o", uncompressed])
if diff_q(uncompressed, expected) != 0:
sys.exit(1)
# Test the streaming version
- with open(filename, "rb") as infile:
- p = Popen('"%s" -d' % BRO, stdin=infile, stdout=PIPE, shell=True)
- output = p.communicate()[0]
- with open(uncompressed, "wb") as outfile:
- outfile.write(output)
+ with open(filename, "rb") as infile, open(uncompressed, "wb") as outfile:
+ check_call([PYTHON, BRO, '-d'], stdin=infile, stdout=outfile)
if diff_q(uncompressed, expected) != 0:
sys.exit(1)
diff --git a/python/tests/roundtrip_test.py b/python/tests/roundtrip_test.py
index 5ef4ba3..e9e8525 100755
--- a/python/tests/roundtrip_test.py
+++ b/python/tests/roundtrip_test.py
@@ -2,7 +2,7 @@
from __future__ import print_function
import sys
import os
-from subprocess import call, Popen, PIPE
+from subprocess import check_call, Popen, PIPE
import filecmp
@@ -14,6 +14,7 @@ def diff_q(first_file, second_file):
return 0
+PYTHON = sys.executable or "python"
BRO = os.path.abspath("../bro.py")
INPUTS = """\
@@ -33,18 +34,13 @@ for filename in INPUTS.splitlines():
print('Roundtrip testing of file "%s"' % os.path.basename(filename))
compressed = os.path.splitext(filename)[0] + ".bro"
uncompressed = os.path.splitext(filename)[0] + ".unbro"
- call('"%s" -f -i "%s" -o "%s"' % (BRO, filename, compressed), shell=True)
- call('"%s" -f -d -i "%s" -o "%s"' %
- (BRO, compressed, uncompressed), shell=True)
+ check_call([PYTHON, BRO, "-f", "-i", filename, "-o", compressed])
+ check_call([PYTHON, BRO, "-f", "-d", "-i", compressed, "-o", uncompressed])
if diff_q(filename, uncompressed) != 0:
sys.exit(1)
# Test the streaming version
- with open(filename, "rb") as infile:
- p1 = Popen(BRO, stdin=infile, stdout=PIPE, shell=True)
- p2 = Popen("%s -d" % BRO, stdin=p1.stdout, stdout=PIPE, shell=True)
- p1.stdout.close()
- output = p2.communicate()[0]
- with open(uncompressed, "wb") as outfile:
- outfile.write(output)
+ with open(filename, "rb") as infile, open(uncompressed, "wb") as outfile:
+ p = Popen([PYTHON, BRO], stdin=infile, stdout=PIPE)
+ check_call([PYTHON, BRO, "-d"], stdin=p.stdout, stdout=outfile)
if diff_q(filename, uncompressed) != 0:
sys.exit(1)