-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from machow/dev-pydantic-compat
Dev pydantic compat
- Loading branch information
Showing
16 changed files
with
188 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
try: | ||
from pydantic.v1 import ( | ||
BaseModel, | ||
Field, | ||
Extra, | ||
PrivateAttr, | ||
ValidationError, | ||
) # noqa | ||
except ImportError: | ||
from pydantic import BaseModel, Field, Extra, PrivateAttr, ValidationError # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# serializer version: 1 | ||
# name: test_misplaced_kindpage | ||
''' | ||
Code: | ||
|
||
quartodoc: | ||
package: zzz | ||
sections: | ||
- kind: page | ||
|
||
|
||
Error: | ||
Configuration error for YAML: | ||
- Missing field `path` for element 0 in the list for `sections`, which you need when setting `kind: page`. | ||
|
||
''' | ||
# --- | ||
# name: test_missing_name_contents | ||
''' | ||
Code: | ||
|
||
quartodoc: | ||
package: zzz | ||
sections: | ||
- title: Section 1 | ||
- title: Section 2 | ||
contents: | ||
|
||
# name missing here ---- | ||
- children: linked | ||
|
||
- name: MdRenderer | ||
|
||
Error: | ||
Configuration error for YAML: | ||
- Missing field `name` for element 0 in the list for `contents` located in element 1 in the list for `sections` | ||
|
||
''' | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,57 @@ | ||
import copy | ||
import pytest | ||
import yaml | ||
|
||
from textwrap import indent, dedent | ||
|
||
from quartodoc.autosummary import Builder | ||
|
||
EXAMPLE_SECTIONS = [ | ||
{ | ||
"title": "Preperation Functions", | ||
"desc": "Functions that fetch objects.\nThey prepare a representation of the site.\n", | ||
"contents": ["Auto", "blueprint", "collect", "get_object", "preview"], | ||
}, | ||
{ | ||
"title": "Docstring Renderers", | ||
"desc": "Renderers convert parsed docstrings into a target format, like markdown.\n", | ||
"contents": [ | ||
{"name": "MdRenderer", "children": "linked"}, | ||
{"name": "MdRenderer.render", "dynamic": True}, | ||
{"name": "MdRenderer.render_annotation", "dynamic": True}, | ||
{"name": "MdRenderer.render_header", "dynamic": True}, | ||
], | ||
}, | ||
{ | ||
"title": "API Builders", | ||
"desc": "Builders build documentation. They tie all the pieces\nof quartodoc together.\n", | ||
"contents": [ | ||
{"kind": "auto", "name": "Builder", "members": []}, | ||
"Builder.from_quarto_config", | ||
"Builder.build", | ||
"Builder.write_index", | ||
], | ||
}, | ||
] | ||
|
||
|
||
@pytest.fixture | ||
def sections(): | ||
return copy.deepcopy(EXAMPLE_SECTIONS) | ||
|
||
|
||
def check_ValueError(sections): | ||
|
||
def check_ValueError(cfg: str): | ||
"Check that a ValueError is raised when creating a `Builder` instance. Return the error message as a string." | ||
|
||
d = yaml.safe_load(cfg) | ||
with pytest.raises(ValueError) as e: | ||
Builder(sections=sections, package="quartodoc") | ||
return str(e.value) | ||
Builder.from_quarto_config(d) | ||
|
||
fmt_cfg = indent(dedent(cfg), " " * 4) | ||
fmt_value = indent(str(e.value), " " * 4) | ||
return f"""\ | ||
Code:\n{fmt_cfg} | ||
Error:\n{fmt_value} | ||
""" | ||
|
||
def test_valid_yaml(sections): | ||
"Test that valid YAML passes validation" | ||
Builder(sections=sections, package="quartodoc") | ||
|
||
def test_missing_name_contents(snapshot): | ||
"Test that a missing name in contents raises an error in a different section." | ||
|
||
def test_missing_name_contents_1(sections): | ||
"Test that a missing name in contents raises an error" | ||
del sections[2]["contents"][0]["name"] | ||
msg = check_ValueError(sections) | ||
assert ( | ||
"- Missing field `name` for element 0 in the list for `contents` located in element 2 in the list for `sections`" | ||
in msg | ||
) | ||
cfg = """ | ||
quartodoc: | ||
package: zzz | ||
sections: | ||
- title: Section 1 | ||
- title: Section 2 | ||
contents: | ||
# name missing here ---- | ||
- children: linked | ||
def test_missing_name_contents_2(sections): | ||
"Test that a missing name in contents raises an error in a different section." | ||
del sections[1]["contents"][0]["name"] | ||
msg = check_ValueError(sections) | ||
assert ( | ||
"- Missing field `name` for element 0 in the list for `contents` located in element 1 in the list for `sections`" | ||
in msg | ||
) | ||
- name: MdRenderer | ||
""" | ||
|
||
msg = check_ValueError(cfg) | ||
assert msg == snapshot | ||
|
||
def test_misplaced_kindpage(sections): | ||
|
||
def test_misplaced_kindpage(snapshot): | ||
"Test that a misplaced kind: page raises an error" | ||
sections[0]["kind"] = "page" | ||
msg = check_ValueError(sections) | ||
assert ( | ||
" - Missing field `path` for element 0 in the list for `sections`, which you need when setting `kind: page`." | ||
in msg | ||
) | ||
|
||
cfg = """ | ||
quartodoc: | ||
package: zzz | ||
sections: | ||
- kind: page | ||
""" | ||
|
||
msg = check_ValueError(cfg) | ||
assert msg == snapshot |
Oops, something went wrong.