"""Tests for {{ module_name }} interface.

These tests use the fake interface to validate the interface contract
without requiring actual hardware.

Generated by: madsci new module --template module/basic
Template version: {{ template_version }}
"""

import pytest

from {{ module_name }}_fake_interface import {{ module_name | pascal_case }}FakeInterface


class Test{{ module_name | pascal_case }}FakeInterface:
    """Test cases for the {{ module_name }} fake interface."""

    @pytest.fixture
    def interface(self) -> {{ module_name | pascal_case }}FakeInterface:
        """Create a test interface instance."""
        return {{ module_name | pascal_case }}FakeInterface(simulated_latency=0.01)

    def test_initial_state(self, interface: {{ module_name | pascal_case }}FakeInterface) -> None:
        """Test that interface starts disconnected."""
        assert not interface.is_connected
        assert interface.operation_count == 0

    def test_connect(self, interface: {{ module_name | pascal_case }}FakeInterface) -> None:
        """Test connection."""
        interface.connect()
        assert interface.is_connected

    def test_disconnect(self, interface: {{ module_name | pascal_case }}FakeInterface) -> None:
        """Test disconnection."""
        interface.connect()
        interface.disconnect()
        assert not interface.is_connected

    def test_do_something_requires_connection(
        self, interface: {{ module_name | pascal_case }}FakeInterface
    ) -> None:
        """Test that operations require connection."""
        with pytest.raises(RuntimeError, match="Not connected"):
            interface.do_something("test")

    def test_do_something_success(
        self, interface: {{ module_name | pascal_case }}FakeInterface
    ) -> None:
        """Test successful operation."""
        interface.connect()
        result = interface.do_something("hello")

        assert "hello" in result
        assert interface.operation_count == 1

    def test_operation_count_increments(
        self, interface: {{ module_name | pascal_case }}FakeInterface
    ) -> None:
        """Test that operation count increments correctly."""
        interface.connect()

        interface.do_something("one")
        assert interface.operation_count == 1

        interface.do_something("two")
        assert interface.operation_count == 2

        interface.do_something("three")
        assert interface.operation_count == 3

    def test_get_state(self, interface: {{ module_name | pascal_case }}FakeInterface) -> None:
        """Test state retrieval."""
        interface.connect()
        interface.do_something("test message")

        state = interface.get_state()

        assert state["connected"] is True
        assert state["operation_count"] == 1
        assert state["last_message"] == "test message"
        assert "last_operation_time" in state

    def test_reset_state(self, interface: {{ module_name | pascal_case }}FakeInterface) -> None:
        """Test state reset."""
        interface.connect()
        interface.do_something("test")
        interface.reset_state()

        assert interface.operation_count == 0
        state = interface.get_state()
        assert "last_message" not in state
