"""Unit tests for VESC driver node."""

import pytest


def test_vesc_driver_init():
    """Test VESC driver node initialization."""
    import rclpy

    rclpy.init(allow_reuse=True)
    try:
        from saltybot_vesc_driver.vesc_driver_node import VESCDriverNode

        node = VESCDriverNode()
        assert node is not None
        node.destroy_node()
    except Exception as e:
        # pyvesc may not be installed in test env
        assert "pyvesc" in str(e) or "serial" in str(e)


def test_vesc_state():
    """Test VESC state object."""
    from saltybot_vesc_driver.vesc_driver_node import VESCState

    state = VESCState()
    assert state.voltage_v == 0.0
    assert state.current_a == 0.0
    assert state.rpm == 0
    assert state.fault_code == 0


def test_vesc_command_mode():
    """Test VESC command mode enum."""
    from saltybot_vesc_driver.vesc_driver_node import VESCCommandMode

    assert VESCCommandMode.DUTY_CYCLE.value == "duty_cycle"
    assert VESCCommandMode.RPM.value == "rpm"
    assert VESCCommandMode.CURRENT.value == "current"


if __name__ == "__main__":
    pytest.main([__file__, "-v"])
