Skip to content

Commit ccdfbb9

Browse files
authored
Merge pull request #68 from tcalmant/uv-update
Configured repo to be usable with uv/ruff
2 parents 3b625cd + e577afc commit ccdfbb9

File tree

9 files changed

+94
-42
lines changed

9 files changed

+94
-42
lines changed

.github/workflows/build-24.04.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
run: |
3131
python -m pip install --upgrade pip
3232
python -m pip install flake8 pytest
33-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3433
- name: Lint with flake8
3534
run: |
3635
# stop the build if there are Python syntax errors or undefined names

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ __pycache__
1111
# VS Code
1212
.vscode
1313
.cache
14-
.mypy_cache
14+
.*_cache
1515

1616
# Tox
1717
.tox/
1818
.coverage
19+
.coverage.*
1920
htmlcov/
2021

2122
# Nosetests
2223
.noseids
2324
nosetests.xml
2425

2526
# Development environment
27+
.venv/
2628
venv*/
2729

2830
# When installed in develop mode
@@ -32,3 +34,6 @@ venv*/
3234
build/*
3335
dist/*
3436
*.egg-info/
37+
38+
# uv lock file
39+
uv.lock

jsonrpclib/SimpleJSONRPCServer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def _dispatch(self, method, params, config=None):
425425
)
426426
_logger.warning("Invalid call parameters: %s", fault)
427427
return fault
428-
except:
428+
except BaseException:
429429
# Method exception
430430
err_lines = traceback.format_exception(*sys.exc_info())
431431
trace_string = "{0} | {1}".format(
@@ -502,7 +502,7 @@ def do_POST(self):
502502

503503
# No exception: send a 200 OK
504504
self.send_response(200)
505-
except:
505+
except BaseException:
506506
# Exception: send 500 Server Error
507507
self.send_response(500)
508508
err_lines = traceback.format_exception(*sys.exc_info())

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,14 @@ Issues = "https://github.com/tcalmant/jsonrpclib/issues"
4444
Documentation = "https://jsonrpclib-pelix.readthedocs.io/"
4545
Source = "https://github.com/tcalmant/jsonrpclib/"
4646

47+
[dependency-groups]
48+
dev = [
49+
"coverage>=6.2",
50+
"pytest>=7.0.1",
51+
]
52+
4753
[tool.black]
4854
line-length = 80
55+
56+
[tool.ruff]
57+
line-length = 80

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

tests/cgi-bin/cgi_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
root_dir = os.path.dirname(os.path.dirname(current_dir))
1111
sys.path.insert(0, root_dir)
1212

13-
from jsonrpclib.SimpleJSONRPCServer import CGIJSONRPCRequestHandler
13+
from jsonrpclib.SimpleJSONRPCServer import CGIJSONRPCRequestHandler # noqa: E402
1414

1515

1616
def add(a, b):

tests/test_headers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ def captured_headers(self, check_duplicates=True):
7474
# Extract the sent request content
7575
request_lines = f.getvalue().splitlines()
7676
request_lines = list(
77-
filter(lambda l: l.startswith("send:"), request_lines)
77+
filter(lambda line: line.startswith("send:"), request_lines)
7878
)
7979
request_line = request_lines[0].split("send: ")[-1]
8080

8181
# Convert it to a string
8282
try:
8383
# Use eval to convert the representation into a string
8484
request_line = from_bytes(eval(request_line))
85-
except:
85+
except Exception:
8686
# Keep the received version
8787
pass
8888

tests/test_jsonlib.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,30 @@ def test_best(self):
8989
available = {"json"}
9090

9191
try:
92-
import cjson # pylint: disable=unused-import,import-outside-toplevel
92+
import cjson
9393

94-
available.add("cjson")
94+
available.add(cjson.__name__)
9595
except ImportError:
9696
pass
9797

9898
try:
99-
import ujson # pylint: disable=unused-import,import-outside-toplevel
99+
import ujson
100100

101-
available.add("ujson")
101+
available.add(ujson.__name__)
102102
except ImportError:
103103
pass
104104

105105
try:
106-
import simplejson # pylint: disable=unused-import,import-outside-toplevel
106+
import simplejson
107107

108-
available.add("simplejson")
108+
available.add(simplejson.__name__)
109109
except ImportError:
110110
pass
111111

112112
try:
113-
import orjson # pylint: disable=unused-import,import-outside-toplevel
113+
import orjson
114114

115-
available.add("orjson")
115+
available.add(orjson.__name__)
116116
except ImportError:
117117
pass
118118

tests/test_unix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_full_path(self):
6565
# Clean up
6666
try:
6767
os.remove(socket_name)
68-
except:
68+
except IOError:
6969
pass
7070

7171
def test_host_only(self):
@@ -105,5 +105,5 @@ def test_host_only(self):
105105
# Clean up
106106
try:
107107
os.remove(socket_name)
108-
except:
108+
except IOError:
109109
pass

0 commit comments

Comments
 (0)