[python] prepend build/lib folder to PYTHONPATH before running tests

This commit is contained in:
Cosimo Lupo 2015-04-22 16:49:00 +01:00
parent 7fa4586079
commit 906f4f52ab
3 changed files with 40 additions and 7 deletions

4
.gitignore vendored
View File

@ -2,4 +2,6 @@
*.txt.uncompressed
*.bro
*.unbro
/tools/bro
tools/bro
build/
dist/

View File

@ -2,6 +2,7 @@
from __future__ import print_function
import sys
import os
import sysconfig
from subprocess import check_call
import filecmp
@ -14,6 +15,18 @@ def diff_q(first_file, second_file):
return 0
# prepend ../../build/lib folder to PYTHONPATH
LIB_DIRNAME = "lib.{platform}-{version[0]}.{version[1]}".format(
platform=sysconfig.get_platform(),
version=sys.version_info)
BUILD_PATH = os.path.abspath(os.path.join("..", "..", "build", LIB_DIRNAME))
TEST_ENV = os.environ.copy()
if 'PYTHONPATH' not in TEST_ENV:
TEST_ENV['PYTHONPATH'] = BUILD_PATH
else:
TEST_ENV['PYTHONPATH'] = BUILD_PATH + os.pathsep + TEST_ENV['PYTHONPATH']
PYTHON = sys.executable or "python"
BRO = os.path.abspath("../bro.py")
@ -43,11 +56,13 @@ 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]
check_call([PYTHON, BRO, "-f", "-d", "-i", filename, "-o", uncompressed])
check_call([PYTHON, BRO, "-f", "-d", "-i", filename, "-o", uncompressed],
env=TEST_ENV)
if diff_q(uncompressed, expected) != 0:
sys.exit(1)
# Test the streaming version
with open(filename, "rb") as infile, open(uncompressed, "wb") as outfile:
check_call([PYTHON, BRO, '-d'], stdin=infile, stdout=outfile)
check_call([PYTHON, BRO, '-d'], stdin=infile, stdout=outfile,
env=TEST_ENV)
if diff_q(uncompressed, expected) != 0:
sys.exit(1)

View File

@ -2,6 +2,7 @@
from __future__ import print_function
import sys
import os
import sysconfig
from subprocess import check_call, Popen, PIPE
import filecmp
@ -14,6 +15,18 @@ def diff_q(first_file, second_file):
return 0
# prepend ../../build/lib folder to PYTHONPATH
LIB_DIRNAME = "lib.{platform}-{version[0]}.{version[1]}".format(
platform=sysconfig.get_platform(),
version=sys.version_info)
BUILD_PATH = os.path.abspath(os.path.join("..", "..", "build", LIB_DIRNAME))
TEST_ENV = os.environ.copy()
if 'PYTHONPATH' not in TEST_ENV:
TEST_ENV['PYTHONPATH'] = BUILD_PATH
else:
TEST_ENV['PYTHONPATH'] = BUILD_PATH + os.pathsep + TEST_ENV['PYTHONPATH']
PYTHON = sys.executable or "python"
BRO = os.path.abspath("../bro.py")
@ -34,13 +47,16 @@ 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"
check_call([PYTHON, BRO, "-f", "-i", filename, "-o", compressed])
check_call([PYTHON, BRO, "-f", "-d", "-i", compressed, "-o", uncompressed])
check_call([PYTHON, BRO, "-f", "-i", filename, "-o", compressed],
env=TEST_ENV)
check_call([PYTHON, BRO, "-f", "-d", "-i", compressed, "-o", uncompressed],
env=TEST_ENV)
if diff_q(filename, uncompressed) != 0:
sys.exit(1)
# Test the streaming version
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)
p = Popen([PYTHON, BRO], stdin=infile, stdout=PIPE, env=TEST_ENV)
check_call([PYTHON, BRO, "-d"], stdin=p.stdout, stdout=outfile,
env=TEST_ENV)
if diff_q(filename, uncompressed) != 0:
sys.exit(1)