Skip to content

Commit 7ff0016

Browse files
committed
fix: add snapshot, ensure original render tests pass again
1 parent b3bf95b commit 7ff0016

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

quartodoc/renderers/md_renderer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def __init__(
6565
show_signature_annotations: bool = False,
6666
display_name: str = "relative",
6767
hook_pre=None,
68-
use_interlinks=False,
68+
render_interlinks=False,
6969
):
7070
self.header_level = header_level
7171
self.show_signature = show_signature
7272
self.show_signature_annotations = show_signature_annotations
7373
self.display_name = display_name
7474
self.hook_pre = hook_pre
75-
self.use_interlinks = use_interlinks
75+
self.render_interlinks = render_interlinks
7676

7777
self.crnt_header_level = self.header_level
7878

@@ -124,7 +124,10 @@ def render_annotation(self, el: None) -> str:
124124
def render_annotation(self, el: expr.Name) -> str:
125125
# TODO: maybe there is a way to get tabulate to handle this?
126126
# unescaped pipes screw up table formatting
127-
return f"[{sanitize(el.source)}](`{el.full}`)"
127+
if self.render_interlinks:
128+
return f"[{el.source}](`{el.full}`)"
129+
130+
return el.source
128131

129132
@dispatch
130133
def render_annotation(self, el: expr.Expression) -> str:
@@ -468,7 +471,7 @@ def render(self, el: ds.DocstringSectionAttributes):
468471
def render(self, el: ds.DocstringAttribute):
469472
row = [
470473
sanitize(el.name),
471-
self.render_annotation(el.annotation),
474+
sanitize(self.render_annotation(el.annotation)),
472475
sanitize(el.description or "", allow_markdown=True),
473476
]
474477
return row

quartodoc/tests/__snapshots__/test_renderers.ambr

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# serializer version: 1
2+
# name: test_render_annotations_complex
3+
'''
4+
# quartodoc.tests.example_signature.a_complex_signature { #quartodoc.tests.example_signature.a_complex_signature }
5+
6+
`tests.example_signature.a_complex_signature(x)`
7+
'''
8+
# ---
29
# name: test_render_doc_class[embedded]
310
'''
411
# quartodoc.tests.example_class.C { #quartodoc.tests.example_class.C }
@@ -12,10 +19,10 @@
1219

1320
## Parameters
1421

15-
| Name | Type | Description | Default |
16-
|--------|--------------|----------------------|------------|
17-
| `x` | [str](`str`) | Uses signature type. | _required_ |
18-
| `y` | [int](`int`) | Uses manual type. | _required_ |
22+
| Name | Type | Description | Default |
23+
|--------|--------|----------------------|------------|
24+
| `x` | str | Uses signature type. | _required_ |
25+
| `y` | int | Uses manual type. | _required_ |
1926

2027
## Attributes
2128

@@ -51,10 +58,10 @@
5158

5259
## Parameters
5360

54-
| Name | Type | Description | Default |
55-
|--------|--------------|----------------------|------------|
56-
| `x` | [str](`str`) | Uses signature type. | _required_ |
57-
| `y` | [int](`int`) | Uses manual type. | _required_ |
61+
| Name | Type | Description | Default |
62+
|--------|--------|----------------------|------------|
63+
| `x` | str | Uses signature type. | _required_ |
64+
| `y` | int | Uses manual type. | _required_ |
5865

5966
## Attributes
6067

@@ -87,11 +94,11 @@
8794

8895
## Attributes
8996

90-
| Name | Type | Description |
91-
|--------|------------------|---------------------|
92-
| x | [str](`str`) | Uses signature type |
93-
| y | [int](`int`) | Uses manual type |
94-
| z | [float](`float`) | Defined in init |
97+
| Name | Type | Description |
98+
|--------|--------|---------------------|
99+
| x | str | Uses signature type |
100+
| y | int | Uses manual type |
101+
| z | float | Defined in init |
95102
'''
96103
# ---
97104
# name: test_render_doc_module[embedded]

quartodoc/tests/example_signature.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ def early_args(x, *args, a, b=2, **kwargs):
2222

2323
def late_args(x, a, b=2, *args, **kwargs):
2424
...
25+
26+
27+
class C:
28+
...
29+
30+
31+
def a_complex_signature(x: "list[C | int | None]"):
32+
...

quartodoc/tests/test_renderers.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def test_render_param_kwargs(renderer):
1919

2020

2121
def test_render_param_kwargs_annotated():
22-
renderer = MdRenderer()
22+
renderer = MdRenderer(show_signature_annotations=True)
2323
f = get_object("quartodoc.tests.example_signature.yes_annotations")
2424

2525
res = renderer.render(f.parameters)
2626

2727
assert (
2828
res
29-
== "a: int, b: int = 1, *args: list\\[str\\], c: int, d: int, **kwargs: dict\\[str, str\\]"
29+
== "a: int, b: int = 1, *args: list\[str\], c: int, d: int, **kwargs: dict\[str, str\]"
3030
)
3131

3232

@@ -94,14 +94,14 @@ def test_render_doc_attribute(renderer):
9494
attr = ds.DocstringAttribute(
9595
name="abc",
9696
description="xyz",
97-
annotation=exp.Expression(exp.Name("Optional[]", full="Optional")),
97+
annotation=exp.Expression(exp.Name("Optional", full="Optional"), "[", "]"),
9898
value=1,
9999
)
100100

101101
res = renderer.render(attr)
102102
print(res)
103103

104-
assert res == ["abc", r"[Optional\[\]](`Optional`)", "xyz"] # noqa
104+
assert res == ["abc", r"Optional\[\]", "xyz"]
105105

106106

107107
@pytest.mark.parametrize("children", ["embedded", "flat"])
@@ -112,6 +112,14 @@ def test_render_doc_module(snapshot, renderer, children):
112112
assert res == snapshot
113113

114114

115+
def test_render_annotations_complex(snapshot):
116+
renderer = MdRenderer(render_interlinks=True)
117+
bp = blueprint(Auto(name="quartodoc.tests.example_signature.a_complex_signature"))
118+
res = renderer.render(bp)
119+
120+
assert res == snapshot
121+
122+
115123
@pytest.mark.parametrize("children", ["embedded", "flat"])
116124
def test_render_doc_class(snapshot, renderer, children):
117125
bp = blueprint(Auto(name="quartodoc.tests.example_class.C", children=children))

0 commit comments

Comments
 (0)