1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from __future__ import annotations
from types import TracebackType
from typing import Self
import pytest
from fastapi import Request
from starlette.responses import Response
from pygitweb.api.action import Action
from pygitweb.api.subpage import Subpage
def test_action_subclass_wrong_return_annotation() -> None:
with pytest.raises(TypeError, match="missing or mismatched 'action'"):
class BadAction(Action):
def __enter__(self) -> Self:
return self
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> bool | None:
return None
def action_name(self) -> str:
return "bad"
def action(self, project: str, req: Request | None = None) -> int:
return 1
def test_action_subclass_missing_exit() -> None:
with pytest.raises(TypeError, match="missing or mismatched '__exit__'"):
class BadAction(Action):
def __enter__(self) -> Self:
return self
def action_name(self) -> str:
return "bad"
def action(self, project: str, req: Request | None = None) -> Response | None:
return None
def test_subpage_subclass_wrong_return_annotation() -> None:
with pytest.raises(TypeError, match="missing or mismatched 'subpage_name'"):
class BadSubpage(Subpage):
def __enter__(self) -> Self:
return self
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> bool | None:
return None
def subpage_name(self) -> int:
return 1
def link_name(self, project: str) -> str | None:
return None
def subpage_html(self, project: str) -> str | None:
return None
def summary_value_suffix_html(self, project: str, project_enc: str) -> str | None:
return None
def test_action_virtual_register_non_compliant() -> None:
class Bad:
def __enter__(self) -> Self:
return self
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> bool | None:
return None
def action_name(self) -> str:
return "bad"
def action(self, project: str, req: Request | None = None) -> int:
return 1
with pytest.raises(TypeError, match="missing or mismatched 'action'"):
Action.register(Bad)