"""Tests for MME reader."""

import pytest

from impakt.io.mme import MMEReader


class TestMMEReader:
    def test_supports_mme_directory(self, sample_mme_dir):
        reader = MMEReader()
        assert reader.supports(sample_mme_dir)

    def test_does_not_support_random_dir(self, tmp_path):
        reader = MMEReader()
        empty_dir = tmp_path / "empty"
        empty_dir.mkdir()
        assert not reader.supports(empty_dir)

    def test_read_metadata(self, sample_mme_dir):
        reader = MMEReader()
        meta = reader.metadata(sample_mme_dir)
        assert meta.test_number == "TEST_001"
        assert meta.vehicle.make == "Toyota"
        assert meta.vehicle.model == "Camry"
        assert meta.dummy.dummy_type == "H3-50M"

    def test_read_full_data(self, sample_mme_dir):
        reader = MMEReader()
        test_data = reader.read(sample_mme_dir)
        assert test_data.test_id == "TEST_001"
        assert len(test_data) >= 1
        assert "11HEAD0000ACXA" in test_data

    def test_read_channel_data(self, sample_mme_dir):
        reader = MMEReader()
        test_data = reader.read(sample_mme_dir)
        ch = test_data.get("11HEAD0000ACXA")
        assert ch.unit == "g"
        assert ch.sample_rate == 20000.0
        assert ch.n_samples > 0
        assert len(ch.time) == len(ch.data)

    def test_format_name(self):
        reader = MMEReader()
        assert reader.format_name == "ISO 13499 MME"
