|
1 |
| -import pytest, copy |
| 1 | +import copy |
| 2 | +import pytest |
| 3 | + |
2 | 4 | from quartodoc.autosummary import Builder
|
3 | 5 |
|
4 | 6 | EXAMPLE_SECTIONS = [
|
5 |
| - {'title': 'Preperation Functions', |
6 |
| - 'desc': 'Functions that fetch objects.\nThey prepare a representation of the site.\n', |
7 |
| - 'contents': ['Auto', 'blueprint', 'collect', 'get_object', 'preview']}, |
8 |
| - {'title': 'Docstring Renderers', |
9 |
| - 'desc': 'Renderers convert parsed docstrings into a target format, like markdown.\n', |
10 |
| - 'contents': [{'name': 'MdRenderer', 'children': 'linked'}, |
11 |
| - {'name': 'MdRenderer.render', 'dynamic': True}, |
12 |
| - {'name': 'MdRenderer.render_annotation', 'dynamic': True}, |
13 |
| - {'name': 'MdRenderer.render_header', 'dynamic': True}] |
14 |
| - }, |
15 |
| - {'title': 'API Builders', |
16 |
| - 'desc': 'Builders build documentation. They tie all the pieces\nof quartodoc together.\n', |
17 |
| - 'contents': [{'kind': 'auto', 'name': 'Builder', 'members': []}, |
18 |
| - 'Builder.from_quarto_config', 'Builder.build', 'Builder.write_index'] |
19 |
| - }, |
20 |
| - ] |
| 7 | + { |
| 8 | + "title": "Preperation Functions", |
| 9 | + "desc": "Functions that fetch objects.\nThey prepare a representation of the site.\n", |
| 10 | + "contents": ["Auto", "blueprint", "collect", "get_object", "preview"], |
| 11 | + }, |
| 12 | + { |
| 13 | + "title": "Docstring Renderers", |
| 14 | + "desc": "Renderers convert parsed docstrings into a target format, like markdown.\n", |
| 15 | + "contents": [ |
| 16 | + {"name": "MdRenderer", "children": "linked"}, |
| 17 | + {"name": "MdRenderer.render", "dynamic": True}, |
| 18 | + {"name": "MdRenderer.render_annotation", "dynamic": True}, |
| 19 | + {"name": "MdRenderer.render_header", "dynamic": True}, |
| 20 | + ], |
| 21 | + }, |
| 22 | + { |
| 23 | + "title": "API Builders", |
| 24 | + "desc": "Builders build documentation. They tie all the pieces\nof quartodoc together.\n", |
| 25 | + "contents": [ |
| 26 | + {"kind": "auto", "name": "Builder", "members": []}, |
| 27 | + "Builder.from_quarto_config", |
| 28 | + "Builder.build", |
| 29 | + "Builder.write_index", |
| 30 | + ], |
| 31 | + }, |
| 32 | +] |
| 33 | + |
21 | 34 |
|
22 | 35 | @pytest.fixture
|
23 | 36 | def sections():
|
24 | 37 | return copy.deepcopy(EXAMPLE_SECTIONS)
|
25 | 38 |
|
| 39 | + |
26 | 40 | def check_ValueError(sections):
|
27 | 41 | "Check that a ValueError is raised when creating a `Builder` instance. Return the error message as a string."
|
28 | 42 | with pytest.raises(ValueError) as e:
|
29 |
| - Builder(sections=sections, package='quartodoc') |
| 43 | + Builder(sections=sections, package="quartodoc") |
30 | 44 | return str(e.value)
|
31 | 45 |
|
| 46 | + |
32 | 47 | def test_valid_yaml(sections):
|
33 | 48 | "Test that valid YAML passes validation"
|
34 |
| - Builder(sections=sections, package='quartodoc') |
| 49 | + Builder(sections=sections, package="quartodoc") |
35 | 50 |
|
36 |
| -def test_missing_title(sections): |
37 |
| - "Test that missing title raises an error" |
38 |
| - del sections[0]['title'] |
39 |
| - msg = check_ValueError(sections) |
40 |
| - assert '- Missing field `title` for element 0 in the list for `sections`' in msg |
41 |
| - |
42 |
| -def test_missing_desc(sections): |
43 |
| - "Test that a missing description raises an error" |
44 |
| - sections = copy.deepcopy(EXAMPLE_SECTIONS) |
45 |
| - del sections[2]['desc'] |
46 |
| - msg = check_ValueError(sections) |
47 |
| - assert '- Missing field `desc` for element 2 in the list for `sections`' in msg |
48 | 51 |
|
49 | 52 | def test_missing_name_contents_1(sections):
|
50 | 53 | "Test that a missing name in contents raises an error"
|
51 |
| - del sections[2]['contents'][0]['name'] |
| 54 | + del sections[2]["contents"][0]["name"] |
52 | 55 | msg = check_ValueError(sections)
|
53 |
| - assert '- Missing field `name` for element 0 in the list for `contents` located in element 2 in the list for `sections`' in msg |
| 56 | + assert ( |
| 57 | + "- Missing field `name` for element 0 in the list for `contents` located in element 2 in the list for `sections`" |
| 58 | + in msg |
| 59 | + ) |
| 60 | + |
54 | 61 |
|
55 | 62 | def test_missing_name_contents_2(sections):
|
56 | 63 | "Test that a missing name in contents raises an error in a different section."
|
57 |
| - del sections[1]['contents'][0]['name'] |
| 64 | + del sections[1]["contents"][0]["name"] |
58 | 65 | msg = check_ValueError(sections)
|
59 |
| - assert '- Missing field `name` for element 0 in the list for `contents` located in element 1 in the list for `sections`' in msg |
| 66 | + assert ( |
| 67 | + "- Missing field `name` for element 0 in the list for `contents` located in element 1 in the list for `sections`" |
| 68 | + in msg |
| 69 | + ) |
| 70 | + |
60 | 71 |
|
61 | 72 | def test_misplaced_kindpage(sections):
|
62 | 73 | "Test that a misplaced kind: page raises an error"
|
63 |
| - sections[0]['kind'] = 'page' |
| 74 | + sections[0]["kind"] = "page" |
64 | 75 | msg = check_ValueError(sections)
|
65 |
| - assert ' - Missing field `path` for element 0 in the list for `sections`, which you need when setting `kind: page`.' in msg |
| 76 | + assert ( |
| 77 | + " - Missing field `path` for element 0 in the list for `sections`, which you need when setting `kind: page`." |
| 78 | + in msg |
| 79 | + ) |
0 commit comments