import pytest

# Mark entire module as hardware + babylin so it's easy to select/deselect via -m
pytestmark = [pytest.mark.hardware, pytest.mark.babylin]


def test_babylin_connect_receive_timeout(lin, rp):
    """
    Title: BabyLIN Hardware Smoke - Connect and Timed Receive

    Description:
        Minimal hardware sanity check that relies on the configured fixtures to
        connect to a BabyLIN device and perform a short receive call.
        The test is intentionally permissive: it accepts either a valid LinFrame
        or a None (timeout) as success, focusing on verifying that the adapter
        is functional and not crashing.

    Requirements: REQ-HW-SMOKE

    Test Steps:
        1. Use the 'lin' fixture to connect to the BabyLIN SDK adapter
        2. Call receive() with a short timeout
        3. Assert the outcome is either a LinFrame or None (timeout)

    Expected Result:
        - No exceptions are raised
        - Return value is None (timeout) or an object with an 'id' attribute
    """
    # Step 2: Perform a short receive to verify operability
    rx = lin.receive(timeout=1.0)  # 1 second timeout
    rp("receive_result", "timeout" if rx is None else "frame")

    # Step 3: Accept either a timeout (None) or a frame-like object
    assert rx is None or hasattr(rx, "id")
