File: test__pydantic.py

package info (click to toggle)
python-pdoc 16.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: python: 5,260; javascript: 1,156; makefile: 18; sh: 3
file content (26 lines) | stat: -rw-r--r-- 930 bytes parent folder | download
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
import pydantic

from pdoc import _pydantic
import pdoc.doc


def test_no_pydantic(monkeypatch):
    monkeypatch.setattr(_pydantic, "pydantic", None)

    assert not _pydantic.is_pydantic_model(pdoc.doc.Module)
    assert _pydantic.get_field_docstring(pdoc.doc.Module, "kind") is None
    assert _pydantic.default_value(pdoc.doc.Module, "kind", "module") == "module"


def test_with_pydantic(monkeypatch):
    class User(pydantic.BaseModel):
        id: int
        name: str = pydantic.Field(description="desc", default="Jane Doe")

    assert _pydantic.is_pydantic_model(User)
    assert _pydantic.get_field_docstring(User, "name") == "desc"
    assert _pydantic.default_value(User, "name", None) == "Jane Doe"

    assert not _pydantic.is_pydantic_model(pdoc.doc.Module)
    assert _pydantic.get_field_docstring(pdoc.doc.Module, "kind") is None
    assert _pydantic.default_value(pdoc.doc.Module, "kind", "module") == "module"