def test_drip_recorded_handler_should_call_back_per_drip(self): mock_communicatior = MagicMock() starting_height = 0.0 drips_per_mm = 1.0 mock_call_back = MagicMock() expected_drips = 1 expected_height = 1.0 expected_average = 0.0 sdza = SerialDripZAxis(mock_communicatior, drips_per_mm, starting_height, mock_call_back) drip_message = DripRecordedMessage(1) start = time.time() sdza.drip_reported_handler(drip_message) end = time.time() self.assertTrue(mock_call_back.called) self.assertEqual(expected_drips, mock_call_back.call_args_list[0][0][0]) self.assertEqual(expected_height, mock_call_back.call_args_list[0][0][1]) self.assertEqual(expected_average, mock_call_back.call_args_list[0][0][2]) self.assertTrue(mock_call_back.call_args_list[0][0][3][0] >= start) self.assertTrue(mock_call_back.call_args_list[0][0][3][0] <= end)
def test_move_to_sends_drips_as_ints(self): mock_communicatior = MagicMock() starting_height = 0.0 drips_per_mm = 1.0 mock_call_back = MagicMock() sdza = SerialDripZAxis(mock_communicatior, drips_per_mm, starting_height, mock_call_back) sdza.move_to(3.5) mock_communicatior.send.assert_called_with(MoveToDripCountMessage(4))
def test_drip_recorded_handler_adds_correct_height_per_drip(self): mock_communicatior = MagicMock() starting_height = 0.0 drips_per_mm = 2.5 sdza = SerialDripZAxis(mock_communicatior, drips_per_mm, starting_height) drip_message = DripRecordedMessage(1) sdza.drip_reported_handler(drip_message) self.assertEqual(0.4, sdza.current_z_location_mm())
def _change_dripper(self): self._stop_current_dripper() if self._current_config.dripper.dripper_type == 'emulated': pass elif self._current_config.dripper.dripper_type == 'photo': pass elif self._current_config.dripper.dripper_type == 'microcontroller': self._communicator = UsbPacketCommunicator( self._current_config.circut.calibration_queue_length) self._communicator.start() self._drip_detector = SerialDripZAxis( self._communicator, 1, 0.0, drip_call_back=self.drip_call_back)
def test_drip_recorded_handler_adds_drips_if_missing_message(self): mock_communicatior = MagicMock() starting_height = 0.0 drips_per_mm = 1.0 sdza = SerialDripZAxis(mock_communicatior, drips_per_mm, starting_height) drip_message_1 = DripRecordedMessage(1) drip_message_2 = DripRecordedMessage(3) sdza.drip_reported_handler(drip_message_1) sdza.drip_reported_handler(drip_message_2) self.assertEqual(3.0, sdza.current_z_location_mm())
def test_drip_recorded_handler_should_adjust_history_for_missing_drips(self): mock_communicatior = MagicMock() starting_height = 0.0 drips_per_mm = 1.0 mock_call_back = MagicMock() sdza = SerialDripZAxis(mock_communicatior, drips_per_mm, starting_height, mock_call_back) drip_message_1 = DripRecordedMessage(1) drip_message_2 = DripRecordedMessage(10) sdza.drip_reported_handler(drip_message_1) sdza.drip_reported_handler(drip_message_2) self.assertEquals(10, len(mock_call_back.call_args_list[1][0][3]))
def test_drip_recorded_handler_should_adjust_history_for_missing_drips( self): mock_communicatior = MagicMock() starting_height = 0.0 drips_per_mm = 1.0 mock_call_back = MagicMock() sdza = SerialDripZAxis(mock_communicatior, drips_per_mm, starting_height, mock_call_back) drip_message_1 = DripRecordedMessage(1) drip_message_2 = DripRecordedMessage(10) sdza.drip_reported_handler(drip_message_1) sdza.drip_reported_handler(drip_message_2) self.assertEquals(10, len(mock_call_back.call_args_list[1][0][3]))
def _change_dripper(self): self._stop_current_dripper() if self._current_config.dripper.dripper_type == 'emulated': pass elif self._current_config.dripper.dripper_type == 'photo': pass elif self._current_config.dripper.dripper_type == 'microcontroller': self._communicator = UsbPacketCommunicator(self._current_config.circut.calibration_queue_length) self._communicator.start() self._drip_detector = SerialDripZAxis(self._communicator, 1, 0.0, drip_call_back=self.drip_call_back)
def test_reset_removes_drips_count(self): mock_communicatior = MagicMock() starting_height = 0.0 drips_per_mm = 2.5 sdza = SerialDripZAxis(mock_communicatior, drips_per_mm, starting_height) drip_message = DripRecordedMessage(1) sdza.drip_reported_handler(drip_message) sdza.reset() actual_height = sdza.current_z_location_mm() history = sdza.drip_history self.assertEqual(0.0, actual_height) self.assertEqual([], history)
def _get_zaxis(self, dry_run): if dry_run: return None elif self._configuration.dripper.dripper_type == 'photo': logger.info("Photo Zaxis") return PhotoZAxis(self._start_height, self._configuration.dripper.photo_zaxis_delay) elif self._configuration.dripper.dripper_type == 'emulated': logger.info("Emulated Zaxis") return TimedDripZAxis(self._configuration.dripper.drips_per_mm, self._start_height, drips_per_second=self._configuration.dripper. emulated_drips_per_second) elif self._configuration.dripper.dripper_type == 'microcontroller': logger.info("Micro Controller Zaxis") return SerialDripZAxis( self._get_communicator(dry_run), self._configuration.dripper.drips_per_mm, self._start_height, )
class DripperSetupMixIn(object): '''Depricated use get_dripper_drips_per_mm''' def get_drips_per_mm(self): logging.warning("Depricated use get_dripper_drips_per_mm") return self.get_dripper_drips_per_mm() '''Returns Drips Per mm''' def get_dripper_drips_per_mm(self): return self._current_config.dripper.drips_per_mm '''Returns the configured Dripper Type''' def get_dripper_type(self): return self._current_config.dripper.dripper_type '''Depricated use get_dripper_emulated_drips_per_second''' def get_emulated_drips_per_second(self): logging.warning("Depricated use get_dripper_emulated_drips_per_second") return self.get_dripper_emulated_drips_per_second() '''Gets the drips per second to be emulated''' def get_dripper_emulated_drips_per_second(self): return self._current_config.dripper.emulated_drips_per_second '''Depricated use get_dripper_photo_zaxis_delay''' def get_photo_zaxis_delay(self): logging.warning("Depricated use get_dripper_photo_zaxis_delay") return self.get_dripper_photo_zaxis_delay() '''Gets the photo delay in seconds''' def get_dripper_photo_zaxis_delay(self): return self._current_config.dripper.photo_zaxis_delay '''Depricated use set_dripper_drips_per_mm''' def set_drips_per_mm(self, drips): logging.warning("Depricated use set_dripper_drips_per_mm") self.set_dripper_drips_per_mm(drips) '''Sets Drips Per mm''' def set_dripper_drips_per_mm(self, drips): self._current_config.dripper.drips_per_mm = drips if self._drip_detector: self._drip_detector.set_drips_per_mm(drips) self.save() '''Sets the configured Dripper Type''' def set_dripper_type(self, value): self._current_config.dripper.dripper_type = value self.save() '''Depricated use set_dripper_emulated_drips_per_second''' def set_emulated_drips_per_second(self, value): logging.warning("Depricated use set_dripper_emulated_drips_per_second") self.set_dripper_emulated_drips_per_second(value) '''Sets the drips per second to be emulated''' def set_dripper_emulated_drips_per_second(self, value): self._current_config.dripper.emulated_drips_per_second = value self.save() '''Depricated use set_dripper_photo_zaxis_delay''' def set_photo_zaxis_delay(self, value): logging.warning("Depricated use set_dripper_photo_zaxis_delay") self.set_dripper_photo_zaxis_delay(value) '''Sets the photo delay in seconds''' def set_dripper_photo_zaxis_delay(self, value): self._current_config.dripper.photo_zaxis_delay = value self.save() '''Sets the drip count back to 0''' def reset_drips(self): self._drip_detector.reset() '''Turns on the counting of drips. Stop must be called to end this.''' def start_counting_drips(self, drip_call_back=None): self.drip_call_back = drip_call_back if self._current_config.serial.on: self._commander = SerialCommander(self._current_config.serial.port) self._change_dripper() def _change_dripper(self): self._stop_current_dripper() if self._current_config.dripper.dripper_type == 'emulated': pass elif self._current_config.dripper.dripper_type == 'photo': pass elif self._current_config.dripper.dripper_type == 'microcontroller': self._communicator = UsbPacketCommunicator( self._current_config.circut.calibration_queue_length) self._communicator.start() self._drip_detector = SerialDripZAxis( self._communicator, 1, 0.0, drip_call_back=self.drip_call_back) def _stop_current_dripper(self): if self._communicator: self._communicator.close() if self._drip_detector: self._drip_detector.close() self._drip_detector = None '''Turns off the counting of drips if counting''' def stop_counting_drips(self): if self._commander: self._commander.close() self._stop_current_dripper() def send_dripper_on_command(self): if self._commander: self._commander.send_command( self._current_config.serial.on_command) else: raise Exception("Serial not Started") def send_dripper_off_command(self): if self._commander: self._commander.send_command( self._current_config.serial.off_command) else: raise Exception("Serial not Started")
class DripperSetupMixIn(object): '''This is a Mixin for the ConfigurationAPI and exists only for organizational purposes''' def get_dripper_drips_per_mm(self): '''Returns Drips Per mm''' return self._current_config.dripper.drips_per_mm def get_dripper_type(self): '''Returns the configured Dripper Type''' return self._current_config.dripper.dripper_type def get_dripper_emulated_drips_per_second(self): '''Gets the drips per second to be emulated''' return self._current_config.dripper.emulated_drips_per_second def get_dripper_photo_zaxis_delay(self): '''Gets the photo delay in seconds''' return self._current_config.dripper.photo_zaxis_delay def set_dripper_drips_per_mm(self, drips): '''Sets Drips Per mm''' self._current_config.dripper.drips_per_mm = drips if self._drip_detector: self._drip_detector.set_drips_per_mm(drips) self.save() def set_dripper_type(self, value): '''Sets the configured Dripper Type''' self._current_config.dripper.dripper_type = value self.save() def set_dripper_emulated_drips_per_second(self, value): '''Sets the drips per second to be emulated''' self._current_config.dripper.emulated_drips_per_second = value self.save() def set_dripper_photo_zaxis_delay(self, value): '''Sets the photo delay in seconds''' self._current_config.dripper.photo_zaxis_delay = value self.save() def reset_drips(self): '''Sets the drip count back to 0''' self._drip_detector.reset() def start_counting_drips(self, drip_call_back=None): '''Turns on the counting of drips. Stop must be called to end this.''' self.drip_call_back = drip_call_back if self._current_config.serial.on: self._commander = SerialCommander(self._current_config.serial.port) self._change_dripper() def _change_dripper(self): self._stop_current_dripper() if self._current_config.dripper.dripper_type == 'emulated': pass elif self._current_config.dripper.dripper_type == 'photo': pass elif self._current_config.dripper.dripper_type == 'microcontroller': self._communicator = UsbPacketCommunicator( self._current_config.circut.calibration_queue_length) self._communicator.start() self._drip_detector = SerialDripZAxis( self._communicator, 1, 0.0, drip_call_back=self.drip_call_back) def _stop_current_dripper(self): if self._communicator: self._communicator.close() if self._drip_detector: self._drip_detector.close() self._drip_detector = None def stop_counting_drips(self): '''Turns off the counting of drips if counting''' if self._commander: self._commander.close() self._stop_current_dripper() def send_dripper_on_command(self): '''If serial commuinication is enabled this send the turn on drips command''' if self._commander: self._commander.send_command( self._current_config.serial.on_command) else: raise Exception("Serial not Started") def send_dripper_off_command(self): '''If serial commuinication is enabled this send the turn off drips command''' if self._commander: self._commander.send_command( self._current_config.serial.off_command) else: raise Exception("Serial not Started")
def test_init_sets_up_starting_height(self): mock_communicatior = MagicMock() starting_height = 10.0 sdza = SerialDripZAxis(mock_communicatior, 1.0, starting_height) self.assertEqual(starting_height, sdza.current_z_location_mm())
def test_reset_removes_drips_count_accounting_for_hardware(self): mock_communicatior = MagicMock() starting_height = 0.0 drips_per_mm = 1.0 sdza = SerialDripZAxis(mock_communicatior, drips_per_mm, starting_height) drip_message_1 = DripRecordedMessage(1) drip_message_2 = DripRecordedMessage(2) drip_message_3 = DripRecordedMessage(1) sdza.drip_reported_handler(drip_message_1) self.assertEqual(1.0, sdza.current_z_location_mm()) sdza.drip_reported_handler(drip_message_2) self.assertEqual(2.0, sdza.current_z_location_mm()) sdza.reset() self.assertEqual(0.0, sdza.current_z_location_mm()) self.assertEqual(2, mock_communicatior.send.call_count) mock_communicatior.send.assert_called_with(SetDripCountMessage(0)) sdza.drip_reported_handler(drip_message_3) self.assertEqual(1.0, sdza.current_z_location_mm())
class DripperSetupMixIn(object): '''This is a Mixin for the ConfigurationAPI and exists only for organizational purposes''' def get_dripper_drips_per_mm(self): '''Returns Drips Per mm''' return self._current_config.dripper.drips_per_mm def get_dripper_type(self): '''Returns the configured Dripper Type''' return self._current_config.dripper.dripper_type def get_dripper_emulated_drips_per_second(self): '''Gets the drips per second to be emulated''' return self._current_config.dripper.emulated_drips_per_second def get_dripper_photo_zaxis_delay(self): '''Gets the photo delay in seconds''' return self._current_config.dripper.photo_zaxis_delay def set_dripper_drips_per_mm(self, drips): '''Sets Drips Per mm''' self._current_config.dripper.drips_per_mm = drips if self._drip_detector: self._drip_detector.set_drips_per_mm(drips) self.save() def set_dripper_type(self, value): '''Sets the configured Dripper Type''' self._current_config.dripper.dripper_type = value self.save() def set_dripper_emulated_drips_per_second(self, value): '''Sets the drips per second to be emulated''' self._current_config.dripper.emulated_drips_per_second = value self.save() def set_dripper_photo_zaxis_delay(self, value): '''Sets the photo delay in seconds''' self._current_config.dripper.photo_zaxis_delay = value self.save() def reset_drips(self): '''Sets the drip count back to 0''' self._drip_detector.reset() def start_counting_drips(self, drip_call_back=None): '''Turns on the counting of drips. Stop must be called to end this.''' self.drip_call_back = drip_call_back if self._current_config.serial.on: self._commander = SerialCommander(self._current_config.serial.port) self._change_dripper() def _change_dripper(self): self._stop_current_dripper() if self._current_config.dripper.dripper_type == 'emulated': pass elif self._current_config.dripper.dripper_type == 'photo': pass elif self._current_config.dripper.dripper_type == 'microcontroller': self._communicator = UsbPacketCommunicator(self._current_config.circut.calibration_queue_length) self._communicator.start() self._drip_detector = SerialDripZAxis(self._communicator, 1, 0.0, drip_call_back=self.drip_call_back) def _stop_current_dripper(self): if self._communicator: self._communicator.close() if self._drip_detector: self._drip_detector.close() self._drip_detector = None def stop_counting_drips(self): '''Turns off the counting of drips if counting''' if self._commander: self._commander.close() self._stop_current_dripper() def send_dripper_on_command(self): '''If serial commuinication is enabled this send the turn on drips command''' if self._commander: self._commander.send_command(self._current_config.serial.on_command) else: raise Exception("Serial not Started") def send_dripper_off_command(self): '''If serial commuinication is enabled this send the turn off drips command''' if self._commander: self._commander.send_command(self._current_config.serial.off_command) else: raise Exception("Serial not Started")
class DripperSetupMixIn(object): '''Depricated use get_dripper_drips_per_mm''' def get_drips_per_mm(self): logging.warning("Depricated use get_dripper_drips_per_mm") return self.get_dripper_drips_per_mm() '''Returns Drips Per mm''' def get_dripper_drips_per_mm(self): return self._current_config.dripper.drips_per_mm '''Returns the configured Dripper Type''' def get_dripper_type(self): return self._current_config.dripper.dripper_type '''Depricated use get_dripper_emulated_drips_per_second''' def get_emulated_drips_per_second(self): logging.warning("Depricated use get_dripper_emulated_drips_per_second") return self.get_dripper_emulated_drips_per_second() '''Gets the drips per second to be emulated''' def get_dripper_emulated_drips_per_second(self): return self._current_config.dripper.emulated_drips_per_second '''Depricated use get_dripper_photo_zaxis_delay''' def get_photo_zaxis_delay(self): logging.warning("Depricated use get_dripper_photo_zaxis_delay") return self.get_dripper_photo_zaxis_delay() '''Gets the photo delay in seconds''' def get_dripper_photo_zaxis_delay(self): return self._current_config.dripper.photo_zaxis_delay '''Depricated use set_dripper_drips_per_mm''' def set_drips_per_mm(self, drips): logging.warning("Depricated use set_dripper_drips_per_mm") self.set_dripper_drips_per_mm(drips) '''Sets Drips Per mm''' def set_dripper_drips_per_mm(self, drips): self._current_config.dripper.drips_per_mm = drips if self._drip_detector: self._drip_detector.set_drips_per_mm(drips) self.save() '''Sets the configured Dripper Type''' def set_dripper_type(self, value): self._current_config.dripper.dripper_type = value self.save() '''Depricated use set_dripper_emulated_drips_per_second''' def set_emulated_drips_per_second(self, value): logging.warning("Depricated use set_dripper_emulated_drips_per_second") self.set_dripper_emulated_drips_per_second(value) '''Sets the drips per second to be emulated''' def set_dripper_emulated_drips_per_second(self, value): self._current_config.dripper.emulated_drips_per_second = value self.save() '''Depricated use set_dripper_photo_zaxis_delay''' def set_photo_zaxis_delay(self, value): logging.warning("Depricated use set_dripper_photo_zaxis_delay") self.set_dripper_photo_zaxis_delay(value) '''Sets the photo delay in seconds''' def set_dripper_photo_zaxis_delay(self, value): self._current_config.dripper.photo_zaxis_delay = value self.save() '''Sets the drip count back to 0''' def reset_drips(self): self._drip_detector.reset() '''Turns on the counting of drips. Stop must be called to end this.''' def start_counting_drips(self, drip_call_back=None): self.drip_call_back = drip_call_back if self._current_config.serial.on: self._commander = SerialCommander(self._current_config.serial.port) self._change_dripper() def _change_dripper(self): self._stop_current_dripper() if self._current_config.dripper.dripper_type == 'emulated': pass elif self._current_config.dripper.dripper_type == 'photo': pass elif self._current_config.dripper.dripper_type == 'microcontroller': self._communicator = UsbPacketCommunicator(self._current_config.circut.calibration_queue_length) self._communicator.start() self._drip_detector = SerialDripZAxis(self._communicator, 1, 0.0, drip_call_back=self.drip_call_back) def _stop_current_dripper(self): if self._communicator: self._communicator.close() if self._drip_detector: self._drip_detector.close() self._drip_detector = None '''Turns off the counting of drips if counting''' def stop_counting_drips(self): if self._commander: self._commander.close() self._stop_current_dripper() def send_dripper_on_command(self): if self._commander: self._commander.send_command(self._current_config.serial.on_command) else: raise Exception("Serial not Started") def send_dripper_off_command(self): if self._commander: self._commander.send_command(self._current_config.serial.off_command) else: raise Exception("Serial not Started")
def test_init_calls_registers_handler(self): mock_communicatior = MagicMock() sdza = SerialDripZAxis(mock_communicatior, 1.0, 0.0) mock_communicatior.register_handler.assert_called_with( DripRecordedMessage, sdza.drip_reported_handler)
def test_init_resets_micro_drip_counter(self): mock_communicatior = MagicMock() starting_height = 10.0 sdza = SerialDripZAxis(mock_communicatior, 1.0, starting_height) mock_communicatior.send.assert_called_with(SetDripCountMessage(0))