Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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())
Ejemplo n.º 3
0
    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())
Ejemplo n.º 4
0
    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())
Ejemplo n.º 5
0
    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]))
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    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())
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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]))
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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())
Ejemplo n.º 12
0
    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())