File size: 1,529 Bytes
60caae2
 
 
 
 
 
ec30e3a
60caae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05c50a2
60caae2
05c50a2
 
 
 
 
 
 
 
 
 
60caae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05c50a2
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Tests for studycraft.loader."""

from pathlib import Path

import pytest

from studycraft.loader import SUPPORTED, load_document, supported_extensions


@pytest.fixture
def tmp_txt(tmp_path: Path) -> Path:
    p = tmp_path / "sample.txt"
    p.write_text("Chapter 1: Hello World\nThis is a test document.", encoding="utf-8")
    return p


@pytest.fixture
def tmp_md(tmp_path: Path) -> Path:
    p = tmp_path / "sample.md"
    p.write_text("# Chapter 1\n\nMarkdown content here.", encoding="utf-8")
    return p


def test_supported_extensions_complete():
    exts = supported_extensions()
    for ext in (".pdf", ".docx", ".txt", ".md", ".rtf", ".epub"):
        assert ext in exts, f"Missing supported extension: {ext}"


def test_supported_set_matches_function():
    assert set(supported_extensions()) == SUPPORTED


def test_supported_count():
    assert len(SUPPORTED) == 6


def test_load_txt(tmp_txt: Path):
    text = load_document(tmp_txt)
    assert "Hello World" in text
    assert "test document" in text


def test_load_md(tmp_md: Path):
    text = load_document(tmp_md)
    assert "# Chapter 1" in text
    assert "Markdown content" in text


def test_unsupported_format(tmp_path: Path):
    p = tmp_path / "file.xyz"
    p.write_text("data")
    with pytest.raises(ValueError, match="Unsupported"):
        load_document(p)


def test_unsupported_error_message(tmp_path: Path):
    p = tmp_path / "file.xyz"
    p.write_text("data")
    with pytest.raises(ValueError, match=r"\.xyz"):
        load_document(p)