Skip to content

Commit

Permalink
add test_incorrect_dbm
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizordec committed Dec 15, 2023
1 parent 1723fca commit eb49858
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sphinxcontrib/datatemplates/directive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import codecs
import csv
import dbm
import json
import mimetypes
from collections import defaultdict
Expand Down Expand Up @@ -214,7 +215,11 @@ def run(self):
nodes.literal_block(self.block_text, self.block_text),
line=self.lineno)
return [error]
except (json.decoder.JSONDecodeError, ET.ParseError) as err:
except (
json.decoder.JSONDecodeError,
ET.ParseError,
dbm.error[0],
) 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 @@ -112,3 +112,14 @@ def test_incorrect_import_module(app: SphinxTestApp, warning: StringIO):
"ERROR: Source module 'some_module' not found"
)
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 file 'sampledbm': "
"db type could not be determined"
)
assert expected_error_str in warning.getvalue()
2 changes: 2 additions & 0 deletions tests/testdata/test-incorrect-dbm/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-dbm/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. datatemplate:dbm:: sampledbm
:template: sample.tmpl
1 change: 1 addition & 0 deletions tests/testdata/test-incorrect-dbm/sampledbm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sample text
1 change: 1 addition & 0 deletions tests/testdata/test-incorrect-dbm/templates/sample.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{data}}

0 comments on commit eb49858

Please sign in to comment.