forked from scijava/scyjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·107 lines (96 loc) · 2.87 KB
/
test.sh
File metadata and controls
executable file
·107 lines (96 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/sh
# Executes the pytest framework in both JPype and Jep modes.
#
# Usage examples:
# bin/test.sh
# bin/test.sh tests/test_basics.py
# bin/test.sh tests/test_convert.py::TestConvert::test2DStringArray
set -e
dir=$(dirname "$0")
cd "$dir/.."
echo
echo "-------------------------------------------"
echo "| Testing JPype mode (Java inside Python) |"
echo "-------------------------------------------"
if [ $# -gt 0 ]
then
python -m pytest -p no:faulthandler $@
else
python -m pytest -p no:faulthandler tests/
fi
jpypeCode=$?
echo
echo "-------------------------------------------"
echo "| Running integration tests (JPype only) |"
echo "-------------------------------------------"
itCode=0
for t in tests/it/*.py
do
python "$t"
code=$?
printf -- "--> %s " "$t"
if [ "$code" -eq 0 ]
then
echo "[OK]"
else
echo "[FAILED]"
itCode=$code
fi
done
echo
echo "-------------------------------------------"
echo "| Testing Jep mode (Python inside Java) |"
echo "-------------------------------------------"
# Discern the Jep installation.
site_packages=$(python -c 'import sys; print(next(p for p in sys.path if p.endswith("site-packages")))')
test -d "$site_packages/jep" || {
echo "[ERROR] Failed to detect Jep installation in current environment!" 1>&2
exit 1
}
# We execute the pytest framework through Jep via jgo, so that
# the surrounding JVM includes scijava-table on the classpath.
#
# Arguments to the shell script are translated into an argument
# list to the pytest.main function. A weak attempt at handling
# special characters, e.g. single quotation marks and backslashes,
# is made, but there are surely other non-working cases.
if [ $# -gt 0 ]
then
a=$(echo "$@" | sed 's/\\/\\\\/g') # escape backslashes
a=$(echo "$a" | sed 's/'\''/\\'\''/g') # escape single quotes
a=$(echo "$a" | sed 's/ /'\'','\''/g') # replace space with ','
argString="['-v', '$a']"
else
argString=""
fi
if ! java -version 2>&1 | grep -q '^openjdk version "\(1\.8\|9\|10\|11\|12\|13\|14\|15\|16\)\.'
then
echo "Skipping jep tests due to unsupported Java version:"
java -version || true
jepCode=0
elif [ "$(uname -s)" = "Darwin" ]
then
echo "Skipping jep tests on macOS due to flakiness"
jepCode=0
else
echo "# AUTOGENERATED test file for jep; safe to delete.
import logging, sys, pytest, scyjava
scyjava._logger.addHandler(logging.StreamHandler(sys.stderr))
scyjava._logger.setLevel(logging.INFO)
scyjava.config.set_verbose(2)
result = pytest.main($argString)
if result:
sys.exit(result)
" > jep_test.py
jgo -vv \
-r scijava.public=https://maven.scijava.org/content/groups/public \
-Djava.library.path="$site_packages/jep" \
black.ninia:jep:jep.Run+org.scijava:scijava-table \
jep_test.py
jepCode=$?
rm -f jep_test.py
fi
test "$jpypeCode" -ne 0 && exit "$jpypeCode"
test "$itCode" -ne 0 && exit "$itCode"
test "$jepCode" -ne 0 && exit "$jepCode"
exit 0