Skip to content

Commit 498e153

Browse files
committed
One more blacken-docs test, refs #1718
1 parent 92b2667 commit 498e153

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

docs/testing_plugins.rst

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ If you use the template described in :ref:`writing_plugins_cookiecutter` your pl
1919
response = await datasette.client.get("/-/plugins.json")
2020
assert response.status_code == 200
2121
installed_plugins = {p["name"] for p in response.json()}
22-
assert "datasette-plugin-template-demo" in installed_plugins
22+
assert (
23+
"datasette-plugin-template-demo"
24+
in installed_plugins
25+
)
2326
2427
2528
This test uses the :ref:`internals_datasette_client` object to exercise a test instance of Datasette. ``datasette.client`` is a wrapper around the `HTTPX <https://www.python-httpx.org/>`__ Python library which can imitate HTTP requests using ASGI. This is the recommended way to write tests against a Datasette instance.
@@ -37,9 +40,7 @@ If you are building an installable package you can add them as test dependencies
3740
setup(
3841
name="datasette-my-plugin",
3942
# ...
40-
extras_require={
41-
"test": ["pytest", "pytest-asyncio"]
42-
},
43+
extras_require={"test": ["pytest", "pytest-asyncio"]},
4344
tests_require=["datasette-my-plugin[test]"],
4445
)
4546
@@ -87,31 +88,34 @@ Here's an example that uses the `sqlite-utils library <https://sqlite-utils.data
8788
import pytest
8889
import sqlite_utils
8990
91+
9092
@pytest.fixture(scope="session")
9193
def datasette(tmp_path_factory):
9294
db_directory = tmp_path_factory.mktemp("dbs")
9395
db_path = db_directory / "test.db"
9496
db = sqlite_utils.Database(db_path)
95-
db["dogs"].insert_all([
96-
{"id": 1, "name": "Cleo", "age": 5},
97-
{"id": 2, "name": "Pancakes", "age": 4}
98-
], pk="id")
97+
db["dogs"].insert_all(
98+
[
99+
{"id": 1, "name": "Cleo", "age": 5},
100+
{"id": 2, "name": "Pancakes", "age": 4},
101+
],
102+
pk="id",
103+
)
99104
datasette = Datasette(
100105
[db_path],
101106
metadata={
102107
"databases": {
103108
"test": {
104109
"tables": {
105-
"dogs": {
106-
"title": "Some dogs"
107-
}
110+
"dogs": {"title": "Some dogs"}
108111
}
109112
}
110113
}
111-
}
114+
},
112115
)
113116
return datasette
114117
118+
115119
@pytest.mark.asyncio
116120
async def test_example_table_json(datasette):
117121
response = await datasette.client.get("/test/dogs.json?_shape=array")
@@ -121,6 +125,7 @@ Here's an example that uses the `sqlite-utils library <https://sqlite-utils.data
121125
{"id": 2, "name": "Pancakes", "age": 4},
122126
]
123127
128+
124129
@pytest.mark.asyncio
125130
async def test_example_table_html(datasette):
126131
response = await datasette.client.get("/test/dogs")
@@ -137,6 +142,7 @@ If you want to create that test database repeatedly for every individual test fu
137142
@pytest.fixture
138143
def datasette(tmp_path_factory):
139144
# This fixture will be executed repeatedly for every test
145+
...
140146
141147
.. _testing_plugins_pytest_httpx:
142148

@@ -197,14 +203,17 @@ Here's a test for that plugin that mocks the HTTPX outbound request:
197203
198204
async def test_outbound_http_call(httpx_mock):
199205
httpx_mock.add_response(
200-
url='https://www.example.com/',
201-
text='Hello world',
206+
url="https://www.example.com/",
207+
text="Hello world",
202208
)
203209
datasette = Datasette([], memory=True)
204-
response = await datasette.client.post("/-/fetch-url", data={
205-
"url": "https://www.example.com/"
206-
})
210+
response = await datasette.client.post(
211+
"/-/fetch-url",
212+
data={"url": "https://www.example.com/"},
213+
)
207214
assert response.text == "Hello world"
208215
209216
outbound_request = httpx_mock.get_request()
210-
assert outbound_request.url == "https://www.example.com/"
217+
assert (
218+
outbound_request.url == "https://www.example.com/"
219+
)

0 commit comments

Comments
 (0)