コード例 #1
0
def test_fail_get_temp_deck_temperature():
    # Get the curent and target temperatures
    # If no target temp has been previously set,
    # then the response will set 'T' to 'none'
    import types
    from opentrons.drivers.temp_deck import TempDeck

    temp_deck = TempDeck()
    temp_deck.simulating = False
    return_string = 'T:none C:90'

    def _mock_send_command(self, command, timeout=None):
        return return_string

    temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)

    temp_deck.update_temperature()

    assert temp_deck._temperature == {'current': 90, 'target': None}

    return_string = 'Tx:none C:1'

    def _mock_send_command(self, command, timeout=None):
        return return_string

    temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)

    temp_deck.update_temperature()
    assert temp_deck._temperature == {'current': 90, 'target': None}
コード例 #2
0
async def test_set_temp_deck_temperature(monkeypatch):
    # Set target temperature
    import types
    from opentrons.drivers.temp_deck import TempDeck

    temp_deck = TempDeck()
    temp_deck.simulating = False
    command_log = []

    def _mock_send_command(self, command, timeout=None, tag=None):
        nonlocal command_log
        command_log += [command]
        return ''

    def _mock_update_temp(self):
        return 'holding at target'

    temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)
    temp_deck._update_temp = types.MethodType(_mock_send_command, temp_deck)

    try:
        await asyncio.wait_for(temp_deck.set_temperature(99), timeout=0.2)
    except asyncio.TimeoutError:
        pass
    assert command_log[-1] == 'M104 S99.0'

    try:
        await asyncio.wait_for(temp_deck.set_temperature(-9), timeout=0.2)
    except asyncio.TimeoutError:
        pass
    assert command_log[-1] == 'M104 S-9.0'
コード例 #3
0
def test_get_device_info(monkeypatch):

    import types
    from opentrons.drivers.temp_deck import TempDeck

    temp_deck = TempDeck()
    temp_deck.simulating = False
    command_log = []

    model = 'temp-v1'
    firmware_version = 'edge-1a2b345'
    serial = 'td20180102A01'

    def _mock_send_command(self, command, timeout=None, tag=None):
        nonlocal command_log
        command_log += [command]
        return 'model:' + model \
            + ' version:' + firmware_version \
            + ' serial:' + serial

    temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)

    res = temp_deck.get_device_info()
    assert res == {
        'model': model,
        'version': firmware_version,
        'serial': serial
    }
コード例 #4
0
def test_get_temp_deck_temperature():
    # Get the curent and target temperatures
    # If no target temp has been previously set,
    # then the response will set 'T' to 'none'
    import types
    from opentrons.drivers.temp_deck import TempDeck

    temp_deck = TempDeck()
    temp_deck.simulating = False
    command_log = []
    return_string = 'T:none C:90'

    def _mock_send_command(self, command, timeout=None, tag=None):
        nonlocal command_log, return_string
        command_log += [command]
        return return_string

    temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)

    assert temp_deck.temperature == 25  # driver's initialized value
    assert temp_deck.target is None
    temp_deck.update_temperature()
    assert command_log == ['M105']
    assert temp_deck.temperature == 90
    assert temp_deck.target is None

    command_log = []
    return_string = 'T:99 C:90'
    temp_deck.update_temperature()
    assert command_log == ['M105']
    assert temp_deck.temperature == 90
    assert temp_deck.target == 99
コード例 #5
0
def test_fail_get_temp_deck_temperature():
    # Get the curent and target temperatures
    # If get fails, temp_deck temperature is not updated
    import types
    from opentrons.drivers.temp_deck import TempDeck

    temp_deck = TempDeck()
    temp_deck.simulating = False

    done = False

    def _mock_send_command1(self, command, timeout=None, tag=None):
        nonlocal done
        done = True
        return 'T:none C:90'

    temp_deck._send_command = types.MethodType(_mock_send_command1, temp_deck)

    temp_deck.update_temperature()
    time.sleep(0.25)
    while not done:
        time.sleep(0.25)

    assert temp_deck._temperature == {'current': 90, 'target': None}

    def _mock_send_command2(self, command, timeout=None, tag=None):
        nonlocal done
        done = True
        return 'Tx:none C:1'  # Failure premise

    temp_deck._send_command = types.MethodType(_mock_send_command2, temp_deck)
    done = False
    temp_deck.update_temperature()
    time.sleep(0.25)
    while not done:
        time.sleep(0.25)
    assert temp_deck._temperature == {'current': 90, 'target': None}
コード例 #6
0
def test_dfu_command(monkeypatch):
    import types
    from opentrons.drivers.temp_deck import TempDeck

    temp_deck = TempDeck()
    temp_deck.simulating = False
    command_log = []

    def _mock_send_command(self, command, timeout=None, tag=None):
        nonlocal command_log
        command_log += [command]
        return ''

    temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)

    temp_deck.enter_programming_mode()
    assert command_log == ['dfu']
コード例 #7
0
def test_turn_off_temp_deck(monkeypatch):
    import types
    from opentrons.drivers.temp_deck import TempDeck

    temp_deck = TempDeck()
    temp_deck.simulating = False
    command_log = []

    def _mock_send_command(self, command, timeout=None, tag=None):
        nonlocal command_log
        command_log += [command]
        return ''

    temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)

    temp_deck.deactivate()
    assert command_log == ['M18']
コード例 #8
0
def test_set_temp_deck_temperature(monkeypatch):
    # Set target temperature
    import types
    from opentrons.drivers.temp_deck import TempDeck

    temp_deck = TempDeck()
    temp_deck.simulating = False
    command_log = []

    def _mock_send_command(self, command, timeout=None):
        nonlocal command_log
        command_log += [command]
        return ''

    temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)

    temp_deck.set_temperature(99)
    assert command_log[-1] == 'M104 S99.0'

    temp_deck.set_temperature(-9)
    assert command_log[-1] == 'M104 S-9.0'