|
1 | 1 | #!/bin/bash |
2 | 2 | # |
3 | | -# Script to execute tests in Docker |
| 3 | +# Script to execute tests in Docker / CI / UV environment |
4 | 4 | # |
5 | 5 |
|
| 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 | + |
6 | 61 | echo "Installing dependencies..." |
7 | | -pip install pytest coverage || exit 1 |
| 62 | +run_pip_install pytest coverage || exit 1 |
8 | 63 | export COVERAGE_PROCESS_START=".coveragerc" |
9 | 64 |
|
10 | 65 | echo "Initial tests..." |
11 | 66 | export JSONRPCLIB_TEST_EXPECTED_LIB=json |
12 | | -coverage run -m pytest || exit 1 |
| 67 | +run_coverage run -m pytest || exit 1 |
13 | 68 |
|
14 | 69 | 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 |
20 | 71 |
|
21 | 72 | 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 |
27 | 74 |
|
28 | 75 | 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 |
34 | 77 |
|
35 | 78 | 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 |
41 | 80 |
|
42 | 81 | echo "Combine results..." |
43 | | -coverage combine || exit $? |
44 | | -coverage report |
| 82 | +run_coverage combine || exit $? |
| 83 | +run_coverage report |
0 commit comments