forked from sphinx-contrib/datatemplates
-
Notifications
You must be signed in to change notification settings - Fork 1
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 sphinx-contrib#99 from Bizordec/master
handle directive exceptions
- Loading branch information
Showing
53 changed files
with
343 additions
and
39 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 |
---|---|---|
@@ -1 +1,23 @@ | ||
import pytest | ||
|
||
from pathlib import Path | ||
from sphinx import version_info as sphinx_version_info | ||
|
||
pytest_plugins = "sphinx.testing.fixtures" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def rootdir(): | ||
""" | ||
Fixture for 'pytest.mark.sphinx'. | ||
Test data is stored in the 'testdata/test-<testroot>'. | ||
""" | ||
if sphinx_version_info >= (7, 2): | ||
abs_path = Path(__file__).parent.absolute() | ||
else: | ||
from sphinx.testing.path import path | ||
|
||
abs_path = path(__file__).parent.abspath() | ||
|
||
return abs_path / "testdata" |
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,125 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
import pytest | ||
|
||
if TYPE_CHECKING: | ||
from io import StringIO | ||
from sphinx.testing.util import SphinxTestApp | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="empty-source") | ||
def test_empty_source(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: ERROR: Source file is required" | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="nonexistent-source") | ||
def test_nonexisting_source(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Source file 'sample1.json' not found" | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="empty-template") | ||
def test_empty_template(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: ERROR: Template is empty" | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="nonexistent-template") | ||
def test_nonexistent_template(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Template file 'sample1.tmpl' not found" | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="nonexistent-template-filter") | ||
def test_nonexistent_template_filter(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Error in template file 'sample.tmpl' line 1: " | ||
"No filter named 'some_filter'." | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="incorrect-template-syntax") | ||
def test_incorrect_template_syntax(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Error in template file 'sample.tmpl' line 1: " | ||
"unexpected '}'" | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="incorrect-json-syntax") | ||
def test_incorrect_json_syntax(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Error in source 'sample.json': " | ||
"Invalid control character at: line 2 column 28 (char 29)" | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="incorrect-yaml-syntax") | ||
def test_incorrect_yaml_syntax(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Error in source 'sample.yaml': " | ||
"while parsing a block collection\n" | ||
' in "sample.yaml", line 11, column 3\n' | ||
"expected <block end>, but found '?'\n" | ||
' in "sample.yaml", line 12, column 3' | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="incorrect-xml-syntax") | ||
def test_incorrect_xml_syntax(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Error in source 'sample.xml': " | ||
"not well-formed (invalid token): line 2, column 4" | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="incorrect-import-module") | ||
def test_incorrect_import_module(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Error in source 'some_module': No module named 'some_module'" | ||
) | ||
assert expected_error_str in warning.getvalue() | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="incorrect-dbm") | ||
def test_incorrect_dbm(app: SphinxTestApp, warning: StringIO): | ||
app.builder.build_all() | ||
expected_error_str = ( | ||
f"{app.srcdir / 'index.rst'}:1: " | ||
"ERROR: Error in source 'sampledbm': " | ||
"db type could not be determined" | ||
) | ||
assert expected_error_str in warning.getvalue() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,2 @@ | ||
extensions = ["sphinxcontrib.datatemplates"] | ||
templates_path = ["templates"] |
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,2 @@ | ||
.. datatemplate:json:: | ||
:template: sample.tmpl |
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,3 @@ | ||
{ | ||
"some_key": "some_value" | ||
} |
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 @@ | ||
{{data.some_key}} |
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,2 @@ | ||
extensions = ["sphinxcontrib.datatemplates"] | ||
templates_path = ["templates"] |
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 @@ | ||
.. datatemplate:json:: sample.json |
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,3 @@ | ||
{ | ||
"some_key": "some_value" | ||
} |
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 @@ | ||
{{data.some_key}} |
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,2 @@ | ||
extensions = ["sphinxcontrib.datatemplates"] | ||
templates_path = ["templates"] |
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,2 @@ | ||
.. datatemplate:dbm:: sampledbm | ||
:template: sample.tmpl |
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 @@ | ||
sample text |
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 @@ | ||
{{data}} |
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,2 @@ | ||
extensions = ["sphinxcontrib.datatemplates"] | ||
templates_path = ["templates"] |
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,2 @@ | ||
.. datatemplate:import-module:: some_module | ||
:template: sample.tmpl |
1 change: 1 addition & 0 deletions
1
tests/testdata/test-incorrect-import-module/templates/sample.tmpl
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 @@ | ||
{{data}} |
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,2 @@ | ||
extensions = ["sphinxcontrib.datatemplates"] | ||
templates_path = ["templates"] |
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,2 @@ | ||
.. datatemplate:json:: sample.json | ||
:template: sample.tmpl |
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,3 @@ | ||
{ | ||
"some_key": "some_value | ||
} |
Oops, something went wrong.