aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorCosimo Lupo <cosimo.lupo@daltonmaag.com>2015-04-22 17:54:56 +0100
committerCosimo Lupo <cosimo.lupo@daltonmaag.com>2015-04-22 17:54:56 +0100
commitcdde52ef63d9ef69473cb123b5257770be493117 (patch)
treedc3dfe8ea30d7e9a4aef53721abb00beb23599da /python
parent906f4f52ab3e3daaf4bb893e69d0bcfee1f49726 (diff)
downloadbrotli-cdde52ef63d9ef69473cb123b5257770be493117.zip
brotli-cdde52ef63d9ef69473cb123b5257770be493117.tar.gz
brotli-cdde52ef63d9ef69473cb123b5257770be493117.tar.bz2
[python] refactored tests and import shared utilities from module
Diffstat (limited to 'python')
-rwxr-xr-xpython/tests/compatibility_test.py25
-rwxr-xr-xpython/tests/roundtrip_test.py25
-rw-r--r--python/tests/test_utils.py36
3 files changed, 38 insertions, 48 deletions
diff --git a/python/tests/compatibility_test.py b/python/tests/compatibility_test.py
index 941b306..68886be 100755
--- a/python/tests/compatibility_test.py
+++ b/python/tests/compatibility_test.py
@@ -2,33 +2,10 @@
from __future__ import print_function
import sys
import os
-import sysconfig
from subprocess import check_call
-import filecmp
+from test_utils import PYTHON, BRO, TEST_ENV, diff_q
-def diff_q(first_file, second_file):
- """Simulate call to POSIX diff with -q argument"""
- if not filecmp.cmp(first_file, second_file, shallow=False):
- print("Files %s and %s differ" % (first_file, second_file))
- return 1
- 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")
INPUTS = """\
testdata/empty.compressed
diff --git a/python/tests/roundtrip_test.py b/python/tests/roundtrip_test.py
index 69391a6..36d91dd 100755
--- a/python/tests/roundtrip_test.py
+++ b/python/tests/roundtrip_test.py
@@ -2,33 +2,10 @@
from __future__ import print_function
import sys
import os
-import sysconfig
from subprocess import check_call, Popen, PIPE
-import filecmp
+from test_utils import PYTHON, BRO, TEST_ENV, diff_q
-def diff_q(first_file, second_file):
- """Simulate call to POSIX diff with -q argument"""
- if not filecmp.cmp(first_file, second_file, shallow=False):
- print("Files %s and %s differ" % (first_file, second_file))
- return 1
- 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")
INPUTS = """\
testdata/alice29.txt
diff --git a/python/tests/test_utils.py b/python/tests/test_utils.py
new file mode 100644
index 0000000..381b64e
--- /dev/null
+++ b/python/tests/test_utils.py
@@ -0,0 +1,36 @@
+from __future__ import print_function
+import sys
+import os
+import sysconfig
+import filecmp
+
+
+def diff_q(first_file, second_file):
+ """Simulate call to POSIX diff with -q argument"""
+ if not filecmp.cmp(first_file, second_file, shallow=False):
+ print("Files %s and %s differ" % (first_file, second_file),
+ file=sys.stderr)
+ return 1
+ return 0
+
+
+PYTHON = sys.executable or "python"
+
+# 'bro.py' script should be in parent directory
+BRO = os.path.abspath("../bro.py")
+
+# get platform- and version-specific build/lib folder
+platform_lib_name = "lib.{platform}-{version[0]}.{version[1]}".format(
+ platform=sysconfig.get_platform(),
+ version=sys.version_info)
+
+# by default, distutils' build base is in the same location as setup.py
+build_base = os.path.abspath(os.path.join("..", "..", "build"))
+build_lib = os.path.join(build_base, platform_lib_name)
+
+# prepend build/lib to PYTHONPATH environment variable
+TEST_ENV = os.environ.copy()
+if 'PYTHONPATH' not in TEST_ENV:
+ TEST_ENV['PYTHONPATH'] = build_lib
+else:
+ TEST_ENV['PYTHONPATH'] = build_lib + os.pathsep + TEST_ENV['PYTHONPATH']