class ProtocolTestCase(unittest.TestCase): def setUp(self): self.robot = Robot() def test_protocol_container_setup(self): plate = containers_load(self.robot, '96-flat', '1', 'myPlate') tiprack = containers_load(self.robot, 'tiprack-10ul', '5') containers_list = self.robot.get_containers() self.assertEqual(len(containers_list), 3) self.assertEqual(self.robot._deck['1']['myPlate'], plate) self.assertEqual(self.robot._deck['5']['tiprack-10ul'], tiprack) self.assertTrue(plate in containers_list) self.assertTrue(tiprack in containers_list) def test_protocol_head(self): trash = containers_load(self.robot, 'point', '1', 'myTrash') tiprack = containers_load(self.robot, 'tiprack-10ul', '5') p200 = pipette.Pipette( self.robot, name='myPipette', trash_container=trash, tip_racks=[tiprack], min_volume=10, # These are variable mount='left', channels=1) instruments_list = self.robot.get_instruments() self.assertEqual(instruments_list[0], ('left', p200)) instruments_list = self.robot.get_instruments('myPipette') self.assertEqual(instruments_list[0], ('left', p200)) def test_deck_setup(self): deck = self.robot.deck pip = pipette.Pipette(self.robot, mount='left') # Check that the fixed trash has loaded on to the pipette trash = pip.trash_container tiprack = containers_load(self.robot, 'tiprack-10ul', '5') self.assertTrue(isinstance(tiprack, Container)) self.assertTrue(isinstance(deck, Deck)) # Check that well location is the same on the robot as the pipette self.assertEqual(self.robot._deck['12']['tall-fixed-trash'][0], trash) self.assertTrue(deck.has_container(tiprack))
class ProtocolTestCase(unittest.TestCase): def setUp(self): self.robot = Robot() def test_protocol_container_setup(self): plate = containers_load(self.robot, '96-flat', 'A1', 'myPlate') tiprack = containers_load(self.robot, 'tiprack-10ul', 'B2') containers_list = self.robot.containers().values() self.assertEqual(len(containers_list), 2) self.assertEqual(self.robot._deck['A1']['myPlate'], plate) self.assertEqual(self.robot._deck['B2']['tiprack-10ul'], tiprack) self.assertTrue(plate in containers_list) self.assertTrue(tiprack in containers_list) def test_protocol_head(self): trash = containers_load(self.robot, 'point', 'A1', 'myTrash') tiprack = containers_load(self.robot, 'tiprack-10ul', 'B2') p200 = pipette.Pipette( self.robot, name='myPipette', trash_container=trash, tip_racks=[tiprack], min_volume=10, # These are variable axis="b", channels=1) instruments_list = self.robot.get_instruments() self.assertEqual(instruments_list[0], ('B', p200)) instruments_list = self.robot.get_instruments('myPipette') self.assertEqual(instruments_list[0], ('B', p200)) def test_deck_setup(self): deck = self.robot.deck trash = containers_load(self.robot, 'point', 'A1', 'myTrash') tiprack = containers_load(self.robot, 'tiprack-10ul', 'B2') self.assertTrue(isinstance(tiprack, Container)) self.assertTrue(isinstance(deck, Deck)) self.assertTrue(deck.has_container(trash)) self.assertTrue(deck.has_container(tiprack))
def setup_robot(): robot = Robot() for port in list_of_ports: trycon(robot, port) if (robot.is_simulating()): print("no connection made") else: robot.home() robot._driver.speeds['z'] = 1200 for (axis, pipette) in robot.get_instruments(): pipette.load_persisted_data() try: yield robot finally: robot.disconnect()
class RobotSerializationTestCase(unittest.TestCase): def setUp(self): Robot.reset_for_tests() self.robot = Robot() def test_serializing_and_deserializing_unconfigured_robot(self): robot_as_bytes = dill.dumps(self.robot) self.assertIsInstance(robot_as_bytes, bytes) dill.loads(robot_as_bytes) def test_serializing_configured_robot(self): plate = containers.load('96-flat', 'A1') p200 = instruments.Pipette(axis='b', max_volume=200) for well in plate: p200.aspirate(well).delay(5).dispense(well) original_robot_cmd_cnts = len(self.robot._commands) robot_as_bytes = dill.dumps(self.robot) self.assertIsInstance(robot_as_bytes, bytes) deserialized_robot = dill.loads(robot_as_bytes) deserialized_robot_cmd_cnts = len(deserialized_robot._commands) self.assertEqual(deserialized_robot_cmd_cnts, original_robot_cmd_cnts) original_robot_instruments = self.robot.get_instruments() deserialized_robot_instruments = self.robot.get_instruments() self.assertEqual( len(original_robot_instruments), len(deserialized_robot_instruments), ) self.assertEqual( original_robot_instruments[0][0], deserialized_robot_instruments[0][0], ) def test_serializing_configured_robot_with_2_instruments(self): plate = containers.load('96-flat', 'A1') trash = containers.load('point', 'A2') tiprack = containers.load('tiprack-200ul', 'A3') p200 = instruments.Pipette( axis='b', tip_racks=[tiprack], trash_container=trash, max_volume=200 ) p100 = instruments.Pipette( axis='a', channels=8, tip_racks=[tiprack], trash_container=trash, max_volume=100 ) self.make_commands(p200, plate, p100, plate) original_robot_cmds_txt = self.robot.commands() original_robot_cmd_cnts = len(self.robot._commands) robot_as_bytes = dill.dumps(self.robot) self.assertIsInstance(robot_as_bytes, bytes) deserialized_robot = dill.loads(robot_as_bytes) deserialized_robot_cmd_cnts = len(deserialized_robot._commands) # Check commands are unmarshalled self.assertEqual(deserialized_robot_cmd_cnts, original_robot_cmd_cnts) # Check instruments are unmarshalled original_robot_instruments = self.robot.get_instruments() deserialized_robot_instruments = self.robot.get_instruments() self.assertEqual( len(original_robot_instruments), len(deserialized_robot_instruments), ) self.assertEqual( original_robot_instruments[0][0], deserialized_robot_instruments[0][0], ) # Set deserialized robot as the global robot and attempt to # reconstruct the same commands again Singleton._instances[Robot] = deserialized_robot deserialized_robot._commands = [] r2_p200 = deserialized_robot_instruments[0][1] r2_p100 = deserialized_robot_instruments[1][1] self.make_commands(r2_p200, plate, r2_p100, plate) self.assertEqual( original_robot_cmd_cnts, len(deserialized_robot._commands) ) self.assertListEqual( original_robot_cmds_txt, deserialized_robot.commands() ) def make_commands(self, inst1, inst1_plate, inst2, inst2_plate): for well in inst1_plate: inst1.aspirate(well).delay(5).dispense(well) for row in inst2_plate.rows[::-1]: inst2.aspirate(row).delay(5).dispense(row)
class RobotSerializationTestCase(unittest.TestCase): def setUp(self): self.robot = Robot() def test_serializing_and_deserializing_unconfigured_robot(self): robot_as_bytes = dill.dumps(self.robot) self.assertIsInstance(robot_as_bytes, bytes) dill.loads(robot_as_bytes) def test_serializing_configured_robot(self): plate = containers_load(self.robot, '96-flat', 'A1') p200 = pipette.Pipette(self.robot, axis='b', max_volume=200) for well in plate: p200.aspirate(well).delay(5).dispense(well) original_robot_cmd_cnts = len(self.robot._commands) robot_as_bytes = dill.dumps(self.robot) self.assertIsInstance(robot_as_bytes, bytes) deserialized_robot = dill.loads(robot_as_bytes) deserialized_robot_cmd_cnts = len(deserialized_robot._commands) self.assertEqual(deserialized_robot_cmd_cnts, original_robot_cmd_cnts) original_robot_instruments = self.robot.get_instruments() deserialized_robot_instruments = self.robot.get_instruments() self.assertEqual( len(original_robot_instruments), len(deserialized_robot_instruments), ) self.assertEqual( original_robot_instruments[0][0], deserialized_robot_instruments[0][0], ) def test_serializing_configured_robot_with_2_instruments(self): plate = containers_load(self.robot, '96-flat', 'A1') trash = containers_load(self.robot, 'point', 'A2') tiprack = containers_load(self.robot, 'tiprack-200ul', 'A3') p200 = pipette.Pipette( self.robot, axis='b', tip_racks=[tiprack], trash_container=trash, max_volume=200 ) p100 = pipette.Pipette( self.robot, axis='a', channels=8, tip_racks=[tiprack], trash_container=trash, max_volume=100 ) self.make_commands(p200, plate, p100, plate) # original_robot_cmds_txt = self.robot.commands() original_robot_cmd_cnts = len(self.robot._commands) robot_as_bytes = dill.dumps(self.robot) self.assertIsInstance(robot_as_bytes, bytes) deserialized_robot = dill.loads(robot_as_bytes) deserialized_robot_cmd_cnts = len(deserialized_robot._commands) # Check commands are unmarshalled self.assertEqual(deserialized_robot_cmd_cnts, original_robot_cmd_cnts) # Check instruments are unmarshalled original_robot_instruments = self.robot.get_instruments() deserialized_robot_instruments = self.robot.get_instruments() self.assertEqual( len(original_robot_instruments), len(deserialized_robot_instruments), ) self.assertEqual( original_robot_instruments[0][0], deserialized_robot_instruments[0][0], ) # Set deserialized robot as the global robot and attempt to # reconstruct the same commands again r2_p200 = deserialized_robot_instruments[0][1] r2_p100 = deserialized_robot_instruments[1][1] self.make_commands(r2_p200, plate, r2_p100, plate) # self.assertEqual( # original_robot_cmd_cnts, # len(deserialized_robot._commands) # ) # self.assertListEqual( # original_robot_cmds_txt, # deserialized_robot.commands() # ) def make_commands(self, inst1, inst1_plate, inst2, inst2_plate): for well in inst1_plate: inst1.aspirate(well).delay(5).dispense(well) for row in inst2_plate.rows[::-1]: inst2.aspirate(row).delay(5).dispense(row)