mirror of
https://github.com/google/brotli.git
synced 2024-11-24 20:40:13 +00:00
Merge pull request #43 from anthrotype/fix_py
[python] fix calling python script as subprocess on Windows
This commit is contained in:
commit
e0aa0cc450
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user