from datetime import datetime from fam_edge.video_processor import ( _parse_event_start_from_filename, _parse_event_ts, _clean_person, ) def test_parse_filename_pure_digit_format(): assert _parse_event_start_from_filename( "Generic_ONVIF-001-20260820-140416-1787205856321-7.mp4" ) == "2026-08-20 14:04:16" def test_parse_filename_underscore_date_format(): assert _parse_event_start_from_filename("20260821_081500.mp4") == "2026-08-21 08:15:00" def test_parse_filename_dashed_date_format(): assert _parse_event_start_from_filename("2026-08-21_081500.mp4") == "2026-08-21 08:15:00" def test_parse_filename_no_match_returns_empty(): assert _parse_event_start_from_filename("客厅.mp4") == "" def test_parse_event_ts_relative_offset(): start = datetime(2026, 8, 21, 15, 53, 3) abs_ts, offset = _parse_event_ts("00:18:22", start) assert abs_ts == "2026-08-21 16:11:25" assert offset == 18 * 60 + 22 def test_parse_event_ts_relative_offset_no_start(): abs_ts, offset = _parse_event_ts("00:01:23", None) assert abs_ts == "00:01:23" assert offset == 83.0 def test_parse_event_ts_over_6_hours_falls_back_to_absolute(): """相对时间 > 6 小时视为模型误输出绝对时间,不强行按偏移定位。""" start = datetime(2026, 8, 21, 8, 0, 0) abs_ts, offset = _parse_event_ts("2026-08-21 09:00:00", start) assert abs_ts == "2026-08-21 09:00:00" assert offset == 3600.0 def test_clean_person_strips_fullwidth_parens(): assert _clean_person("人物A(别名/标识:人物B)") == "人物A" def test_clean_person_strips_ascii_parens(): assert _clean_person("人物A(alias: 人物B)") == "人物A" def test_clean_person_no_parens_unchanged(): assert _clean_person("汤圆") == "汤圆"