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")
    def test_recoverRetractionIfNeeded_noLastRetraction_excluding(self):
        """Test recoverRetractionIfNeeded with NO lastRetraction and excluding (do nothing)."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        with mock.patch.object(unit,
                               '_recoverRetraction') as recoverRetractionMock:
            unit.lastRetraction = None
            unit.excluding = True

            result = unit.recoverRetractionIfNeeded("G11", True)

            recoverRetractionMock.assert_not_called()
            self.assertIsNone(unit.lastRetraction,
                              "The lastRetraction should not be updated")
            self.assertEqual(result, [], "The result should be an empty list.")
    def test_recoverRetractionIfNeeded_noLastRetraction_notExcluding_isRecoveryCommand(
            self):
        """Test recoverRetractionIfNeeded with NO lastRetraction, not excluding, is recovery."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        with mock.patch.object(unit,
                               '_recoverRetraction') as recoverRetractionMock:
            unit.lastRetraction = None
            unit.excluding = False

            result = unit.recoverRetractionIfNeeded("G1 E1", True)

            recoverRetractionMock.assert_not_called()
            self.assertIsNone(unit.lastRetraction,
                              "The lastRetraction should not be updated")
            self.assertEqual(
                result, ["G1 E1"],
                "The result should contain only the provided command")
    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 _resetStateSetup():
        """Create and initialize the instance to test the resetState method on."""
        # pylint: disable=protected-access
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        unit.excludedRegions = ["abc"]
        unit.position.X_AXIS.current = 100
        unit.feedRate = 100
        unit.feedRateUnitMultiplier = 1234
        unit._exclusionEnabled = False
        unit.excluding = True
        unit.excludeStartTime = None
        unit.numExcludedCommands = 4321
        unit.numCommands = 6789
        unit.lastRetraction = "abc"
        unit.lastPosition = "123"
        unit.pendingCommands = {"a": 1}

        return unit