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..."
    )

[((66, 782), 'pytest.mark.parametrize', '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,\n    'Delaying for 9 minutes and 10.0 seconds'], [100, 0, 40, 1,\n    'Delaying for 1 minutes and 40.0 seconds'], [105, 5.25, 0, 7,\n    'Delaying for 7 minutes and 0.0 seconds'], [0.5, 0, 0.5, 0,\n    'Delaying for 0 minutes and 0.5 seconds'], [105.5, 5.25, 0.5, 7,\n    'Delaying for 7 minutes and 0.5 seconds'], [0.998, 0, 0.998, 0,\n    'Delaying for 0 minutes and 0.998 seconds'], [0.9998, 0, 0.9998, 0,\n    'Delaying for 0 minutes and 1.0 seconds'], [1.0001, 0, 1.0001, 0,\n    'Delaying for 0 minutes and 1.0 seconds']]"}), "(argnames=\n    'seconds,minutes,expected_seconds,expected_minutes,expected_text',\n    argvalues=[[10, 0, 10, 0, 'Delaying for 0 minutes and 10.0 seconds'], [\n    10, 9, 10, 9, 'Delaying for 9 minutes and 10.0 seconds'], [100, 0, 40, \n    1, 'Delaying for 1 minutes and 40.0 seconds'], [105, 5.25, 0, 7,\n    'Delaying for 7 minutes and 0.0 seconds'], [0.5, 0, 0.5, 0,\n    'Delaying for 0 minutes and 0.5 seconds'], [105.5, 5.25, 0.5, 7,\n    'Delaying for 7 minutes and 0.5 seconds'], [0.998, 0, 0.998, 0,\n    'Delaying for 0 minutes and 0.998 seconds'], [0.9998, 0, 0.9998, 0,\n    'Delaying for 0 minutes and 1.0 seconds'], [1.0001, 0, 1.0001, 0,\n    'Delaying for 0 minutes and 1.0 seconds']])\n", (89, 782), False, 'import pytest\n'), ((1068, 1109), 'opentrons.commands.protocol_commands.delay', 'protocol_commands.delay', (['seconds', 'minutes'], {}), '(seconds, minutes)\n', (1091, 1109), False, 'from opentrons.commands import protocol_commands\n'), ((1467, 1530), 'opentrons.commands.protocol_commands.delay', 'protocol_commands.delay', ([], {'seconds': '(1)', 'minutes': '(1)', 'msg': '"""Waiting..."""'}), "(seconds=1, minutes=1, msg='Waiting...')\n", (1490, 1530), False, 'from opentrons.commands import protocol_commands\n')]