Skip to content

Commit 374e416

Browse files
authored
🧪 TEST: Add test_malformed_file_parse (#17)
1 parent ff4d83d commit 374e416

File tree

8 files changed

+27
-2
lines changed

8 files changed

+27
-2
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ Questions / TODOs:
317317
- Should `titlesonly` default to `True` (as in jupyter-book)?
318318
- nested numbered toctree not allowed (logs warning), so should be handled if `numbered: true` is in defaults
319319
- Add additional top-level keys, e.g. `appendices` (see https://github.com/sphinx-doc/sphinx/issues/2502) and `bibliography`
320-
- Add tests for "bad" toc files
321320
- Using `external_toc_exclude_missing` to exclude a certain file suffix:
322321
currently if you had files `doc.md` and `doc.rst`, and put `doc.md` in your ToC,
323322
it will add `doc.rst` to the excluded patterns but then, when looking for `doc.md`,

tests/_bad_toc_files/empty.yml

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root: index
2+
sections:
3+
- file: doc
4+
glob: doc*

tests/_bad_toc_files/list.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- 1
2+
- 2

tests/_bad_toc_files/no_root.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x: a
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root: index
2+
sections:
3+
- glob: doc*
4+
sections:
5+
- file: other
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root: index
2+
sections:
3+
- url: http://example.com
4+
sections:
5+
- file: other

tests/test_api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import pytest
44

5-
from sphinx_external_toc.api import create_toc_dict, parse_toc_yaml
5+
from sphinx_external_toc.api import MalformedError, create_toc_dict, parse_toc_yaml
66

77
TOC_FILES = list(Path(__file__).parent.joinpath("_toc_files").glob("*.yml"))
8+
TOC_FILES_BAD = list(Path(__file__).parent.joinpath("_bad_toc_files").glob("*.yml"))
89

910

1011
@pytest.mark.parametrize(
@@ -22,3 +23,11 @@ def test_create_toc_dict(path: Path, data_regression):
2223
site_map = parse_toc_yaml(path)
2324
data = create_toc_dict(site_map)
2425
data_regression.check(data)
26+
27+
28+
@pytest.mark.parametrize(
29+
"path", TOC_FILES_BAD, ids=[path.name.rsplit(".", 1)[0] for path in TOC_FILES_BAD]
30+
)
31+
def test_malformed_file_parse(path: Path):
32+
with pytest.raises(MalformedError):
33+
parse_toc_yaml(path)

0 commit comments

Comments
 (0)