Skip to content

Commit 50015ba

Browse files
committed
Add stubs for WebTest
1 parent 5a7bac0 commit 50015ba

8 files changed

Lines changed: 539 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# error: failed to find stub
2+
# ==========================
3+
# These modules have been migrated to external packages
4+
# and emit an `ImportError` if people try to use the
5+
# functions/classes defined within
6+
webtest.ext
7+
webtest.sel
8+
# Compatibility/utility modules for internal use that didn't
9+
# seem worth including in the stubs
10+
webtest.compat
11+
webtest.lint
12+
webtest.utils
13+
14+
# error: variable differs from runtime type
15+
# =========================================
16+
# Even though this can be `None`, it never should be during
17+
# normal use of WebTest, so it seems more pragmatic to treat
18+
# it as always non-`None`
19+
webtest.response.TestResponse.request
20+
webtest.TestResponse.request

stubs/WebTest/METADATA.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version = "3.0.*"
2+
upstream_repository = "https://github.com/Pylons/webtest"
3+
requires = ["types-beautifulsoup4", "types-waitress", "types-WebOb"]

stubs/WebTest/webtest/__init__.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from webtest.app import AppError as AppError, TestApp as TestApp, TestRequest as TestRequest
2+
from webtest.forms import (
3+
Checkbox as Checkbox,
4+
Field as Field,
5+
Form as Form,
6+
Hidden as Hidden,
7+
Radio as Radio,
8+
Select as Select,
9+
Submit as Submit,
10+
Text as Text,
11+
Textarea as Textarea,
12+
Upload as Upload,
13+
)
14+
from webtest.response import TestResponse as TestResponse

stubs/WebTest/webtest/app.pyi

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import json
2+
from _typeshed.wsgi import WSGIApplication
3+
from collections.abc import Mapping, Sequence
4+
from http.cookiejar import CookieJar, DefaultCookiePolicy
5+
from typing import Any, Generic, Literal, TypeVar
6+
from typing_extensions import TypeAlias
7+
8+
from webob.request import BaseRequest
9+
from webtest.response import TestResponse
10+
11+
_Files: TypeAlias = Sequence[tuple[str, str] | tuple[str, str, bytes]]
12+
_AppT = TypeVar("_AppT", bound=WSGIApplication, default=WSGIApplication)
13+
14+
__all__ = ["TestApp", "TestRequest"]
15+
16+
class AppError(Exception):
17+
def __init__(self, message: str, *args: object) -> None: ...
18+
19+
class CookiePolicy(DefaultCookiePolicy): ...
20+
21+
class TestRequest(BaseRequest):
22+
ResponseClass: type[TestResponse]
23+
__test__: Literal[False]
24+
25+
class TestApp(Generic[_AppT]):
26+
RequestClass: type[TestRequest]
27+
app: _AppT
28+
lint: bool
29+
relative_to: str | None
30+
extra_environ: dict[str, Any]
31+
use_unicode: bool
32+
cookiejar: CookieJar
33+
JSONEncoder: json.JSONEncoder
34+
__test__: Literal[False]
35+
def __init__(
36+
self,
37+
app: _AppT,
38+
extra_environ: dict[str, Any] | None = None,
39+
relative_to: str | None = None,
40+
use_unicode: bool = True,
41+
cookiejar: CookieJar | None = None,
42+
parser_features: Sequence[str] | str | None = None,
43+
json_encoder: json.JSONEncoder | None = None,
44+
lint: bool = True,
45+
) -> None: ...
46+
def get_authorization(self) -> tuple[str, str | tuple[str, str]]: ...
47+
def set_authorization(self, value: tuple[str, str | tuple[str, str]]) -> None: ...
48+
@property
49+
def authorization(self) -> tuple[str, str | tuple[str, str]]: ...
50+
@authorization.setter
51+
def authorization(self, value: tuple[str, str | tuple[str, str]]) -> None: ...
52+
@property
53+
def cookies(self) -> dict[str, str | None]: ...
54+
def set_cookie(self, name: str, value: str | None) -> None: ...
55+
def reset(self) -> None: ...
56+
def set_parser_features(self, parser_features: Sequence[str] | str) -> None: ...
57+
def get(
58+
self,
59+
url: str,
60+
params: Mapping[str, str] | str | None = None,
61+
headers: Mapping[str, str] | None = None,
62+
extra_environ: Mapping[str, Any] | None = None,
63+
status: int | str | None = None,
64+
expect_errors: bool = False,
65+
xhr: bool = False,
66+
) -> TestResponse: ...
67+
def post(
68+
self,
69+
url: str,
70+
params: Mapping[str, str] | str = "",
71+
headers: Mapping[str, str] | None = None,
72+
extra_environ: Mapping[str, Any] | None = None,
73+
status: int | str | None = None,
74+
upload_files: _Files | None = None,
75+
expect_errors: bool = False,
76+
content_type: str | None = None,
77+
xhr: bool = False,
78+
) -> TestResponse: ...
79+
def put(
80+
self,
81+
url: str,
82+
params: Mapping[str, str] | str = "",
83+
headers: Mapping[str, str] | None = None,
84+
extra_environ: Mapping[str, Any] | None = None,
85+
status: int | str | None = None,
86+
upload_files: _Files | None = None,
87+
expect_errors: bool = False,
88+
content_type: str | None = None,
89+
xhr: bool = False,
90+
) -> TestResponse: ...
91+
def patch(
92+
self,
93+
url: str,
94+
params: Mapping[str, str] | str = "",
95+
headers: Mapping[str, str] | None = None,
96+
extra_environ: Mapping[str, Any] | None = None,
97+
status: int | str | None = None,
98+
upload_files: _Files | None = None,
99+
expect_errors: bool = False,
100+
content_type: str | None = None,
101+
xhr: bool = False,
102+
) -> TestResponse: ...
103+
def delete(
104+
self,
105+
url: str,
106+
params: Mapping[str, str] | str = "",
107+
headers: Mapping[str, str] | None = None,
108+
extra_environ: Mapping[str, Any] | None = None,
109+
status: int | str | None = None,
110+
expect_errors: bool = False,
111+
content_type: str | None = None,
112+
xhr: bool = False,
113+
) -> TestResponse: ...
114+
def options(
115+
self,
116+
url: str,
117+
headers: Mapping[str, str] | None = None,
118+
extra_environ: Mapping[str, Any] | None = None,
119+
status: int | str | None = None,
120+
expect_errors: bool = False,
121+
xhr: bool = False,
122+
) -> TestResponse: ...
123+
def head(
124+
self,
125+
url: str,
126+
params: Mapping[str, str] | str | None = None,
127+
headers: Mapping[str, str] | None = None,
128+
extra_environ: Mapping[str, Any] | None = None,
129+
status: int | str | None = None,
130+
expect_errors: bool = False,
131+
xhr: bool = False,
132+
) -> TestResponse: ...
133+
def post_json(
134+
self,
135+
url: str,
136+
params: Any = ...,
137+
*,
138+
headers: Mapping[str, str] | None = None,
139+
extra_environ: Mapping[str, Any] | None = None,
140+
status: int | str | None = None,
141+
expect_errors: bool = False,
142+
content_type: str | None = None,
143+
xhr: bool = False,
144+
) -> TestResponse: ...
145+
def put_json(
146+
self,
147+
url: str,
148+
params: Any = ...,
149+
*,
150+
headers: Mapping[str, str] | None = None,
151+
extra_environ: Mapping[str, Any] | None = None,
152+
status: int | str | None = None,
153+
expect_errors: bool = False,
154+
content_type: str | None = None,
155+
xhr: bool = False,
156+
) -> TestResponse: ...
157+
def patch_json(
158+
self,
159+
url: str,
160+
params: Any = ...,
161+
*,
162+
headers: Mapping[str, str] | None = None,
163+
extra_environ: Mapping[str, Any] | None = None,
164+
status: int | str | None = None,
165+
expect_errors: bool = False,
166+
content_type: str | None = None,
167+
xhr: bool = False,
168+
) -> TestResponse: ...
169+
def delete_json(
170+
self,
171+
url: str,
172+
params: Any = ...,
173+
*,
174+
headers: Mapping[str, str] | None = None,
175+
extra_environ: Mapping[str, Any] | None = None,
176+
status: int | str | None = None,
177+
expect_errors: bool = False,
178+
content_type: str | None = None,
179+
xhr: bool = False,
180+
) -> TestResponse: ...
181+
def encode_multipart(self, params: Sequence[tuple[str, str]], files: _Files) -> tuple[str, bytes]: ...
182+
def request(
183+
self, url_or_req: str | TestRequest, status: int | str | None = None, expect_errors: bool = False, **req_params: Any
184+
) -> TestResponse: ...
185+
def do_request(
186+
self, req: TestRequest, status: int | str | None = None, expect_errors: bool | None = None
187+
) -> TestResponse: ...

stubs/WebTest/webtest/debugapp.pyi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from _typeshed import StrOrBytesPath
2+
from _typeshed.wsgi import StartResponse, WSGIEnvironment
3+
from collections.abc import Iterable
4+
from typing import TypedDict
5+
from typing_extensions import Unpack
6+
7+
class _DebugAppParams(TypedDict, total=False):
8+
form: StrOrBytesPath | bytes | None
9+
show_form: bool
10+
11+
__all__ = ["DebugApp", "make_debug_app"]
12+
13+
class DebugApp:
14+
form: bytes | None
15+
show_form: bool
16+
def __init__(self, form: StrOrBytesPath | bytes | None = None, show_form: bool = False) -> None: ...
17+
def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ...
18+
19+
debug_app: DebugApp
20+
21+
def make_debug_app(global_conf: object, **local_conf: Unpack[_DebugAppParams]) -> DebugApp: ...

0 commit comments

Comments
 (0)