|
| 1 | +"""Tests for blockquote element type consistency (Issue #270). |
| 2 | +
|
| 3 | +blockquote is listed in --help but rejected at runtime by valid_types check. |
| 4 | +""" |
| 5 | + |
| 6 | +from click.testing import CliRunner |
| 7 | + |
| 8 | +from dacli.cli import cli |
| 9 | + |
| 10 | + |
| 11 | +class TestBlockquoteElementType: |
| 12 | + """blockquote must be accepted as a valid element type.""" |
| 13 | + |
| 14 | + def test_blockquote_no_warning(self, tmp_path): |
| 15 | + """Passing --type blockquote must not produce an 'Unknown element type' warning.""" |
| 16 | + doc = tmp_path / "test.md" |
| 17 | + doc.write_text("# Test\n\n> A blockquote\n") |
| 18 | + |
| 19 | + runner = CliRunner() |
| 20 | + result = runner.invoke(cli, [ |
| 21 | + "--docs-root", str(tmp_path), |
| 22 | + "--format", "json", |
| 23 | + "elements", |
| 24 | + "--type", "blockquote", |
| 25 | + ]) |
| 26 | + |
| 27 | + assert "Unknown element type" not in result.output, ( |
| 28 | + f"blockquote rejected as unknown: {result.output}" |
| 29 | + ) |
| 30 | + |
| 31 | + def test_valid_types_match_help_text(self): |
| 32 | + """All types listed in --help must be in valid_types.""" |
| 33 | + runner = CliRunner() |
| 34 | + result = runner.invoke(cli, ["elements", "--help"]) |
| 35 | + |
| 36 | + # Extract types from help text |
| 37 | + # Help says: "Element type: admonition, blockquote, code, image, list, plantuml, table" |
| 38 | + assert "blockquote" in result.output, "blockquote missing from --help" |
| 39 | + |
| 40 | + def test_all_model_element_types_accepted(self, tmp_path): |
| 41 | + """Every ElementType in the model should be accepted by CLI validation.""" |
| 42 | + from dacli.models import Element |
| 43 | + |
| 44 | + doc = tmp_path / "test.md" |
| 45 | + doc.write_text("# Test\n\nSome content.\n") |
| 46 | + |
| 47 | + runner = CliRunner() |
| 48 | + # Get all valid types from the Element model's type field |
| 49 | + # The Literal type annotation lists all valid values |
| 50 | + import typing |
| 51 | + type_hints = typing.get_type_hints(Element) |
| 52 | + # Element.type is Literal["code", "table", ...] |
| 53 | + literal_args = typing.get_args(type_hints["type"]) |
| 54 | + |
| 55 | + for etype in literal_args: |
| 56 | + result = runner.invoke(cli, [ |
| 57 | + "--docs-root", str(tmp_path), |
| 58 | + "--format", "json", |
| 59 | + "elements", |
| 60 | + "--type", etype, |
| 61 | + ]) |
| 62 | + assert "Unknown element type" not in result.output, ( |
| 63 | + f"Element type '{etype}' rejected by CLI but defined in model" |
| 64 | + ) |
0 commit comments