|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import pytest |
5 | 6 | from docutils import nodes |
6 | 7 |
|
7 | 8 | from sphinx import addnodes |
@@ -365,12 +366,12 @@ def test_pyproperty(app): |
365 | 366 | def test_pytypealias(app): |
366 | 367 | text = (".. py:module:: example\n" |
367 | 368 | ".. py:type:: Alias1\n" |
368 | | - " :value: list[str | int]\n" |
| 369 | + " :canonical: list[str | int]\n" |
369 | 370 | "\n" |
370 | 371 | ".. py:class:: Class\n" |
371 | 372 | "\n" |
372 | 373 | " .. py:type:: Alias2\n" |
373 | | - " :value: int\n") |
| 374 | + " :canonical: int\n") |
374 | 375 | domain = app.env.get_domain('py') |
375 | 376 | doctree = restructuredtext.parse(app, text) |
376 | 377 | assert_node(doctree, (addnodes.index, |
@@ -413,6 +414,25 @@ def test_pytypealias(app): |
413 | 414 | assert domain.objects['example.Class.Alias2'] == ('index', 'example.Class.Alias2', 'type', False) |
414 | 415 |
|
415 | 416 |
|
| 417 | +@pytest.mark.sphinx('html', testroot='domain-py', freshenv=True) |
| 418 | +def test_domain_py_type_alias(app, status, warning): |
| 419 | + app.build(force_all=True) |
| 420 | + |
| 421 | + content = (app.outdir / 'type_alias.html').read_text(encoding='utf8') |
| 422 | + assert ('<em class="property"><span class="pre">type</span><span class="w"> </span></em>' |
| 423 | + '<span class="sig-prename descclassname"><span class="pre">module_one.</span></span>' |
| 424 | + '<span class="sig-name descname"><span class="pre">MyAlias</span></span>' |
| 425 | + '<em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span>' |
| 426 | + '<span class="w"> </span><span class="pre">list</span>' |
| 427 | + '<span class="p"><span class="pre">[</span></span>' |
| 428 | + '<span class="pre">int</span><span class="w"> </span>' |
| 429 | + '<span class="p"><span class="pre">|</span></span><span class="w"> </span>' |
| 430 | + '<a class="reference internal" href="#module_two.SomeClass" title="module_two.SomeClass">' |
| 431 | + '<span class="pre">module_two.SomeClass</span></a>' |
| 432 | + '<span class="p"><span class="pre">]</span></span></em>' in content) |
| 433 | + assert warning.getvalue() == '' |
| 434 | + |
| 435 | + |
416 | 436 | def test_pydecorator_signature(app): |
417 | 437 | text = ".. py:decorator:: deco" |
418 | 438 | domain = app.env.get_domain('py') |
|
0 commit comments