Skip to content

Commit 0d30b56

Browse files
committed
add valgrind tests
1 parent 8a7a19e commit 0d30b56

File tree

8 files changed

+542
-8
lines changed

8 files changed

+542
-8
lines changed

.github/workflows/memory_check.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Memory Check
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
env:
12+
PYTHONUNBUFFERED: "1"
13+
FORCE_COLOR: "1"
14+
PYTHONIOENCODING: "utf8"
15+
16+
jobs:
17+
run:
18+
name: Valgrind on Ubuntu
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Set up Python 3.12
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: 3.12
28+
29+
- name: Install PyTest
30+
run: |
31+
pip install pytest pytest-asyncio
32+
shell: bash
33+
34+
- name: Build project
35+
run: pip install .[full]
36+
37+
- name: Install Valgrind
38+
run: sudo apt-get -y install valgrind
39+
40+
- name: Run tests with Valgrind
41+
run: valgrind --supressions=valgrind-python.supp --error-exitcode=1 pytest -x

src/_view/results.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ static int find_result_for(
8888
return -1;
8989
};
9090

91-
Py_DECREF(v_bytes);
92-
9391
if (PyList_Append(
9492
headers,
9593
header_list

src/_view/routing.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ int handle_route_callback(
443443
if (!dct)
444444
return -1;
445445

446-
447446
coro = PyObject_Vectorcall(
448447
send,
449448
(PyObject*[]) { dct },

src/view/app.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,12 @@ def load(self, *routes: Route) -> None:
10221022
if routes and (self.config.app.loader != "manual"):
10231023
warnings.warn(_ROUTES_WARN_MSG)
10241024

1025+
for index, i in enumerate(routes):
1026+
if not isinstance(i, Route):
1027+
raise TypeError(
1028+
f"(index {index}) expected Route object, got {i}"
1029+
)
1030+
10251031
if self.config.app.loader == "filesystem":
10261032
load_fs(self, self.config.app.loader_path)
10271033
elif self.config.app.loader == "simple":
@@ -1033,7 +1039,7 @@ def load(self, *routes: Route) -> None:
10331039
raise InvalidCustomLoaderError("custom loader was not set")
10341040

10351041
collected = self._user_loader(self, self.config.app.loader_path)
1036-
if not isinstance(routes, CollectionsIterable):
1042+
if not isinstance(collected, CollectionsIterable):
10371043
raise InvalidCustomLoaderError(
10381044
f"expected custom loader to return a list of routes, got {collected!r}"
10391045
)

tests/test_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def methodless_ctx(context: Context):
779779
async def m(context: Context):
780780
return context.method
781781

782-
app.load([m])
782+
app.load(m)
783783

784784
async with app.test() as test:
785785
assert (await test.get("/")).message == "a"

tests/test_loaders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def d():
3636
async def o():
3737
return "options"
3838

39-
app.load([g, p, pu, pa, d, o])
39+
app.load(g, p, pu, pa, d, o)
4040

4141
async with app.test() as test:
4242
assert (await test.get("/get")).message == "get"
@@ -114,7 +114,7 @@ def test_custom_loader_errors():
114114

115115
@app.custom_loader
116116
def my_loader(app: App, path: Path) -> List[Route]:
117-
return 123
117+
return 123 # type: ignore
118118

119119
with pytest.raises(InvalidCustomLoaderError):
120120
app.load()

tests/test_websocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def back_and_forth(ws: WebSocket):
4141
assert message == count
4242
count += 1
4343

44-
app.load([back_and_forth])
44+
app.load(back_and_forth)
4545

4646
async with app.test() as test:
4747
async with test.websocket("/") as ws:

0 commit comments

Comments
 (0)