def test__getSampleCenter__WithCalibration2(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') s = samples.sample(sample_name='SampleThatCannotBeNamed', sample_type='test_sample') # Rack receives calibration r.updateCenter(200, 100, 400, 50, 70, 450) # Placing sample into the rack s.place(r, 0, 0) cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "Servo" tools.llc.serial.Serial = mock.MagicMock() tools.pipettor.home = mock.MagicMock() ar = cartesian.arnie('COM1', 'COM2') ar.getToolAtCoord = mock.MagicMock() serial_device = llc.serial_device('COM3') p1000 = tools.pipettor.getTool(robot=ar, tool_name='p1000_tool') # Tool receives calibration p1000.setStalagmyteCoord(51, 69, 420) x, y = s.getSampleCenterXY(p1000) self.assertEqual(x, 201 - 51.75) self.assertEqual(y, 99 - 33.75)
def test__pipettor__getTool(self, mock_home, mock_serialdev, mock_readAll, mock_cartesian): """ If coordinates are not matched, then library for some reason not loading json file, and using probably slot calibration data instead. """ with open('p1000_tool_rack.json', 'r') as f: saved_dict = json.loads(f.read()) x, y, z = saved_dict['position'] config = configparser.ConfigParser() config_path = 'configs/pipette_rack.ini' config.read(config_path) z_working_height = float(config['geometry']['z_working_height']) z_height = float(config['geometry']['z_box_height']) z_pickup = z - z_working_height # Setting mocks mock_readAll.return_value = "Servo" # Initializing ar = cartesian.arnie('COM1', 'COM2') ar.getToolAtCoord = mock.MagicMock() serial_device = llc.serial_device('COM3') p1000_tool = tools.pipettor.getTool(robot=ar, tool_name='p1000_tool') # Testing ar.getToolAtCoord.assert_called_with(x, y, z_pickup, z_init=0, speed_xy=None, speed_z=None)
def test__init__3(self, mock_serial): with patch.object(low_level_comm.serial_device, 'readAll', return_value='Message') as mock_readAll: dev = low_level_comm.serial_device(port_name='COM1') mock_readAll.assert_called() self.assertEqual(dev.actual_welcome_message, 'Message')
def test__pipettor__getStalagmyteCoord(self): # Mocking pipettor cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "Servo" tools.llc.serial.Serial = mock.MagicMock() tools.pipettor.home = mock.MagicMock() # Initializing the robot ar = cartesian.arnie('COM1', 'COM2') ar.getToolAtCoord = mock.MagicMock() serial_device = llc.serial_device('COM3') p1000 = tools.pipettor.getTool(robot=ar, tool_name='p1000_tool') # Mimicking initial calibration p1000.setStalagmyteCoord(51, 69, 420) # Checking that calibration was properly saved x, y, z = p1000.getStalagmyteCoord() self.assertEqual(x, 51) self.assertEqual(y, 69) self.assertEqual(z, 420) # Emulating pipette tip pickup p1000.tip_attached = True # Checking the calibration recalculated due to the added tip xt, yt, zt = p1000.getStalagmyteCoord() self.assertEqual(xt, 51) self.assertEqual(yt, 69) self.assertEqual(zt, 420 - p1000.tip_added_z_length) # Repeating calibration with a new tip added p1000.setStalagmyteCoord(50, 70, 350) # Checking that the robot returns updated calibration points xt2, yt2, zt2 = p1000.getStalagmyteCoord() self.assertEqual(xt2, 50) self.assertEqual(yt2, 70) self.assertEqual(zt2, 350) # Emulating tip discard p1000.tip_attached = False # Calibration points must be the same as before tip calibration x2, y2, z2 = p1000.getStalagmyteCoord() self.assertEqual(x2, 51) self.assertEqual(y2, 69) self.assertEqual(z2, 420)
def test__mobile_tool__getTool(self, mock_serialdev, mock_readAll, mock_cartesian): # Preparing for the test try: os.remove('generic_tool.json') except: pass with open('generic_tool_rack.json', 'w') as f: f.write(json.dumps({'a': 'b', 'position': [50, 66, 450]})) # Setting mocks mock_readAll.return_value = "Welcome returned from the device" # Initializing ar = cartesian.arnie('COM1', 'COM2') ar.getToolAtCoord = mock.MagicMock() serial_device = llc.serial_device('COM3') generic_tool = tools.mobile_tool.getTool(robot=ar, welcome_message='welcome', tool_name='generic_tool') z_pickup = 450 - generic_tool.rack.z_working_height # Testing ar.getToolAtCoord.assert_called_with(50, 66, z_pickup, z_init=0, speed_xy=None, speed_z=None) # Cleaning up after the test try: os.remove('generic_tool.json') except: pass try: os.remove('generic_tool_rack.json') except: pass
def test_mobile_tool_getToolFromSerialDev(self, mock_serialdev, mock_readAll, mock_cartesian): mock_readAll.return_value = "Welcome returned from the device" ar = cartesian.arnie('COM1', 'COM2') serial_device = llc.serial_device('COM3') generic_tool = tools.mobile_tool.getToolFromSerialDev( robot=ar, device=serial_device, welcome_message='welcome', tool_name='generic_tool') mock_readAll.assert_called() self.assertEqual(generic_tool.actual_welcome_message, "Welcome returned from the device") mock_cartesian.assert_called() mock_serialdev.assert_called() mock_serialdev.assert_called_with('COM3', 115200, timeout=0.1) tool_data = generic_tool.tool_data self.assertEqual(tool_data, { 'name': 'generic_tool', 'welcome_message': 'welcome' })
def getToolAtCoord(self, x, y, z, z_init=0, speed_xy=None, speed_z=None): """ Get tool positioned at known absolute coordinates x, y, z. """ # Producing a list of present serial ports BEFORE engaging a new tool initial_ports_list = llc.listSerialPorts() # Moving to the save height, so nothing is kicked by a robot self.move(z=z_init, speed_z=None) # Opening docker self.openTool() # Moving to the tool coordinate self.move(x=x, y=y, z=z, z_first=False, speed_xy=speed_xy, speed_z=SPEED_Z_MOVING_DOWN) # Closing docker (hopefully gripping the tool) self.closeTool() # Obtaining updated list of serial devices. Now a new device should be present there. updated_ports_list = llc.listSerialPorts() # Obtaining newly appeared port new_port = list(set(updated_ports_list) - set(initial_ports_list))[0] # Connecting to the device device = llc.serial_device(new_port) self.move(z=z_init) # After liting a tool, closing the jaws again, to make grip stronger, and to fix # possible non-ideal pickup. # Added 3/19/2020, after getting tired with precise calibration of pickup height. self.closeTool() self.closeTool() return device
def test__mobile_touch_probe__returnTool(self, mock_serialdev, mock_readAll, mock_cartesian): with open('mobile_touch_probe_rack.json', 'r') as f: saved_dict = json.loads(f.read()) x, y, z = saved_dict['position'] config = configparser.ConfigParser() config_path = 'configs/mobile_touch_probe_rack.ini' config.read(config_path) z_working_height = float(config['geometry']['z_working_height']) z_height = float(config['geometry']['z_box_height']) z_pickup = z - z_working_height # Setting mocks mock_readAll.return_value = "Arnie's mobile touch probe/nRev. 1.01, 11/27/2019" # Initializing ar = cartesian.arnie('COM1', 'COM2') ar.getToolAtCoord = mock.MagicMock() serial_device = llc.serial_device('COM3') mobile_touch_probe = tools.mobile_touch_probe.getTool(robot=ar) mobile_touch_probe.returnTool() # Testing ar.getToolAtCoord.assert_called_with(x, y, z_pickup, z_init=0, speed_xy=None, speed_z=None) ar.returnToolToCoord.assert_called_with(x, y, z_pickup, z_init=0, speed_xy=None, speed_z=None)
def test_calcWorkingPosition2(self): r = racks.stackable(rack_name='RackThatCannotBeNamed', rack_type='test_rack') # Rack receives calibration r.updateCenter(200, 100, 400, 50, 70, 450) cartesian.arnie = mock.MagicMock() tools.llc.serial_device.readAll = mock.MagicMock() tools.llc.serial_device.readAll.return_value = "Servo" tools.llc.serial.Serial = mock.MagicMock() tools.pipettor.home = mock.MagicMock() ar = cartesian.arnie('COM1', 'COM2') ar.getToolAtCoord = mock.MagicMock() serial_device = llc.serial_device('COM3') p1000 = tools.pipettor.getTool(robot=ar, tool_name='p1000_tool') # Tool receives calibration p1000.setStalagmyteCoord(51, 69, 420) x, y, z = r.calcWorkingPosition(well_col=0, well_row=0, tool=p1000) self.assertEqual(x, 201 - 51.75) self.assertEqual(y, 99 - 33.75) self.assertEqual(z, 370)
def test__init__(self, mock_serial, mock_readAll): mock_readAll.return_value = "Welcome returned from the device" dev = low_level_comm.serial_device(port_name='COM1') self.assertEqual(dev.port_name, 'COM1') dev.readAll.assert_called()
def test__init__2(self, mock_serial, mock_readAll): mock_readAll.return_value = 'Message' dev = low_level_comm.serial_device(port_name='COM1') mock_serial.assert_called() mock_serial.assert_called_with('COM1', 115200, timeout=0.1)