Skip to content

Commit 47877c0

Browse files
committed
fixup
1 parent cffe44d commit 47877c0

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

test/test__pydantic.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ def test_no_pydantic(monkeypatch):
1212
assert _pydantic.default_value(pdoc.doc.Module, "kind", "module") == "module"
1313

1414

15-
def test_with_pydantic(monkeypatch):
16-
class User(pydantic.BaseModel):
17-
id: int
18-
name: str = pydantic.Field(description="desc", default="Jane Doe")
15+
class ExampleModel(pydantic.BaseModel):
16+
id: int
17+
name: str = pydantic.Field(description="desc", default="Jane Doe")
18+
1919

20-
assert _pydantic.is_pydantic_model(User)
21-
assert _pydantic.get_field_docstring(User, "name") == "desc"
22-
assert _pydantic.default_value(User, "name", None) == "Jane Doe"
20+
def test_with_pydantic(monkeypatch):
21+
assert _pydantic.is_pydantic_model(ExampleModel)
22+
assert _pydantic.get_field_docstring(ExampleModel, "name") == "desc"
23+
assert _pydantic.default_value(ExampleModel, "name", None) == "Jane Doe"
2324

2425
assert not _pydantic.is_pydantic_model(pdoc.doc.Module)
2526
assert _pydantic.get_field_docstring(pdoc.doc.Module, "kind") is None

test/test_search.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88
here = Path(__file__).parent
99

1010

11+
def test_node_executable(monkeypatch):
12+
monkeypatch.setattr(
13+
shutil, "which", lambda x: "/usr/bin/nodejs" if x == "nodejs" else None
14+
)
15+
search.node_executable.cache_clear()
16+
assert search.node_executable() == "nodejs"
17+
18+
monkeypatch.setattr(
19+
shutil, "which", lambda x: "/usr/bin/node" if x == "node" else None
20+
)
21+
search.node_executable.cache_clear()
22+
assert search.node_executable() == "node"
23+
24+
monkeypatch.setattr(shutil, "which", lambda _: None)
25+
search.node_executable.cache_clear()
26+
assert search.node_executable() is None
27+
28+
1129
def test_precompile_index(monkeypatch, capsys):
1230
docs = [
1331
{
@@ -18,28 +36,25 @@ def test_precompile_index(monkeypatch, capsys):
1836
"doc": "a" * 3 * 1024 * 1024, # we only warn if index size is meaningful.
1937
}
2038
]
39+
raw = json.dumps(docs)
2140
compile_js = here / ".." / "pdoc" / "templates" / "build-search-index.js"
2241

2342
monkeypatch.setattr(subprocess, "check_output", lambda *_, **__: '{"foo": 42}')
43+
monkeypatch.setattr(search, "node_executable", lambda: "nodejs")
2444
assert (
2545
search.precompile_index(docs, compile_js)
2646
== '{"foo": 42, "_isPrebuiltIndex": true}'
2747
)
2848

29-
monkeypatch.setattr(search, "node_executable", lambda: "C:\\nodejs.exe")
30-
assert (
31-
search.precompile_index(docs, compile_js)
32-
== '{"foo": 42, "_isPrebuiltIndex": true}'
33-
)
3449
monkeypatch.setattr(search, "node_executable", lambda: None)
35-
assert (
36-
search.precompile_index(docs, compile_js)
37-
== json.dumps(docs)
38-
)
50+
assert search.precompile_index(docs, compile_js) == raw
3951

4052
def _raise(*_, **__):
4153
raise subprocess.CalledProcessError(-1, ["cmd"], b"nodejs error")
4254

55+
monkeypatch.setattr(search, "node_executable", lambda: "node")
4356
monkeypatch.setattr(subprocess, "check_output", _raise)
44-
assert search.precompile_index(docs, compile_js) == json.dumps(docs)
45-
assert "pdoc failed to precompile the search index" in capsys.readouterr().out
57+
assert search.precompile_index(docs, compile_js) == raw
58+
out = capsys.readouterr().out
59+
assert "pdoc failed to precompile the search index" in out
60+
assert "Node.js Output" in out

test/test_snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_snapshots(snapshot: Snapshot, format: str, monkeypatch):
190190

191191
if __name__ == "__main__":
192192
warnings.simplefilter("error")
193-
pdoc.search.node_executable = lambda: None
193+
pdoc.search.node_executable = lambda: None # type: ignore
194194
os.chdir(snapshot_dir)
195195
skipped_some = False
196196
for snapshot in snapshots:

0 commit comments

Comments
 (0)