-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [CI,nox] show the 5 longest tests in pytest output * ignore coverage for impractical use cases * test custom admonitions * test code annotations * test content tabs * test keys role * test syntax highlighting * test task lists * test rst-example directive * test mermaid graphs * improve json domain coverage * test sitemap generation * test inline icons * switch to using codecov
- Loading branch information
Showing
20 changed files
with
640 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
coverage: | ||
status: | ||
patch: | ||
default: | ||
informational: true | ||
project: | ||
default: | ||
target: auto | ||
# adjust accordingly based on how flaky your tests are | ||
# this allows a 2% drop from the previous base commit coverage | ||
threshold: 2% |
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,127 @@ | ||
"""Tests related to theme's patched admonitions.""" | ||
|
||
import pytest | ||
from sphinx.testing.util import SphinxTestApp | ||
from sphinx.errors import ExtensionError | ||
|
||
conf = [ | ||
{ | ||
"name": "legacy", | ||
"color": (236, 64, 11), | ||
"icon": "fontawesome/solid/recycle", | ||
"classes": ["custom-class"], | ||
}, | ||
{ | ||
"name": "attention", | ||
"classes": ["important"], | ||
}, | ||
{ | ||
"name": "versionremoved", | ||
"classes": ["warning"], | ||
"override": True, | ||
}, | ||
{ | ||
"name": "deprecated", | ||
"color": (0, 0, 0), | ||
"override": True, | ||
}, | ||
{ | ||
# This is impractical, but it covers a condition in production code | ||
"name": "versionchanged", | ||
"override": True, | ||
}, | ||
] | ||
|
||
|
||
def test_admonitions(immaterial_make_app): | ||
app: SphinxTestApp = immaterial_make_app( | ||
extra_conf=f"sphinx_immaterial_custom_admonitions={repr(conf)}", | ||
files={ | ||
"index.rst": """ | ||
The Test | ||
======== | ||
.. deprecated:: 0.0.1 scheduled for removal | ||
.. versionremoved:: 0.1.0 Code was removed! | ||
:collapsible: open | ||
:class: custom-class | ||
Some rationale. | ||
.. legacy:: | ||
:collapsible: open | ||
:class: custom-class | ||
Some content. | ||
.. legacy:: A | ||
:title: Custom title | ||
Some content. | ||
""", | ||
}, | ||
) | ||
|
||
app.build() | ||
assert not app._warning.getvalue() # type: ignore[attr-defined] | ||
|
||
|
||
def test_admonition_name_error(immaterial_make_app): | ||
# both exceptions must be raised here, so signify this using nested with statements | ||
with pytest.raises(ExtensionError): | ||
with pytest.raises(ValueError): | ||
immaterial_make_app( | ||
extra_conf="sphinx_immaterial_custom_admonitions=[{" | ||
'"name":"legacy!","classes":["note"]}]', | ||
files={ | ||
"index.rst": "", | ||
}, | ||
) | ||
|
||
|
||
def test_admonitions_warnings(immaterial_make_app): | ||
app: SphinxTestApp = immaterial_make_app( | ||
files={ | ||
"index.rst": """ | ||
The Test | ||
======== | ||
.. note:: | ||
:collapsible: | ||
:no-title: | ||
Some content. | ||
.. deprecated:: 0.1.0 | ||
:collapsible: | ||
""", | ||
}, | ||
) | ||
|
||
app.build() | ||
warnings = app._warning.getvalue() # type: ignore[attr-defined] | ||
assert warnings | ||
assert "title is needed for collapsible admonitions" in warnings | ||
assert "Expected 2 arguments before content in deprecated directive" in warnings | ||
|
||
|
||
def test_todo_admonition(immaterial_make_app): | ||
app: SphinxTestApp = immaterial_make_app( | ||
extra_conf="extensions.append('sphinx.ext.todo')", | ||
files={ | ||
"index.rst": """ | ||
The Test | ||
======== | ||
.. todo:: | ||
Some content. | ||
""", | ||
}, | ||
) | ||
|
||
app.build() | ||
assert not app._warning.getvalue() # type: ignore[attr-defined] |
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,50 @@ | ||
"""Tests related to theme's code block annotations.""" | ||
|
||
from sphinx.testing.util import SphinxTestApp | ||
|
||
index_rst = """ | ||
The Test | ||
======== | ||
.. code-block:: yaml | ||
:caption: A caption for good measure | ||
# (1)! | ||
.. code-annotations:: | ||
1. An annotation | ||
.. code-annotations:: | ||
#. A regular list not used in annotations. | ||
.. code-block:: python | ||
# A normal code block without annotations | ||
""" | ||
|
||
|
||
def test_code_annotation(immaterial_make_app): | ||
app: SphinxTestApp = immaterial_make_app( | ||
files={"index.rst": index_rst}, | ||
) | ||
|
||
app.build() | ||
assert not app._warning.getvalue() # type: ignore[attr-defined] | ||
|
||
def test_code_annotation_error(immaterial_make_app): | ||
app: SphinxTestApp = immaterial_make_app( | ||
files={ | ||
"index.rst": """ | ||
The Test | ||
======== | ||
.. code-annotations:: | ||
This is not an enumerated list! | ||
"""}, | ||
) | ||
|
||
app.build() | ||
warnings = app._warning.getvalue() # type: ignore[attr-defined] | ||
assert warnings | ||
assert "The code-annotations directive only accepts an enumerated list" in warnings |
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,70 @@ | ||
"""Tests related to theme's content tabs.""" | ||
|
||
from docutils.nodes import Node | ||
import pytest | ||
from sphinx.testing.util import SphinxTestApp | ||
from sphinx_immaterial.content_tabs import is_md_tab_type | ||
|
||
index_rst = """ | ||
The Test | ||
======== | ||
.. md-tab-set:: | ||
:name: tab_set_ref | ||
.. md-tab-item:: A | ||
Tab A content | ||
.. md-tab-item:: B | ||
Tab B content | ||
""" | ||
|
||
|
||
def test_content_tabs(immaterial_make_app): | ||
app: SphinxTestApp = immaterial_make_app( | ||
files={"index.rst": index_rst}, | ||
) | ||
|
||
app.build() | ||
assert not app._warning.getvalue() # type: ignore[attr-defined] | ||
|
||
def test_tab_ext_error(): | ||
assert not is_md_tab_type(Node(), "") | ||
|
||
def test_tab_set_child_error(immaterial_make_app): | ||
app: SphinxTestApp = immaterial_make_app( | ||
files={ | ||
"index.rst": """ | ||
The Test | ||
======== | ||
.. md-tab-set:: | ||
This is not a ``md-tab-item``! | ||
"""}, | ||
) | ||
|
||
with pytest.raises(ValueError): | ||
app.build() | ||
warnings = app._warning.getvalue() # type: ignore[attr-defined] | ||
assert warnings | ||
assert "All children of a 'md-tab-set' should be 'md-tab-item'" in warnings | ||
|
||
def test_tab_item_parent_error(immaterial_make_app): | ||
app: SphinxTestApp = immaterial_make_app( | ||
files={ | ||
"index.rst": """ | ||
The Test | ||
======== | ||
.. md-tab-item:: Orphan | ||
This is ``md-tab-item`` has no parent ``md-tab-set``! | ||
"""}, | ||
) | ||
app.build() | ||
warnings = app._warning.getvalue() # type: ignore[attr-defined] | ||
assert warnings | ||
assert "The parent of a 'md-tab-item' should be a 'md-tab-set'" in warnings |
Oops, something went wrong.