Skip to content

Commit e577afc

Browse files
committed
Make run_tests.sh uv-compatible
Signed-off-by: Thomas Calmant <[email protected]>
1 parent c2f986a commit e577afc

File tree

1 file changed

+64
-25
lines changed

1 file changed

+64
-25
lines changed

run_tests.sh

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,83 @@
11
#!/bin/bash
22
#
3-
# Script to execute tests in Docker
3+
# Script to execute tests in Docker / CI / UV environment
44
#
55

6+
if [ -z "$UV" ]
7+
then
8+
echo "UV is not set"
9+
else
10+
echo "Using UV at $UV"
11+
fi
12+
13+
run_pip_install() {
14+
if [ -z "$UV" ]
15+
then
16+
pip install "$@"
17+
return $?
18+
else
19+
uv pip install "$@"
20+
return $?
21+
fi
22+
}
23+
24+
run_pip_uninstall() {
25+
if [ -z "$UV" ]
26+
then
27+
pip uninstall -y "$@"
28+
return $?
29+
else
30+
uv pip uninstall "$@"
31+
return $?
32+
fi
33+
}
34+
35+
run_coverage() {
36+
if [ -z "$UV" ]
37+
then
38+
coverage "$@"
39+
return $?
40+
else
41+
uv run coverage "$@"
42+
return $?
43+
fi
44+
}
45+
46+
run_lib_tests() {
47+
export JSONRPCLIB_TEST_EXPECTED_LIB="$1"
48+
run_pip_install "$2"
49+
if [ $? -ne 0 ]
50+
then
51+
echo "Failed to install $2"
52+
return 0
53+
fi
54+
55+
run_coverage run -m pytest tests/test_jsonlib.py
56+
rc=$?
57+
run_pip_uninstall "$2"
58+
return $rc
59+
}
60+
661
echo "Installing dependencies..."
7-
pip install pytest coverage || exit 1
62+
run_pip_install pytest coverage || exit 1
863
export COVERAGE_PROCESS_START=".coveragerc"
964

1065
echo "Initial tests..."
1166
export JSONRPCLIB_TEST_EXPECTED_LIB=json
12-
coverage run -m pytest || exit 1
67+
run_coverage run -m pytest || exit 1
1368

1469
echo "orJson tests..."
15-
pip install orjson && (
16-
export JSONRPCLIB_TEST_EXPECTED_LIB=orjson
17-
coverage run -m pytest tests/test_jsonlib.py || exit 1
18-
pip uninstall -y orjson
19-
)
70+
run_lib_tests orjson orjson || exit 1
2071

2172
echo "uJson tests..."
22-
pip install ujson && (
23-
export JSONRPCLIB_TEST_EXPECTED_LIB=ujson
24-
coverage run -m pytest tests/test_jsonlib.py || exit 1
25-
pip uninstall -y ujson
26-
)
73+
run_lib_tests ujson ujson || exit 1
2774

2875
echo "cJson tests..."
29-
pip install python-cjson && (
30-
export JSONRPCLIB_TEST_EXPECTED_LIB=cjson
31-
coverage run -m pytest tests/test_jsonlib.py || exit 1
32-
pip uninstall -y python-cjson
33-
)
76+
run_lib_tests cjson python-cjson || exit 1
3477

3578
echo "simplejson tests..."
36-
pip install simplejson && (
37-
export JSONRPCLIB_TEST_EXPECTED_LIB=simplejson
38-
coverage run -m pytest tests/test_jsonlib.py || exit 1
39-
pip uninstall -y simplejson
40-
)
79+
run_lib_tests simplejson simplejson || exit 1
4180

4281
echo "Combine results..."
43-
coverage combine || exit $?
44-
coverage report
82+
run_coverage combine || exit $?
83+
run_coverage report

0 commit comments

Comments
 (0)