11#! /bin/sh
22
3- # Executes the pytest framework in both JPype and Jep modes .
3+ # Runs the unit tests .
44#
55# Usage examples:
66# bin/test.sh
@@ -13,26 +13,26 @@ dir=$(dirname "$0")
1313cd " $dir /.."
1414
1515echo
16- echo " ------------------------------------------- "
17- echo " | Testing JPype mode (Java inside Python) |"
18- echo " ------------------------------------------- "
16+ echo " ----------------------"
17+ echo " | Running unit tests |"
18+ echo " ----------------------"
1919
2020if [ $# -gt 0 ]
2121then
22- python -m pytest -p no:faulthandler $@
22+ uv run python -m pytest -v -p no:faulthandler $@
2323else
24- python -m pytest -p no:faulthandler tests/
24+ uv run python -m pytest -v -p no:faulthandler tests/
2525fi
2626jpypeCode=$?
2727
2828echo
29- echo " ------------------------------------------- "
30- echo " | Running integration tests (JPype only) |"
31- echo " ------------------------------------------- "
29+ echo " -----------------------------"
30+ echo " | Running integration tests |"
31+ echo " -----------------------------"
3232itCode=0
3333for t in tests/it/* .py
3434do
35- python " $t "
35+ uv run python " $t "
3636 code=$?
3737 printf -- " --> %s " " $t "
3838 if [ " $code " -eq 0 ]
4444 fi
4545done
4646
47- echo
48- echo " -------------------------------------------"
49- echo " | Testing Jep mode (Python inside Java) |"
50- echo " -------------------------------------------"
51-
52- # Discern the Jep installation.
53- site_packages=$( python -c ' import sys; print(next(p for p in sys.path if p.endswith("site-packages")))' )
54- test -d " $site_packages /jep" || {
55- echo " [ERROR] Failed to detect Jep installation in current environment!" 1>&2
56- exit 1
57- }
58-
59- # We execute the pytest framework through Jep via jgo, so that
60- # the surrounding JVM includes scijava-table on the classpath.
61- #
62- # Arguments to the shell script are translated into an argument
63- # list to the pytest.main function. A weak attempt at handling
64- # special characters, e.g. single quotation marks and backslashes,
65- # is made, but there are surely other non-working cases.
66-
67- if [ $# -gt 0 ]
68- then
69- a=$( echo " $@ " | sed ' s/\\/\\\\/g' ) # escape backslashes
70- a=$( echo " $a " | sed ' s/' \' ' /\\' \' ' /g' ) # escape single quotes
71- a=$( echo " $a " | sed ' s/ /' \' ' ,' \' ' /g' ) # replace space with ','
72- argString=" ['-v', '$a ']"
73- else
74- argString=" "
75- fi
76- if ! java -version 2>&1 | grep -q ' ^openjdk version "\(1\.8\|9\|10\|11\|12\|13\|14\|15\|16\)\.'
77- then
78- echo " Skipping jep tests due to unsupported Java version:"
79- java -version || true
80- jepCode=0
81- elif [ " $( uname -s) " = " Darwin" ]
82- then
83- echo " Skipping jep tests on macOS due to flakiness"
84- jepCode=0
85- else
86- echo " # AUTOGENERATED test file for jep; safe to delete.
87- import logging, sys, pytest, scyjava
88- scyjava._logger.addHandler(logging.StreamHandler(sys.stderr))
89- scyjava._logger.setLevel(logging.INFO)
90- scyjava.config.set_verbose(2)
91- result = pytest.main($argString )
92- if result:
93- sys.exit(result)
94- " > jep_test.py
95- jgo -vv \
96- -r scijava.public=https://maven.scijava.org/content/groups/public \
97- -Djava.library.path=" $site_packages /jep" \
98- black.ninia:jep:jep.Run+org.scijava:scijava-table \
99- jep_test.py
100- jepCode=$?
101- rm -f jep_test.py
102- fi
103-
10447test " $jpypeCode " -ne 0 && exit " $jpypeCode "
10548test " $itCode " -ne 0 && exit " $itCode "
106- test " $jepCode " -ne 0 && exit " $jepCode "
10749exit 0
0 commit comments