Skip to content

Commit

Permalink
add test_incorrect_import_module
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizordec committed Dec 15, 2023
1 parent 4671d69 commit 1723fca
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sphinxcontrib/datatemplates/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ def run(self):
nodes.literal_block(self.block_text, self.block_text),
line=self.lineno)
return [error]
except ModuleNotFoundError:
error = self.state_machine.reporter.error(
f"Source module '{relative_resolved_path}' not found",
nodes.literal_block(self.block_text, self.block_text),
line=self.lineno)
return [error]
except (json.decoder.JSONDecodeError, ET.ParseError) as err:
error = self.state_machine.reporter.error(
f"Error in source file '{relative_resolved_path}': {err}",
Expand Down
10 changes: 10 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,13 @@ def test_incorrect_xml_syntax(app: SphinxTestApp, warning: StringIO):
"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: Source module 'some_module' not found"
)
assert expected_error_str in warning.getvalue()
2 changes: 2 additions & 0 deletions tests/testdata/test-incorrect-import-module/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ["sphinxcontrib.datatemplates"]
templates_path = ["templates"]
2 changes: 2 additions & 0 deletions tests/testdata/test-incorrect-import-module/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. datatemplate:import-module:: some_module
:template: sample.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{data}}

0 comments on commit 1723fca

Please sign in to comment.