import pytest
from opentrons.commands import protocol_commands


@pytest.mark.parametrize(
    argnames="seconds,"
             "minutes,"
             "expected_seconds,"
             "expected_minutes,"
             "expected_text",
    argvalues=[
        [10, 0, 10, 0, "Delaying for 0 minutes and 10.0 seconds"],
        [10, 9, 10, 9, "Delaying for 9 minutes and 10.0 seconds"],
        [100, 0, 40, 1, "Delaying for 1 minutes and 40.0 seconds"],
        [105, 5.25, 0, 7, "Delaying for 7 minutes and 0.0 seconds"],
        [0.5, 0, 0.5, 0, "Delaying for 0 minutes and 0.5 seconds"],
        [105.5, 5.25, 0.5, 7, "Delaying for 7 minutes and 0.5 seconds"],
        [0.998, 0, 0.998, 0, "Delaying for 0 minutes and 0.998 seconds"],
        [0.9998, 0, 0.9998, 0, "Delaying for 0 minutes and 1.0 seconds"],
        [1.0001, 0, 1.0001, 0, "Delaying for 0 minutes and 1.0 seconds"],
    ]
)
def test_delay(seconds,
               minutes,
               expected_seconds,
               expected_minutes,
               expected_text
               ):
    command = protocol_commands.delay(seconds, minutes)
    name = command['name']
    payload = command['payload']

    assert name == 'command.DELAY'
    assert payload['seconds'] == expected_seconds
    assert payload['minutes'] == expected_minutes
    assert payload['text'] == expected_text


def test_delay_with_message():
    """It should allow a message to be appended to the delay text."""
    command = protocol_commands.delay(seconds=1, minutes=1, msg="Waiting...")

    assert command["payload"]["text"] == (
        "Delaying for 1 minutes and 1.0 seconds. Waiting..."
    )

[((5, 1, 22, 1), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (), '', False, 'import pytest\n'), ((29, 14, 29, 55), 'opentrons.commands.protocol_commands.delay', 'protocol_commands.delay', ({(29, 38, 29, 45): 'seconds', (29, 47, 29, 54): 'minutes'}, {}), '(seconds, minutes)', False, 'from opentrons.commands import protocol_commands\n'), ((41, 14, 41, 77), 'opentrons.commands.protocol_commands.delay', 'protocol_commands.delay', (), '', False, 'from opentrons.commands import protocol_commands\n')]