def test_MantarrayFrontPanel__get_barcode_returns_cleared_value_correctly( mocker): dummy_xem = okCFrontPanel() mantarray_fp = MantarrayFrontPanel(dummy_xem) expected_barcode = CLEARED_BARCODE_VALUE def get_wire_out_se(ep_addr): return 0 mocker.patch.object(dummy_xem, "GetWireOutValue", autospec=True, side_effect=get_wire_out_se) mocker.patch.object(dummy_xem, "IsFrontPanelEnabled", autospec=True, return_value=True) mocker.patch.object(dummy_xem, "UpdateWireOuts", autospec=True, return_value=True) mantarray_fp.initialize_board() actual = mantarray_fp.get_barcode() assert actual == expected_barcode
def test_MantarrayFrontPanel__get_firmware_version_returns_expected_value_from_correct_xem_GetWireOutValue_address( mocker, ): dummy_xem = okCFrontPanel() expected_value = "0.1.2" mocked_get_wire = mocker.patch.object( dummy_xem, "GetWireOutValue", autospec=True, return_value=0x00000102, ) mocker.patch.object(dummy_xem, "IsFrontPanelEnabled", autospec=True, return_value=True) mocker.patch.object(dummy_xem, "UpdateWireOuts", autospec=True, return_value=True) mantarray_fp = MantarrayFrontPanel(dummy_xem) mantarray_fp.initialize_board() actual = mantarray_fp.get_firmware_version() assert actual == expected_value mocked_get_wire.assert_called_once_with(FIRMWARE_VERSION_WIRE_OUT_ADDRESS)
def test_OkCommunicationProcess_boot_up_instrument__with_real_board__raises_error_if_firmware_version_does_not_match_file_name( four_board_comm_process, patched_firmware_folder, mocker, ): mocker.patch( "builtins.print", autospec=True) # don't print all the error messages to console ok_process = four_board_comm_process["ok_process"] board_queues = four_board_comm_process["board_queues"] dummy_xem = okCFrontPanel() mocker.patch.object(dummy_xem, "ConfigureFPGA", autospec=True, return_value=0) mocker.patch.object(dummy_xem, "IsFrontPanelEnabled", autospec=True, return_value=True) fp_board = MantarrayFrontPanel(dummy_xem) expected_wire_out_version = "-1" mocker.patch.object( fp_board, "get_firmware_version", autospec=True, return_value=expected_wire_out_version, ) ok_process.set_board_connection(0, fp_board) boot_up_comm = { "communication_type": "boot_up_instrument", "command": "initialize_board", "bit_file_name": patched_firmware_folder, "suppress_error": False, "allow_board_reinitialization": False, } board_queues[0][0].put_nowait(boot_up_comm) assert is_queue_eventually_not_empty(board_queues[0][0]) is True expected_error_msg = ( f"File name: {patched_firmware_folder}, Version from wire_out value: {expected_wire_out_version}" ) with pytest.raises( FirmwareFileNameDoesNotMatchWireOutVersionError) as exc_info: invoke_process_run_and_check_errors(ok_process) # Tanner (7/26/20): using match=expected_error_msg as a kwarg in pytest.raises wasn't working in windows because it always treats "\" as a regex escape character, even in an r-string. Not sure if there is a better way around this than making the following assertion assert exc_info.value.args[0] == expected_error_msg
def fixture_patch_connection_to_board(mocker): def set_info(info): info.serialNumber = RunningFIFOSimulator.default_xem_serial_number info.deviceID = RunningFIFOSimulator.default_device_id return 0 dummy_xem = okCFrontPanel() mocker.patch.object(dummy_xem, "GetDeviceInfo", autospec=True, side_effect=set_info) mocked_open_board = mocker.patch.object(ok_comm, "open_board", autospec=True, return_value=dummy_xem) yield dummy_xem, mocked_open_board
def test_MantarrayFrontPanel__start_barcode_scan__calls_activate_trigger_in_correctly( mocker, ): dummy_xem = okCFrontPanel() mantarray_fp = MantarrayFrontPanel(dummy_xem) mocked_ati = mocker.patch.object(dummy_xem, "ActivateTriggerIn", autospec=True, return_value=0) mocker.patch.object(dummy_xem, "IsFrontPanelEnabled", autospec=True, return_value=True) mantarray_fp.initialize_board() mantarray_fp.start_barcode_scan() mocked_ati.assert_called_once_with(BARCODE_SCANNER_TRIGGER_IN_ADDRESS, START_BARCODE_SCAN_TRIG_BIT)
def test_OkCommunicationProcess_boot_up_instrument__with_real_board__does_not_raise_error_if_firmware_version_matches_file_name( four_board_comm_process, patched_firmware_folder, mocker, ): ok_process = four_board_comm_process["ok_process"] board_queues = four_board_comm_process["board_queues"] dummy_xem = okCFrontPanel() mocker.patch.object(dummy_xem, "ConfigureFPGA", autospec=True, return_value=0) mocker.patch.object(dummy_xem, "IsFrontPanelEnabled", autospec=True, return_value=True) fp_board = MantarrayFrontPanel(dummy_xem) expected_wire_out_version = "2.3.4" mocker.patch.object( fp_board, "get_firmware_version", autospec=True, return_value=expected_wire_out_version, ) ok_process.set_board_connection(0, fp_board) boot_up_comm = { "communication_type": "boot_up_instrument", "command": "initialize_board", "bit_file_name": patched_firmware_folder, "suppress_error": False, "allow_board_reinitialization": False, } board_queues[0][0].put_nowait(boot_up_comm) assert is_queue_eventually_not_empty(board_queues[0][0]) is True invoke_process_run_and_check_errors(ok_process) assert is_queue_eventually_not_empty(board_queues[0][1]) is True response_comm = board_queues[0][1].get(timeout=QUEUE_CHECK_TIMEOUT_SECONDS) assert response_comm["main_firmware_version"] == expected_wire_out_version
def test_MantarrayFrontPanel__get_barcode__calls_read_wire_out_correctly__and_returns_correct_value( mocker, ): dummy_xem = okCFrontPanel() mantarray_fp = MantarrayFrontPanel(dummy_xem) expected_barcode = "MA1901900000" def get_wire_out_se(ep_addr): if ep_addr == BARCODE_SCANNER_TOP_WIRE_OUT_ADDRESS: return 0x4D413139 if ep_addr == BARCODE_SCANNER_MID_WIRE_OUT_ADDRESS: return 0x30313930 if ep_addr == BARCODE_SCANNER_BOTTOM_WIRE_OUT_ADDRESS: return 0x30303030 return 0 mocked_get_wire = mocker.patch.object(dummy_xem, "GetWireOutValue", autospec=True, side_effect=get_wire_out_se) mocker.patch.object(dummy_xem, "IsFrontPanelEnabled", autospec=True, return_value=True) mocker.patch.object(dummy_xem, "UpdateWireOuts", autospec=True, return_value=True) mantarray_fp.initialize_board() actual = mantarray_fp.get_barcode() assert actual == expected_barcode mocked_get_wire.assert_any_call(BARCODE_SCANNER_TOP_WIRE_OUT_ADDRESS) mocked_get_wire.assert_any_call(BARCODE_SCANNER_MID_WIRE_OUT_ADDRESS) mocked_get_wire.assert_any_call(BARCODE_SCANNER_BOTTOM_WIRE_OUT_ADDRESS)
def test_MantarrayFrontPanel__read_wire_out_raises_correct_error_if_board_not_initialized( mocker, ): dummy_xem = okCFrontPanel() mantarray_fp = MantarrayFrontPanel(dummy_xem) with pytest.raises(OpalKellyBoardNotInitializedError): mantarray_fp.read_wire_out(0x00)
def test_MantarrayFrontPanel__get_firmware_version_raises_error_if_board_not_initialized( mocker, ): dummy_xem = okCFrontPanel() mantarray_fp = MantarrayFrontPanel(dummy_xem) with pytest.raises(OpalKellyBoardNotInitializedError): mantarray_fp.get_firmware_version()
def test_MantarrayFrontPanel__start_barcode_scan__raises_error_if_board_not_initialized( mocker, ): dummy_xem = okCFrontPanel() mantarray_fp = MantarrayFrontPanel(dummy_xem) with pytest.raises(OpalKellyBoardNotInitializedError): mantarray_fp.start_barcode_scan()