OPEN SOURCE
software/tests/test_models.py
Read on this site and download the files you need.
Nichijoyaku was created using AI. A complete review by human biblical-language and biblical-studies specialists has not been established. Read alongside established translations and original-language resources.
← Back to the open-source guide
1"""Tests for data models."""23import pytest4from datetime import datetime56from src.models.verse import (7BookMetadata,8ChapterSummary,9GlossaryTerm,10TranslationContext,11TranslationOutput,12Verse,13VerseReference,14)151617class TestVerseReference:18"""Tests for VerseReference model."""1920def test_create_verse_reference(self) -> None:21"""Test creating a verse reference."""22ref = VerseReference(book="john", chapter=1, verse=1)23assert ref.book == "john"24assert ref.chapter == 125assert ref.verse == 12627def test_verse_reference_str(self) -> None:28"""Test string representation."""29ref = VerseReference(book="john", chapter=3, verse=16)30assert str(ref) == "john:3:16"3132def test_verse_reference_from_string(self) -> None:33"""Test parsing from string."""34ref = VerseReference.from_string("john:1:1")35assert ref.book == "john"36assert ref.chapter == 137assert ref.verse == 13839def test_verse_reference_from_string_uppercase(self) -> None:40"""Test parsing handles case insensitivity."""41ref = VerseReference.from_string("JOHN:1:1")42assert ref.book == "john"4344def test_verse_reference_invalid_format(self) -> None:45"""Test parsing invalid format raises error."""46with pytest.raises(ValueError, match="Invalid verse reference"):47VerseReference.from_string("john:1")4849def test_verse_reference_invalid_format_too_many_parts(self) -> None:50"""Test parsing invalid format with too many parts."""51with pytest.raises(ValueError, match="Invalid verse reference"):52VerseReference.from_string("john:1:1:extra")535455class TestVerse:56"""Tests for Verse model."""5758def test_create_verse(self) -> None:59"""Test creating a verse."""60ref = VerseReference(book="john", chapter=1, verse=1)61verse = Verse(reference=ref, greek_text="Ἐν ἀρχῇ")62assert verse.reference == ref63assert verse.greek_text == "Ἐν ἀρχῇ"6465def test_verse_has_source_text_with_greek(self) -> None:66"""Test has_source_text with Greek text."""67ref = VerseReference(book="john", chapter=1, verse=1)68verse = Verse(reference=ref, greek_text="Ἐν ἀρχῇ")69assert verse.has_source_text() is True7071def test_verse_has_source_text_with_hebrew(self) -> None:72"""Test has_source_text with Hebrew text."""73ref = VerseReference(book="genesis", chapter=1, verse=1)74verse = Verse(reference=ref, hebrew_text="בְּרֵאשִׁית")75assert verse.has_source_text() is True7677def test_verse_has_source_text_empty(self) -> None:78"""Test has_source_text with no source text."""79ref = VerseReference(book="john", chapter=1, verse=1)80verse = Verse(reference=ref, english_kjv="In the beginning")81assert verse.has_source_text() is False828384class TestGlossaryTerm:85"""Tests for GlossaryTerm model."""8687def test_create_glossary_term(self) -> None:88"""Test creating a glossary term."""89term = GlossaryTerm(90original="λόγος",91transliteration="logos",92japanese="言葉",93english="word",94notes="Used in John 1:1",95)96assert term.original == "λόγος"97assert term.transliteration == "logos"98assert term.japanese == "言葉"99assert term.english == "word"100assert term.notes == "Used in John 1:1"101102def test_create_glossary_term_without_notes(self) -> None:103"""Test creating a glossary term without notes."""104term = GlossaryTerm(105original="ἀγάπη",106transliteration="agape",107japanese="愛",108english="love",109)110assert term.notes is None111112113class TestBookMetadata:114"""Tests for BookMetadata model."""115116def test_create_book_metadata(self) -> None:117"""Test creating book metadata."""118meta = BookMetadata(119book="john",120name_japanese="ヨハネによる福音書",121name_english="Gospel of John",122testament="NT",123author="John the Apostle",124themes=["love", "light", "life"],125description="The fourth Gospel",126chapter_count=21,127verse_count=879,128)129assert meta.book == "john"130assert meta.name_japanese == "ヨハネによる福音書"131assert len(meta.themes) == 3132133134class TestChapterSummary:135"""Tests for ChapterSummary model."""136137def test_create_chapter_summary(self) -> None:138"""Test creating chapter summary."""139summary = ChapterSummary(140book="john",141chapter=1,142summary="The prologue introduces Jesus as the Word.",143key_events=["Word becomes flesh"],144key_characters=["Jesus", "John the Baptist"],145key_themes=["Light", "Word"],146)147assert summary.book == "john"148assert summary.chapter == 1149150151class TestTranslationContext:152"""Tests for TranslationContext model."""153154def test_create_translation_context(self) -> None:155"""Test creating translation context."""156ref = VerseReference(book="john", chapter=1, verse=1)157verse = Verse(reference=ref, greek_text="Ἐν ἀρχῇ")158context = TranslationContext(target_verse=verse)159assert context.target_verse == verse160assert context.preceding_verses == []161assert context.following_verses == []162163164class TestTranslationOutput:165"""Tests for TranslationOutput model."""166167def test_create_translation_output(self) -> None:168"""Test creating translation output."""169ref = VerseReference(book="john", chapter=1, verse=1)170output = TranslationOutput(171reference=ref,172text="初めに言葉があった。",173model="claude-sonnet-4-20250514",174)175assert output.reference == ref176assert output.text == "初めに言葉があった。"177assert output.model == "claude-sonnet-4-20250514"178assert output.prompt_version == "v1.0"179180def test_translation_output_with_timestamp(self) -> None:181"""Test translation output has timestamp."""182ref = VerseReference(book="john", chapter=1, verse=1)183output = TranslationOutput(184reference=ref,185text="初めに言葉があった。",186model="claude-sonnet-4-20250514",187)188assert isinstance(output.timestamp, datetime)189