You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

30 lines
1.6 KiB

import csv
import json
from pathlib import Path
from src.config_loader import TurnLoggingSettings
from src.models import TurnEvent, TurnFrameResult, TurnTrackState
from src.turn_logger import TurnLogger
def test_three_turn_logs_bom_json_and_summary_deduplication(tmp_path: Path) -> None:
logger = TurnLogger(TurnLoggingSettings(True, True, True, True, 1, str(tmp_path)), "exp", "stamp")
logger.open()
frame = TurnFrameResult(1, 2, "now", .2, True, True, True, 0, 25, 25, 25,
"positive", True, True, "weak", .3)
event = TurnEvent("turn_confirmed", 1, 2, "now", .2, 25, 25, "weak", {"注記": "反応"})
state = TurnTrackState(1, total_frames=5, pose_frames=5, face_detected_frames=5,
baseline_yaw=0, baseline_acquired=True, turn_confirmed=True,
turn_level="weak", evaluable=True, valid_for_turn_analysis=True,
exclusion_reason="turn_detected", finalized=True)
logger.write_frames([frame])
logger.write_events([event])
logger.write_summary(state)
logger.write_summary(state)
logger.close(); logger.close()
paths = list(tmp_path.glob("*.csv"))
assert len(paths) == 3 and all(path.read_bytes().startswith(b"\xef\xbb\xbf") for path in paths)
with next(path for path in paths if "events" in path.name).open(encoding="utf-8-sig", newline="") as stream:
assert json.loads(next(csv.DictReader(stream))["metadata_json"])["注記"] == "反応"
with next(path for path in paths if "summary" in path.name).open(encoding="utf-8-sig", newline="") as stream:
assert len(list(csv.DictReader(stream))) == 1