Files
talemate/tests/test_history.py
veguAI f5d41c04c8 0.37.0 (#267)
0.37.0

- **Director Planning** — Multi-step todo lists in director chat plus a Generate long progress action for multi-beat scene arcs.
- **Auto Narration** — Unified auto-narration replacing the old Narrate after Dialogue toggle, with a chance slider and weighted action mix.
- **LLM Prompt Templates Manager** — Dedicated UI tab for viewing, creating, editing, and deleting prompt templates.
- **Character Folders** — Collapsible folders in the World Editor character list, synced across linked scenes.
- **OpenAI Compatible TTS** — Connect any number of OpenAI-compatible TTS servers in parallel.
- **KoboldCpp TTS Auto-Setup** — KoboldCpp clients with a TTS model loaded register themselves as a TTS backend.
- **Model Testing Harness** — Bundled scene that runs basic capability tests against any connected LLM.

Plus 27 improvements and 28 bug fixes
2026-05-12 21:01:51 +03:00

135 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pytest
from talemate.history import shift_scene_timeline
from talemate.tale_mate import Scene
# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------
@pytest.fixture()
def scene_factory():
"""Return a factory that builds a real `Scene` with the given timeline state.
Uses real `Scene` (not a stand-in) so tests catch breakage if Scene's
`ts`/`archived_history`/`layered_history` API changes.
"""
def _factory(ts: str = "PT0S", archived=None, layered=None):
scene = Scene()
scene.ts = ts
scene.archived_history = archived or []
scene.layered_history = layered or []
return scene
return _factory
# ---------------------------------------------------------------------------
# Tests
# ---------------------------------------------------------------------------
@pytest.mark.parametrize(
"initial_ts, archived_tss, layered_tss, shift_iso, expected_scene_ts, expected_archived_ts, expected_layered_ts",
[
# Hours / minutes
(
"PT2H", # initial
["PT1H", "PT90M"],
["PT30M"],
"PT1H", # +1 hour
"PT3H",
["PT2H", "PT2H30M"],
["PT1H30M"],
),
(
"PT2H",
["PT1H", "PT90M"],
["PT30M"],
"-PT30M", # -30 minutes
"PT1H30M",
["PT30M", "PT1H"],
["P0D"], # zero becomes P0D
),
# Months
(
"P2M",
["P1M", "P6M"],
["P3M"],
"P1M", # +1 month
"P3M",
["P2M", "P7M"],
["P4M"],
),
# Years
(
"P3Y",
["P1Y", "P2Y"],
["P6M"],
"-P1Y", # -1 year
"P2Y",
["P0D", "P1Y"],
["P0D"], # clamped to zero
),
# Huge shift 1000 years
(
"P0D",
["P1Y"],
["P2Y"],
"P1000Y",
"P1000Y",
["P1001Y"],
["P1002Y"],
),
],
ids=["hour_plus", "hour_minus", "month_plus", "year_minus", "millennia_plus"],
)
def test_shift_scene_timeline_basic(
scene_factory,
initial_ts,
archived_tss,
layered_tss,
shift_iso,
expected_scene_ts,
expected_archived_ts,
expected_layered_ts,
):
"""Parametrised test verifying various time-unit shifts."""
archived = [{"ts": ts} for ts in archived_tss]
layered = [[{"ts": ts} for ts in layered_tss]]
scene = scene_factory(initial_ts, archived, layered)
shift_scene_timeline(scene, shift_iso)
assert scene.ts == expected_scene_ts
assert [e["ts"] for e in scene.archived_history] == expected_archived_ts
assert [e["ts"] for e in scene.layered_history[0]] == expected_layered_ts
def test_shift_scene_timeline_noop(scene_factory):
"""A shift of PT0S (and variants) should not mutate the scene."""
scene = scene_factory(
"PT0S",
archived=[{"ts": "PT1H", "ts_start": "PT30M", "ts_end": "PT90M"}],
layered=[[{"ts": "PT15M"}]],
)
import copy
pre_state = (
scene.ts,
copy.deepcopy(scene.archived_history),
copy.deepcopy(scene.layered_history),
)
shift_scene_timeline(scene, "PT0S")
assert scene.ts == pre_state[0]
assert scene.archived_history == pre_state[1]
assert scene.layered_history == pre_state[2]