Skip to content

Commit fe60208

Browse files
authored
Merge pull request #5 from Zsailer/docs
Add basic documentation pages.
2 parents ce5d9de + f39f7a5 commit fe60208

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

docs/index.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# pytest-jupyter
2+
3+
A set of [pytest plugins](https://docs.pytest.org/en/stable/plugins.html) for Jupyter libraries and extensions.
4+
5+
## Basic Usage
6+
7+
Install `pytest-jupyter` from PyPI using pip:
8+
```
9+
pip install pytest-jupyter
10+
```
11+
12+
Once it's installed, all fixtures from `pytest-jupyter` will be discoverable by Pytest. Pass any fixture to your unit test function to begin using it, like so:
13+
14+
```python
15+
async def test_jupyter_server_api(jp_fetch):
16+
# Send request to a temporary Jupyter Server Web Application
17+
response = await jp_fetch("api/spec.yml")
18+
19+
# Confirm that the request is successful.
20+
assert response.code == 200
21+
```
22+
23+
24+
```{toctree}
25+
:maxdepth: 2
26+
:hidden:
27+
28+
Core <plugins/jupyter_core>
29+
Server <plugins/jupyter_server>
30+
31+
```
32+
33+
## Search
34+
35+
* {ref}`genindex`
36+
* {ref}`modindex`
37+
* {ref}`search`

docs/plugins/jupyter_core.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Jupyter Core plugin
2+
3+
The following fixtures are useful for setting up a test environment for Jupyter extensions and applications.
4+
5+
## Fixtures
6+
7+
```{eval-rst}
8+
.. automodule:: pytest_jupyter.jupyter_core
9+
:members:
10+
```

docs/plugins/jupyter_server.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Jupyter Server plugin
2+
3+
The jupyter_server module provides fixtures for automatically setting-up/tearing-down Jupyter Servers.
4+
5+
You can make requests to a *test server* using the `jp_fetch` and `jp_ws_fetch` fixtures.
6+
7+
## Fixtures
8+
9+
```{eval-rst}
10+
.. automodule:: pytest_jupyter.jupyter_server
11+
:members:
12+
```

pytest_jupyter/jupyter_server.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,19 @@ def jp_base_url():
195195

196196
@pytest.fixture
197197
def jp_fetch(http_server_client, jp_auth_header, jp_base_url):
198-
"""Performs an HTTP request against the test server."""
198+
"""Sends an (asynchronous) HTTP request to a test server.
199+
200+
The fixture is a factory; it can be called like
201+
a function inside a unit test. Here's a basic
202+
example of how use this fixture:
203+
204+
.. code-block:: python
205+
206+
async def my_test(jp_fetch):
207+
208+
response = await jp_fetch("api", "spec.yaml")
209+
...
210+
"""
199211
def client_fetch(*parts, headers={}, params={}, **kwargs):
200212
# Handle URL strings
201213
path_url = url_escape(url_path_join(jp_base_url, *parts), plus=False)
@@ -212,7 +224,31 @@ def client_fetch(*parts, headers={}, params={}, **kwargs):
212224

213225
@pytest.fixture
214226
def jp_ws_fetch(jp_auth_header, jp_http_port):
215-
"""Performs a websocket request against the test server."""
227+
"""Sends a websocket request to a test server.
228+
229+
The fixture is a factory; it can be called like
230+
a function inside a unit test. Here's a basic
231+
example of how use this fixture:
232+
233+
.. code-block:: python
234+
235+
async def my_test(jp_fetch, jp_ws_fetch):
236+
# Start a kernel
237+
r = await jp_fetch(
238+
'api', 'kernels',
239+
method='POST',
240+
body=json.dumps({
241+
'name': "python3"
242+
})
243+
)
244+
kid = json.loads(r.body.decode())['id']
245+
246+
# Open a websocket connection.
247+
ws = await jp_ws_fetch(
248+
'api', 'kernels', kid, 'channels'
249+
)
250+
...
251+
"""
216252
def client_fetch(*parts, headers={}, params={}, **kwargs):
217253
# Handle URL strings
218254
path = url_escape(url_path_join(*parts), plus=False)

0 commit comments

Comments
 (0)