Skip to content

Commit

Permalink
add test_incorrect_xml_syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizordec committed Dec 15, 2023
1 parent 1d9a94c commit 4671d69
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sphinxcontrib/datatemplates/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def run(self):
nodes.literal_block(self.block_text, self.block_text),
line=self.lineno)
return [error]
except json.decoder.JSONDecodeError as err:
except (json.decoder.JSONDecodeError, ET.ParseError) as err:
error = self.state_machine.reporter.error(
f"Error in source file '{relative_resolved_path}': {err}",
nodes.literal_block(self.block_text, self.block_text),
Expand Down
11 changes: 11 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,14 @@ def test_incorrect_yaml_syntax(app: SphinxTestApp, warning: StringIO):
' 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 file 'sample.xml': "
"not well-formed (invalid token): line 2, column 4"
)
assert expected_error_str in warning.getvalue()
2 changes: 2 additions & 0 deletions tests/testdata/test-incorrect-xml-syntax/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-xml-syntax/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. datatemplate:xml:: sample.xml
:template: sample.tmpl
20 changes: 20 additions & 0 deletions tests/testdata/test-incorrect-xml-syntax/sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<sample
<key1>value1</key1>
<key2>
<item>list item 1</item>
<item>list item 2</item>
<item special='yes'>list item 3</item>
</key2>
<mappingseries>
<mapping>
<cola special='yes'>a</cola>
<colb>b</colb>
<colc>c</colc>
</mapping>
<mapping>
<cola>A</cola>
<colb special='yes'>B</colb>
<colc>C</colc>
</mapping>
</mappingseries>
</sample>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{data.find('key1').text}}

0 comments on commit 4671d69

Please sign in to comment.