from chapter_index import load_titles

def test_reads_titles_without_changing_file(tmp_path):
    path = tmp_path / "chapters.json"
    original = '["Python and Roots", "Python and Branches"]'
    path.write_text(original, encoding="utf-8")

    titles = load_titles(path)

    assert titles == ["Python and Roots", "Python and Branches"]
    assert path.read_text(encoding="utf-8") == original

import pytest

def test_rejects_a_non_text_title(tmp_path):
    path = tmp_path / "chapters.json"
    path.write_text('["Python and Roots", 8]', encoding="utf-8")
    with pytest.raises(ValueError):
        load_titles(path)
