Skip to content

Commit 84dc20c

Browse files
committed
Types
1 parent 1c87074 commit 84dc20c

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/psc/fixtures.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import builtins
55
from collections.abc import Callable
66
from collections.abc import Generator
7+
from collections.abc import Iterable
78
from dataclasses import dataclass
89
from dataclasses import field
910
from mimetypes import guess_type
@@ -192,7 +193,7 @@ class FakeDocument:
192193

193194

194195
@pytest.fixture
195-
def fake_document() -> FakeDocument:
196+
def fake_document() -> Iterable[FakeDocument]:
196197
"""Yield a document that cleans up."""
197198
yield FakeDocument()
198199

@@ -208,7 +209,7 @@ def write(self, value: str) -> None:
208209
"""Collect anything that is written to the node."""
209210
self.document.log.append(value)
210211

211-
def removeAttribute(self, name) -> None: # noqa
212+
def removeAttribute(self, name: str) -> None: # noqa
212213
"""Pretend to remove an attribute from this node."""
213214
pass
214215

@@ -227,10 +228,10 @@ def __call__(self, key: str) -> ElementNode:
227228

228229

229230
@pytest.fixture
230-
def fake_element(fake_document) -> None:
231+
def fake_element(fake_document: FakeDocument) -> None: # type: ignore [misc]
231232
"""Install the stateful Element into builtins."""
232233
try:
233-
builtins.Element = ElementCallable(fake_document)
234+
builtins.Element = ElementCallable(fake_document) #type: ignore [attr-defined]
234235
yield
235236
finally:
236237
delattr(builtins, "Element")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Say Hello."""
2-
output = Element("output")
2+
output = Element("output") #type: ignore
33
output.write("From Python...")

tests/test_fixtures.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
from psc.fixtures import DummyRequest
1212
from psc.fixtures import DummyResponse
1313
from psc.fixtures import DummyRoute
14+
from psc.fixtures import FakeDocument
1415
from psc.fixtures import MockTestClient
1516
from psc.fixtures import PageT
1617
from psc.fixtures import mocked_client_page
1718
from psc.fixtures import route_handler
1819
from psc.here import STATIC
1920

2021

22+
Element = cast("Unknown", "Element")
23+
2124
def test_test_client(test_client: TestClient) -> None:
2225
"""Ensure fixture returns an initialized TestClient."""
2326
assert test_client.app
@@ -138,32 +141,32 @@ def test_route_handler_fake_bad_path() -> None:
138141
def test_fake_element_not_installed() -> None:
139142
"""We don't request the fixture so it isn't available."""
140143
with pytest.raises(NameError):
141-
Element # noqa
144+
Element # noqa
142145

143146

144-
def test_fake_element_installed(fake_element) -> None:
147+
def test_fake_element_installed(fake_element: function) -> None:
145148
"""Element is available as ``fake_element`` installed it."""
146-
Element # noqa
149+
Element # noqa
147150

148151

149-
def test_fake_element_find_element(fake_document, fake_element) -> None:
152+
def test_fake_element_find_element(fake_document: FakeDocument, fake_element: function) -> None:
150153
"""The Element can get a value from the fake document."""
151154
fake_document.values["btn1"] = "value1"
152155
button = Element("btn1") # noqa
153156
assert button.value == "value1"
154157

155158

156-
def test_fake_element_write(fake_document, fake_element) -> None:
159+
def test_fake_element_write(fake_document: FakeDocument, fake_element: function) -> None:
157160
"""The Element can write a value that is captured."""
158161
fake_document.values["btn1"] = "value1"
159-
button = Element("btn1") # noqa
162+
button = Element("btn1") # noqa
160163
button.write("Some Value")
161164
assert fake_document.log[0] == "Some Value"
162165

163166

164-
def test_fake_element_remove_attribute(fake_document, fake_element) -> None:
167+
def test_fake_element_remove_attribute(fake_document: FakeDocument, fake_element: function) -> None:
165168
"""The Element can pretend to remove an attribute."""
166169
fake_document.values["btn1"] = "value1"
167-
button = Element("btn1") # noqa
170+
button = Element("btn1") # noqa
168171
button.removeAttribute("disabled")
169172
assert fake_document.log == []

0 commit comments

Comments
 (0)