test_prose_rst.py

tests/test_prose_rst.py

reStructuredText is prose, chunked by the sections its grammar finds.

test_a_named_target_opens_the_section_it_labels

None test_prose_rst.test_a_named_target_opens_the_section_it_labels()

A label travels with its section.

tests/test_prose_rst.py:129

Show on the map →

Called by none

Calls chunk_rst

Checks

  • assert ".. _install:" in chunks["Install"]
  • assert ".. _install:" not in chunks["Intro"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-001measuredtest_a_named_target_opens_the_section_it_labels → chunk_rst
REQ-DDB-PIPE-012measuredtest_a_named_target_opens_the_section_it_labels → chunk_rst → has_language
Source · 12 lines
def test_a_named_target_opens_the_section_it_labels() -> None:
    """`.. _install:` above a title is that section's label (`:ref:`install``), so it is the
    first line of the section's chunk and not the last line of the one before.

    @brief A label travels with its section. @version 1
    """
    text = "Intro\n=====\n\nHello.\n\n.. _install:\n\nInstall\n=======\n\nSteps.\n"
    chunks = dict(chunk_rst(text, "docs/guide.rst"))
    assert ".. _install:" in chunks["Install"]
    assert ".. _install:" not in chunks["Intro"]

Activity · 4 steps
lines 135–135text = "Intro\n=====\n\nHello.\n\n.. _install:\n\nInstall\n=======\n\nSteps.\n"lines 136–136chunks = dict(chunk_rst(text, "docs/guide.rst"))lines 137–137assert ".. _install:" in chunks["Install"]lines 138–138assert ".. _install:" not in chunks["Intro"]

test_a_scanned_rst_file_is_ingested_as_prose

None test_prose_rst.test_a_scanned_rst_file_is_ingested_as_prose(Path tmp_path)

A scanned `.rst` anywhere in the tree becomes prose.

tests/test_prose_rst.py:56

Show on the map →

Called by none

Calls _chunks, _write, ingest_supplementary_docs

Checks

  • assert _chunks(db) == [("docs/install.rst", "Install")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_a_scanned_rst_file_is_ingested_as_prose → ingest_supplementary_docs → _ingest_one_doc_file → memoized
REQ-DDB-PIPE-001measuredtest_a_scanned_rst_file_is_ingested_as_prose → ingest_supplementary_docs
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-014measuredtest_a_scanned_rst_file_is_ingested_as_prose → ingest_supplementary_docs → within_repo
Source · 15 lines
def test_a_scanned_rst_file_is_ingested_as_prose(tmp_path: Path) -> None:
    """The gap: `docs/install.rst` sits in the scanned set and no glob names it.

    @brief A scanned `.rst` anywhere in the tree becomes prose. @version 1
    """
    root = tmp_path / "repo"
    _write(root, "docs/install.rst", "Install\n=======\n\nRun the installer.\n")
    db = tmp_path / "clew.db"
    db.touch()

    ingest_supplementary_docs(db, root, files=["docs/install.rst"])

    assert _chunks(db) == [("docs/install.rst", "Install")]

Activity · 6 steps
lines 61–61root = tmp_path / "repo"lines 62–62_write(root, "docs/install.rst", "Install\n=======\n\nRun the installer.\n")lines 63–63db = tmp_path / "clew.db"lines 64–64db.touch()lines 66–66ingest_supplementary_docs(db, root, files=["docs/install.rst"])lines 68–68assert _chunks(db) == [("docs/install.rst", "Install")]

test_a_title_shaped_line_inside_a_literal_block_does_not_split

None test_prose_rst.test_a_title_shaped_line_inside_a_literal_block_does_not_split()

Literal blocks are not titles.

tests/test_prose_rst.py:112

Show on the map →

Called by none

Calls chunk_rst

Checks

  • assert [h for h, _ in chunks] == ["Real"]
  • assert "Fake" in chunks[0][1]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-001measuredtest_a_title_shaped_line_inside_a_literal_block_does_not_split → chunk_rst
REQ-DDB-PIPE-012measuredtest_a_title_shaped_line_inside_a_literal_block_does_not_split → chunk_rst → has_language
Source · 11 lines
def test_a_title_shaped_line_inside_a_literal_block_does_not_split() -> None:
    """The grammar knows a literal block; a regex over `====` lines would not.

    @brief Literal blocks are not titles. @version 1
    """
    text = "Real\n====\n\nExample::\n\n    Fake\n    ====\n\nDone.\n"
    chunks = chunk_rst(text, "docs/guide.rst")
    assert [h for h, _ in chunks] == ["Real"]
    assert "Fake" in chunks[0][1]

Activity · 4 steps
lines 117–117text = "Real\n====\n\nExample::\n\n Fake\n ====\n\nDone.\n"lines 118–118chunks = chunk_rst(text, "docs/guide.rst")lines 119–119assert [h for h, _ in chunks] == ["Real"]lines 120–120assert "Fake" in chunks[0][1]

test_an_anonymous_target_stays_with_the_paragraph_it_serves

None test_prose_rst.test_an_anonymous_target_stays_with_the_paragraph_it_serves()

Anonymous targets are not labels.

tests/test_prose_rst.py:141

Show on the map →

Called by none

Calls chunk_rst

Checks

  • assert "__ http://example.org" in chunks["Intro"]
  • assert "__ http" not in chunks["Next"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-001measuredtest_an_anonymous_target_stays_with_the_paragraph_it_serves → chunk_rst
REQ-DDB-PIPE-012measuredtest_an_anonymous_target_stays_with_the_paragraph_it_serves → chunk_rst → has_language
Source · 11 lines
def test_an_anonymous_target_stays_with_the_paragraph_it_serves() -> None:
    """`__ http://...` is a link destination for the text before it, not a section label.

    @brief Anonymous targets are not labels. @version 1
    """
    text = "Intro\n=====\n\nSee `docs`__.\n\n__ http://example.org\n\nNext\n====\n\nMore.\n"
    chunks = dict(chunk_rst(text, "docs/guide.rst"))
    assert "__ http://example.org" in chunks["Intro"]
    assert "__ http" not in chunks["Next"]

Activity · 4 steps
lines 146–146text = "Intro\n=====\n\nSee `docs`__.\n\n__ http://example.org\n\nNext\n====\n\nMore.\n"lines 147–147chunks = dict(chunk_rst(text, "docs/guide.rst"))lines 148–148assert "__ http://example.org" in chunks["Intro"]lines 149–149assert "__ http" not in chunks["Next"]

test_an_overlined_title_is_its_own_style

None test_prose_rst.test_an_overlined_title_is_its_own_style()

Overline distinguishes a style.

tests/test_prose_rst.py:102

Show on the map →

Called by none

Calls _headings

Checks

  • assert _headings(text) == ["Title", "Part"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-001measuredtest_an_overlined_title_is_its_own_style → _headings → chunk_rst
REQ-DDB-PIPE-012measuredtest_an_overlined_title_is_its_own_style → _headings → chunk_rst → has_language
Source · 10 lines
def test_an_overlined_title_is_its_own_style() -> None:
    """An overlined `=` title and an underlined `=` title are two styles, so two levels;
    the overlined one appears first and is the document title.

    @brief Overline distinguishes a style. @version 1
    """
    text = "=====\nTitle\n=====\n\nIntro.\n\nPart\n====\n\nBody.\n"
    assert _headings(text) == ["Title", "Part"]

Activity · 2 steps
lines 108–108text = "=====\nTitle\n=====\n\nIntro.\n\nPart\n====\n\nBody.\n"lines 109–109assert _headings(text) == ["Title", "Part"]

test_content_before_the_first_title_is_headed_by_the_file_name

None test_prose_rst.test_content_before_the_first_title_is_headed_by_the_file_name()

The preamble chunk, as `chunk_markdown` names it.

tests/test_prose_rst.py:123

Show on the map →

Called by none

Calls chunk_rst

Checks

  • assert chunks[0] == ("guide.rst", ":Author: someone")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-001measuredtest_content_before_the_first_title_is_headed_by_the_file_name → chunk_rst
REQ-DDB-PIPE-012measuredtest_content_before_the_first_title_is_headed_by_the_file_name → chunk_rst → has_language
Source · 6 lines
def test_content_before_the_first_title_is_headed_by_the_file_name() -> None:
    """@brief The preamble chunk, as `chunk_markdown` names it. @version 1"""
    chunks = chunk_rst(":Author: someone\n\nTitle\n=====\n\nBody.\n", "docs/guide.rst")
    assert chunks[0] == ("guide.rst", ":Author: someone")

Activity · 2 steps
lines 125–125chunks = chunk_rst(":Author: someone\n\nTitle\n=====\n\nBody.\n", "docs/guide.rst")lines 126–126assert chunks[0] == ("guide.rst", ":Author: someone")

test_levels_follow_the_order_styles_first_appear

None test_prose_rst.test_levels_follow_the_order_styles_first_appear()

Order of appearance, not character, decides a level.

tests/test_prose_rst.py:87

Show on the map →

Called by none

Calls chunk_rst

Checks

  • assert [h for h, _ in chunks] == ["Top", "Two", "Three", "Again two"]
  • assert "Four" in dict(chunks)["Three"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-001measuredtest_levels_follow_the_order_styles_first_appear → chunk_rst
REQ-DDB-PIPE-012measuredtest_levels_follow_the_order_styles_first_appear → chunk_rst → has_language
Source · 15 lines
def test_levels_follow_the_order_styles_first_appear() -> None:
    """docutils' rule: `~` used first is level 1, whatever the character. Level 4 (`-`
    here) stays inside its parent's chunk, as a markdown `####` does.

    @brief Order of appearance, not character, decides a level. @version 1
    """
    text = (
        "Top\n~~~\n\nA.\n\nTwo\n===\n\nB.\n\nThree\n^^^^^\n\nC.\n\n"
        "Four\n----\n\nD.\n\nAgain two\n=========\n\nE.\n"
    )
    chunks = chunk_rst(text, "docs/guide.rst")
    assert [h for h, _ in chunks] == ["Top", "Two", "Three", "Again two"]
    assert "Four" in dict(chunks)["Three"]

Activity · 4 steps
lines 93–96text = ( "Top\n~~~\n\nA.\n\nTwo\n===\n\nB.\n\nThree\n^^^^^\n\nC.\n\n" "Four\n----\n\nD.\n\nAgain two\n=========\n\nE.\n" )lines 97–97chunks = chunk_rst(text, "docs/guide.rst")lines 98–98assert [h for h, _ in chunks] == ["Top", "Two", "Three", "Again two"]lines 99–99assert "Four" in dict(chunks)["Three"]

test_readme_rst_is_split_by_the_rst_grammar_not_markdown

None test_prose_rst.test_readme_rst_is_split_by_the_rst_grammar_not_markdown(Path tmp_path)

README.rst splits at an rst-only title style.

tests/test_prose_rst.py:71

Show on the map →

Called by none

Calls _chunks, _write, ingest_supplementary_docs

Checks

  • assert _chunks(db) == [("README.rst", "Tool"), ("README.rst", "Usage")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_readme_rst_is_split_by_the_rst_grammar_not_markdown → ingest_supplementary_docs → _ingest_one_doc_file → memoized
REQ-DDB-PIPE-001measuredtest_readme_rst_is_split_by_the_rst_grammar_not_markdown → ingest_supplementary_docs
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-014measuredtest_readme_rst_is_split_by_the_rst_grammar_not_markdown → ingest_supplementary_docs → within_repo
Source · 16 lines
def test_readme_rst_is_split_by_the_rst_grammar_not_markdown(tmp_path: Path) -> None:
    """`README.rst` was always globbed, and was chunked as markdown. A `~` underline is no
    markdown heading at all, so the second section never split.

    @brief README.rst splits at an rst-only title style. @version 1
    """
    root = tmp_path / "repo"
    _write(root, "README.rst", "Tool\n~~~~\n\nIntro.\n\nUsage\n^^^^^\n\nRun it.\n")
    db = tmp_path / "clew.db"
    db.touch()

    ingest_supplementary_docs(db, root, files=[])

    assert _chunks(db) == [("README.rst", "Tool"), ("README.rst", "Usage")]

Activity · 6 steps
lines 77–77root = tmp_path / "repo"lines 78–78_write(root, "README.rst", "Tool\n~~~~\n\nIntro.\n\nUsage\n^^^^^\n\nRun it.\n")lines 79–79db = tmp_path / "clew.db"lines 80–80db.touch()lines 82–82ingest_supplementary_docs(db, root, files=[])lines 84–84assert _chunks(db) == [("README.rst", "Tool"), ("README.rst", "Usage")]

test_without_the_grammar_the_file_is_one_chunk

None test_prose_rst.test_without_the_grammar_the_file_is_one_chunk(pytest.MonkeyPatch monkeypatch)

Degrade to one chunk when the grammar is absent.

tests/test_prose_rst.py:152

Show on the map →

Called by none

Calls chunk_rst

Checks

  • assert chunk_rst(text, "docs/guide.rst") == [("guide.rst", text.strip())]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-001measuredtest_without_the_grammar_the_file_is_one_chunk → chunk_rst
REQ-DDB-PIPE-012measuredtest_without_the_grammar_the_file_is_one_chunk → chunk_rst → has_language
Source · 11 lines
def test_without_the_grammar_the_file_is_one_chunk(monkeypatch: pytest.MonkeyPatch) -> None:
    """A substrate built without `lang-rst` must not crash the build, and must not split by
    a guess. The file is still searchable, whole, under its name.

    @brief Degrade to one chunk when the grammar is absent. @version 1
    """
    monkeypatch.setattr(substrate, "compiled_languages", lambda: frozenset({"markdown"}))
    text = "Title\n=====\n\nBody.\n"
    assert chunk_rst(text, "docs/guide.rst") == [("guide.rst", text.strip())]

Activity · 3 steps
lines 158–158monkeypatch.setattr(substrate, "compiled_languages", lambda: frozenset({"markdown"}))lines 159–159text = "Title\n=====\n\nBody.\n"lines 160–160assert chunk_rst(text, "docs/guide.rst") == [("guide.rst", text.strip())]