/
conftest.py
78 lines (64 loc) · 2.01 KB
/
conftest.py
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
import json
import typing as t
import pytest
from jupyter_server.serverapp import ServerApp
from tornado.httpclient import HTTPResponse
from jupyterlab_code_formatter import load_jupyter_server_extension
pytest_plugins = ["jupyter_server.pytest_plugin"]
@pytest.fixture(autouse=True)
def jcf_serverapp(jp_serverapp: ServerApp) -> ServerApp:
load_jupyter_server_extension(jp_serverapp)
return jp_serverapp
@pytest.fixture
def request_format(jp_fetch): # type: ignore[no-untyped-def]
def do_request(
formatter: str,
code: t.List[str],
options: t.Dict[str, t.Any],
headers: t.Optional[t.Dict[str, t.Any]] = None,
**kwargs: t.Any,
) -> HTTPResponse:
return jp_fetch( # type: ignore[no-any-return]
"jupyterlab_code_formatter",
"format",
method="POST",
body=json.dumps(
{
"code": code,
"options": options,
"notebook": True,
"formatter": formatter,
}
),
headers=headers,
**kwargs,
)
return do_request
@pytest.fixture
def request_list_formatters(jp_fetch): # type: ignore[no-untyped-def]
def do_request(
headers: t.Optional[t.Dict[str, t.Any]] = None,
**kwargs: t.Any,
) -> HTTPResponse:
return jp_fetch( # type: ignore[no-any-return]
"jupyterlab_code_formatter",
"formatters",
method="GET",
headers=headers,
**kwargs,
)
return do_request
@pytest.fixture
def request_version(jp_fetch): # type: ignore[no-untyped-def]
def do_request(
headers: t.Optional[t.Dict[str, t.Any]] = None,
**kwargs: t.Any,
) -> HTTPResponse:
return jp_fetch( # type: ignore[no-any-return]
"jupyterlab_code_formatter",
"version",
method="GET",
headers=headers,
**kwargs,
)
return do_request