def test_recordRetraction_recoverExcluded_firmwareRetract(self):
        """Test recordRetraction with recoverExcluded=True and a firmware retract."""
        mockRetractionState = mock.Mock()
        mockRetractionState.originalCommand = "retractionCommand"

        mockLogger = mock.Mock()

        unit = ExcludeRegionState(mockLogger)
        with mock.patch.object(unit, 'lastRetraction'):
            unit.feedRate = 20
            unit.lastRetraction.recoverExcluded = True
            unit.lastRetraction.firmwareRetract = True
            unit.lastRetraction.feedRate = None

            returnCommands = unit.recordRetraction(mockRetractionState)

            self.assertFalse(
                unit.lastRetraction.recoverExcluded,
                "lastRetraction.recoverExcluded should be set to False")

            self.assertIsNone(
                unit.lastRetraction.feedRate,
                "The retraction feedRate should not be modified.")

            self.assertEqual(returnCommands, [],
                             "The result should be an empty list.")
    def test_recordRetraction_noLastRetraction_notExcluding(self):
        """Test recordRetraction with no lastRetraction and not excluding."""
        mockRetractionState = mock.Mock()
        mockRetractionState.originalCommand = "retractionCommand"

        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False
        unit.lastRetraction = None

        returnCommands = unit.recordRetraction(mockRetractionState)

        mockRetractionState.generateRetractCommands.assert_not_called()
        self.assertEqual(returnCommands, ["retractionCommand"],
                         "The original retraction command should be returned")
Esempio n. 3
0
    def test_recordRetraction_noRecoverExcluded_noCombine_excluding(self):
        """Test recordRetraction with recoverExcluded=False and excluding."""
        mockRetractionState = mock.Mock()

        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        with mock.patch.object(unit, 'lastRetraction'):
            unit.lastRetraction.recoverExcluded = False
            unit.lastRetraction.allowCombine = False
            unit.excluding = True

            returnCommands = unit.recordRetraction(mockRetractionState)

            self.assertEqual(returnCommands, [],
                             "The result should be an empty list.")
Esempio n. 4
0
    def test_recordRetraction_noRecoverExcluded_noCombine_notExcluding(self):
        """Test recordRetraction with recoverExcluded=False and not excluding."""
        mockRetractionState = mock.Mock()
        mockRetractionState.originalCommand = "retractionCommand"

        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        with mock.patch.object(unit, 'lastRetraction'):
            unit.lastRetraction.recoverExcluded = False
            unit.lastRetraction.allowCombine = False
            unit.excluding = False

            returnCommands = unit.recordRetraction(mockRetractionState)

            mockRetractionState.generateRetractCommands.assert_not_called()
            self.assertEqual(returnCommands, ["retractionCommand"],
                             "The original command should be returned")
    def test_recordRetraction_noLastRetraction_excluding(self):
        """Test recordRetraction when there is no lastRetraction and isExcluding is True."""
        expectedReturnCommands = ["addedCommand"]

        mockRetractionState = mock.Mock()
        mockRetractionState.generateRetractCommands.return_value = expectedReturnCommands

        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = True
        unit.lastRetraction = None

        returnCommands = unit.recordRetraction(mockRetractionState)

        mockRetractionState.generateRetractCommands.assert_called_with(
            unit.position)
        self.assertEqual(returnCommands, expectedReturnCommands,
                         "The expected command(s) should be returned")
    def test_recordRetraction_noRecoverExcluded_excluding(self):
        """Test recordRetraction with recoverExcluded=False and excluding."""
        expectedReturnCommands = ["addedCommand"]

        mockRetractionState = mock.Mock()
        mockRetractionState.generateRetractCommands.return_value = expectedReturnCommands

        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        with mock.patch.object(unit, 'lastRetraction'):
            unit.lastRetraction.recoverExcluded = False
            unit.excluding = True

            returnCommands = unit.recordRetraction(mockRetractionState)

            mockRetractionState.generateRetractCommands.assert_called_with(
                unit.position)
            self.assertEqual(
                returnCommands, expectedReturnCommands,
                "The result from generateRetractCommands should be returned.")