#!/usr/bin/env python3
"""Unit tests v0.3: match_placement (dense footage ↔ placements)."""
import os
import sys
import unittest

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import vlib as V


# Clips no formato real Paula/Ronaldo (amostra)
CLIPS = [
    {"cam": "cam1_carao1fabr", "name": "cam1_carao1fabr_PRE_0175cerimonia", "startFrame": 91840},
    {"cam": "cam2_william", "name": "cam2_william_C5333cerimoniacam2", "startFrame": 56408},
    {"cam": "cam3_luis", "name": "cam3_luis_DSC_3985cerimoniacam3", "startFrame": 121507},
    {"cam": "cam2_william", "name": "cam2_william_C5330", "startFrame": 31013},
]


class TestMatchPlacement(unittest.TestCase):
    def test_carao_truncated_cerim(self):
        cam, sf = V.match_placement("carao1fabr_PRE_0175cerim", CLIPS)
        self.assertEqual(cam, "cam1_carao1fabr")
        self.assertEqual(sf, 91840)

    def test_william_cerimoniacam2(self):
        cam, sf = V.match_placement("william_C5333cerimonia", CLIPS)
        self.assertEqual(cam, "cam2_william")
        self.assertEqual(sf, 56408)

    def test_luis_cerimoniacam3(self):
        cam, sf = V.match_placement("luis_DSC_3985cerimonia", CLIPS)
        self.assertEqual(cam, "cam3_luis")
        self.assertEqual(sf, 121507)

    def test_junk_short_rejected(self):
        cam, sf = V.match_placement("william_C", CLIPS)
        self.assertIsNone(sf)
        cam, sf = V.match_placement("luis_DSC_", CLIPS)
        self.assertIsNone(sf)

    def test_norm_cerimonia(self):
        self.assertEqual(V.footage_key_norm("carao1fabr_PRE_0175cerimonia"),
                         V.footage_key_norm("carao1fabr_PRE_0175cerim"))
        self.assertEqual(V.footage_key_norm("william_C5333cerimoniacam2"),
                         V.footage_key_norm("william_C5333cerimonia"))


if __name__ == "__main__":
    unittest.main(verbosity=2)
