def test_exitExcludedRegion_zIncreased(self):
        """Test exitExcludedRegion when the final Z is greater than the initial Z."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        unit.excluding = True
        unit.excludeStartTime = time.time()
        unit.feedRate = 1000
        unit.feedRateUnitMultiplier = 1
        unit.lastPosition = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.position = create_position(x=10, y=20, z=30, extruderPosition=40)

        with mock.patch.object(
                unit, '_processPendingCommands') as mockProcessPendingCommands:
            mockProcessPendingCommands.return_value = ["pendingCommand"]

            result = unit.exitExcludedRegion("G1 X1 Y2")

            mockProcessPendingCommands.assert_called_with()
            self.assertEqual(
                result, [
                    "pendingCommand", "G92 E40", "G0 F1000 Z30",
                    "G0 F1000 X10 Y20"
                ], "The result should be a list of the expected commands.")
            self.assertFalse(unit.excluding,
                             "The excluding flag should be cleared.")
Esempio n. 2
0
    def test_processLinearMoves_excluding_noPointInExcludedRegion(self):
        """Test processLinearMoves when points not in an excluded region and currently excluding."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = True
        unit.position = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = 1

        with mock.patch.multiple(unit,
                                 isAnyPointExcluded=mock.DEFAULT,
                                 exitExcludedRegion=mock.DEFAULT,
                                 _processNonMove=mock.DEFAULT) as mocks:
            mocks["isAnyPointExcluded"].return_value = False
            mocks["exitExcludedRegion"].return_value = ["expectedResult"]

            result = unit.processLinearMoves("G1 X10 Y20", None, None, None,
                                             10, 20)

            mocks["isAnyPointExcluded"].assert_called_with(10, 20)
            mocks["exitExcludedRegion"].assert_called_with("G1 X10 Y20")
            mocks["_processNonMove"].assert_not_called()
            self.assertEqual(
                result, ["expectedResult"],
                "The result of exitExcludedRegion should be returned.")
Esempio n. 3
0
    def test_processLinearMoves_extruderPositionDecreased_move(self):
        """Test processLinearMoves for move and a smaller extruderPosition."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False
        unit.position = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = 1

        with mock.patch.object(
                unit,
                'recoverRetractionIfNeeded') as mockRecoverRetractionIfNeeded:
            mockRecoverRetractionIfNeeded.return_value = ["expectedResult"]

            result = unit.processLinearMoves("G1 X2 Y3 E0", 0, None, None, 2,
                                             3)

            mockRecoverRetractionIfNeeded.assert_called_with(
                "G1 X2 Y3 E0", False)

            self.assertEqual(
                unit.position.E_AXIS.current, 0,
                "The extruder position should be updated to the new value")
            self.assertEqual(
                result, ["expectedResult"],
                "It should return the result of recoverRetractionIfNeeded")
Esempio n. 4
0
    def test_processLinearMoves_pointInExcludedRegion(self):
        """Test processLinearMoves with a point in excluded region."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = True
        unit.position = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = 1

        with mock.patch.multiple(unit,
                                 isAnyPointExcluded=mock.DEFAULT,
                                 _processExcludedMove=mock.DEFAULT) as mocks:
            mocks["isAnyPointExcluded"].return_value = True
            mocks["_processExcludedMove"].return_value = [
                "processExcludedMove"
            ]

            result = unit.processLinearMoves("G1 X10 Y20", 3, None, None, 10,
                                             20)

            mocks["isAnyPointExcluded"].assert_called_with(10, 20)
            mocks["_processExcludedMove"].assert_called_with("G1 X10 Y20", -1)
            self.assertEqual(
                result, ["processExcludedMove"],
                "The result should be the commands returned by _processExcludedMove"
            )
Esempio n. 5
0
    def test_recoverRetractionIfNeeded_lastRetraction_notExcluding(self):
        """Test recoverRetractionIfNeeded with a lastRetraction and NOT excluding."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        with mock.patch.multiple(unit,
                                 _recoverRetraction=mock.DEFAULT,
                                 lastRetraction=mock.DEFAULT) as mocks:
            unit.excluding = False
            unit.lastRetraction.recoverExcluded = False
            unit.lastRetraction.allowCombine = True
            mocks["_recoverRetraction"].return_value = ["expectedCommand"]

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

            mocks["_recoverRetraction"].assert_called_with("G11", True)
            self.assertEqual(unit.lastRetraction, mocks["lastRetraction"],
                             "The lastRetraction should not be updated")
            self.assertFalse(unit.lastRetraction.allowCombine,
                             "allowCombine should be set to False")
            self.assertFalse(unit.lastRetraction.recoverExcluded,
                             "recoverExcluded should not be updated")
            self.assertEqual(
                result, ["expectedCommand"],
                "The result should match the list of commands returned by _recoverRetraction"
            )
Esempio n. 6
0
    def test_recoverRetractionIfNeeded_lastRetraction_excluding_notRecoveryCommand(
            self):
        """Test recoverRetractionIfNeeded with lastRetraction, excluding and NO recoveryCommand."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        with mock.patch.multiple(unit,
                                 _recoverRetraction=mock.DEFAULT,
                                 lastRetraction=mock.DEFAULT) as mocks:
            unit.excluding = True
            unit.lastRetraction.recoverExcluded = False
            unit.lastRetraction.allowCombine = True

            result = unit.recoverRetractionIfNeeded("G1 X1 Y2 E3", False)

            # The test against this mock covers both cases where returnCommands None and when it is
            # a list of commands since the final result is built from the _recoverRetraction result
            # which is mocked anyway
            mocks["_recoverRetraction"].assert_not_called()
            self.assertEqual(unit.lastRetraction, mocks["lastRetraction"],
                             "The lastRetraction should not be updated")
            self.assertFalse(unit.lastRetraction.allowCombine,
                             "allowCombine should be set to False")
            self.assertFalse(unit.lastRetraction.recoverExcluded,
                             "recoverExcluded should not be updated")
            self.assertEqual(result, [], "The result should be an empty list.")
    def _test_enterExcludedRegion_common(self, enteringExcludedRegionGcode):
        """Test common functionality of enterExcludedRegion when exclusion is enabled."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        unit.excluding = False
        unit.excludeStartTime = "oldStartTime"
        unit.numExcludedCommands = 42
        unit.numCommands = 84
        unit.lastPosition = "oldPosition"

        unit.enteringExcludedRegionGcode = enteringExcludedRegionGcode

        result = unit.enterExcludedRegion("G1 X1 Y2")

        self.assertTrue(unit.excluding, "The excluding flag should be True")
        self.assertNotEqual(unit.excludeStartTime, "oldStartTime",
                            "The excludeStartTime should be updated")
        self.assertEqual(unit.numExcludedCommands, 0,
                         "The numExcludedCommands should be reset to 0")
        self.assertEqual(unit.numCommands, 0,
                         "The numCommands should be reset to 0")
        self.assertNotEqual(unit.lastPosition, "oldPosition",
                            "The position should be updated")

        return result
Esempio n. 8
0
    def test_processLinearMoves_unitMultiplier(self):
        """Test processLinearMoves when a non-native unit multiplier is in effect."""
        mockLogger = mock.Mock()
        mockLogger.isEnabledFor.return_value = False  # For coverage

        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False
        unit.position = create_position(x=1,
                                        y=2,
                                        z=3,
                                        extruderPosition=4,
                                        unitMultiplier=INCH_TO_MM_FACTOR)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = INCH_TO_MM_FACTOR

        originalIsAnyPointExcluded = unit.isAnyPointExcluded

        def is_any_point_excluded_side_effect(self, *args):
            originalIsAnyPointExcluded(self, *args)
            return True

        with mock.patch.multiple(
                unit,
                _processExcludedMove=mock.DEFAULT,
                isAnyPointExcluded=mock.DEFAULT,
                recoverRetractionIfNeeded=mock.DEFAULT) as mocks:
            mocks[
                "isAnyPointExcluded"].side_effect = is_any_point_excluded_side_effect
            mocks["_processExcludedMove"].return_value = [
                "processExcludedMove"
            ]

            result = unit.processLinearMoves("G1 X1 Y2 Z3 E-1 F100", -1, 100,
                                             3, 1, 2)

            mocks["isAnyPointExcluded"].assert_called_with(1, 2)
            mocks["recoverRetractionIfNeeded"].assert_not_called()
            mocks["_processExcludedMove"].assert_called_with(
                "G1 X1 Y2 Z3 E-1 F100", -4 - 1 * INCH_TO_MM_FACTOR)
            self.assertEqual(
                unit.feedRate, 100 * INCH_TO_MM_FACTOR,
                "The feedRate should be updated to the expected value.")
            self.assertEqual(result, ["processExcludedMove"],
                             "The expected result should be returned.")
            self.assertEqual(
                unit.position.X_AXIS.current, 1 * INCH_TO_MM_FACTOR,
                "The X axis position should be updated from 1 mm to 1 in.")
            self.assertEqual(
                unit.position.Y_AXIS.current, 2 * INCH_TO_MM_FACTOR,
                "The Y axis position should be updated from 2 mm to 2 in.")
            self.assertEqual(
                unit.position.Z_AXIS.current, 3 * INCH_TO_MM_FACTOR,
                "The Z axis position should be updated from 3 mm to 3 in.")
            self.assertEqual(
                unit.position.E_AXIS.current, -1 * INCH_TO_MM_FACTOR,
                "The Z axis position should be updated from 4 mm to -1 in.")
    def test_exitExcludedRegion_notExcluding(self):
        """Test exitExcludedRegion when not currently excluding."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        unit.excluding = False

        with mock.patch.object(
                unit, '_processPendingCommands') as mockProcessPendingCommands:
            result = unit.exitExcludedRegion("G1 X1 Y2")

            mockProcessPendingCommands.assert_not_called()
            self.assertEqual(result, [], "An empty list should be returned.")
Esempio n. 10
0
    def test_processLinearMoves_feedRate_None(self):
        """Test processLinearMoves when None is passed for a feedRate value."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False
        unit.position = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = 1

        unit.processLinearMoves("G1 Z1", None, None, 1)

        self.assertEqual(unit.feedRate, 4000,
                         "The feedRate should not be modified")
Esempio n. 11
0
    def test_processLinearMoves_feedRate_Different(self):
        """Test processLinearMoves when the feedRate parameter doesn't match the current value."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False
        unit.position = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = 1

        unit.processLinearMoves("G1 Z1", None, 1000, 1)

        self.assertEqual(unit.feedRate, 1000,
                         "The feedRate should be updated to the new value")
    def test_processExtendedGcode_noGcode_notExcluding(self):
        """Test processExtendedGcode when not excluding and no gcode provided."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        with mock.patch.object(
                unit, 'extendedExcludeGcodes') as mockExtendedExcludeGcodes:
            unit.excluding = False

            result = unit.processExtendedGcode("someCommand", None, None)

            mockExtendedExcludeGcodes.get.assert_not_called()
            self.assertIsNone(result, "The return value should be None")
    def test_exitExcludedRegion_excluding(self):
        """Test exitExcludedRegion when already excluding."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        unit.excluding = True
        unit.numCommands = 10

        result = unit.enterExcludedRegion("G1 X1 Y2")

        self.assertEqual(unit.numCommands, 10,
                         "The numCommands should not be updated.")
        self.assertEqual(result, [], "An empty list should be returned.")
Esempio n. 14
0
    def test_processExcludedMove_excluding_nonRetract(self):
        """Test _processExcludedMove with a non-retraction move and excluding=True."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = True

        with mock.patch.multiple(unit,
                                 enterExcludedRegion=mock.DEFAULT,
                                 _processNonMove=mock.DEFAULT) as mocks:
            result = unit._processExcludedMove("G1 X10 Y20", 0)  # pylint: disable=protected-access

            mocks["enterExcludedRegion"].assert_not_called()
            mocks["_processNonMove"].assert_not_called()
            self.assertEqual(result, [], "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")
    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.")
Esempio n. 17
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. 18
0
    def test_processLinearMoves_finalZ_Decreased(self):
        """Test processLinearMoves when the finalZ is less than the current Z axis position."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False
        unit.position = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = 1

        result = unit.processLinearMoves("G1 Z0", None, None, 0)

        self.assertEqual(unit.position.Z_AXIS.current, 0,
                         "The Z axis position should be the expected value.")
        self.assertEqual(
            result, ["G1 Z0"],
            "A list containing the provided command should be returned.")
Esempio n. 19
0
    def test_processLinearMoves_extruderPositionSame_move(self):
        """Test processLinearMoves for move and extruderPosition matching the current value."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False
        unit.position = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = 1

        result = unit.processLinearMoves("G1 X2 Y3 E4", 4, None, None, 2, 3)

        self.assertEqual(unit.position.E_AXIS.current, 4,
                         "The extruder position should be the expected value")
        self.assertEqual(
            result, ["G1 X2 Y3 E4"],
            "It should return a list containing the provided command")
    def test_disableExclusion_exclusionEnabled_excluding(
            self, mockExitExcludedRegion):
        """Test the disableExclusion method when exclusion is enabled and currently excluding."""
        mockExitExcludedRegion.return_value = ["ABC"]
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = True

        returnedCommands = unit.disableExclusion("Redundant disable for test")

        self.assertFalse(unit.isExclusionEnabled(),
                         "isExclusionEnabled should report False")
        mockExitExcludedRegion.assert_called_with("Redundant disable for test")
        self.assertEqual(
            returnedCommands, ["ABC"],
            "The commands returned by exitExcludeRegion should be returned")
    def test_processExtendedGcode_excluding_noMatch(self):
        """Test processExtendedGcode when excluding and no entry matches."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        with mock.patch.multiple(
                unit,
                extendedExcludeGcodes=mock.DEFAULT,
                _processExtendedGcodeEntry=mock.DEFAULT) as mocks:
            unit.excluding = True
            mocks["extendedExcludeGcodes"].get.return_value = None

            result = unit.processExtendedGcode("G1 X1 Y2", "G1", None)

            mocks["extendedExcludeGcodes"].get.assert_called_with("G1")
            mocks["_processExtendedGcodeEntry"].assert_not_called()
            self.assertIsNone(result, "The return value should be None")
    def test_processNonMove_deltaE_zero_excluding(self):
        """Test _processNonMove when deltaE is 0 and excluding."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        with mock.patch.multiple(
                unit,
                recordRetraction=mock.DEFAULT,
                recoverRetractionIfNeeded=mock.DEFAULT) as mocks:
            unit.excluding = True
            unit.feedRate = 100

            result = unit._processNonMove("G0 E0 F100", 0)  # pylint: disable=protected-access

            mocks["recordRetraction"].assert_not_called()
            mocks["recoverRetractionIfNeeded"].assert_not_called()
            self.assertEqual(result, [], "The result should be an empty list")
Esempio n. 23
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_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")
Esempio n. 26
0
    def test_processExcludedMove_notExcluding_retract(self):
        """Test _processExcludedMove with a retraction while moving and excluding=False."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False

        with mock.patch.multiple(unit,
                                 enterExcludedRegion=mock.DEFAULT,
                                 _processNonMove=mock.DEFAULT) as mocks:
            mocks["enterExcludedRegion"].return_value = ["enterExcludedRegion"]
            mocks["_processNonMove"].return_value = ["processNonMove"]

            result = unit._processExcludedMove("G1 X10 Y20", -1)  # pylint: disable=protected-access

            mocks["enterExcludedRegion"].assert_called_with("G1 X10 Y20")
            mocks["_processNonMove"].assert_called_with("G1 X10 Y20", -1)
            self.assertEqual(
                result, ["enterExcludedRegion", "processNonMove"],
                "The result should contain the expected commands")
Esempio n. 27
0
    def test_processExcludedMove_notExcluding_nonRetract(self):
        """Test _processExcludedMove with a non-retraction move and excluding=False."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False

        with mock.patch.multiple(unit,
                                 enterExcludedRegion=mock.DEFAULT,
                                 _processNonMove=mock.DEFAULT) as mocks:
            mocks["enterExcludedRegion"].return_value = ["enterExcludedRegion"]

            result = unit._processExcludedMove("G1 X10 Y20", 0)  # pylint: disable=protected-access

            mocks["enterExcludedRegion"].assert_called_with("G1 X10 Y20")
            mocks["_processNonMove"].assert_not_called()
            self.assertEqual(
                result, ["enterExcludedRegion"],
                "The result should be the commands returned by enterExcludedRegion"
            )
Esempio n. 28
0
    def test_processLinearMoves_notExcluding_noPointInExcludedRegion(self):
        """Test processLinearMoves with point not in an excluded region and excluding=False."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.excluding = False
        unit.position = create_position(x=1, y=2, z=3, extruderPosition=4)
        unit.feedRate = 4000
        unit.feedRateUnitMultiplier = 1

        with mock.patch.object(unit,
                               'isAnyPointExcluded') as mockIsAnyPointExcluded:
            mockIsAnyPointExcluded.return_value = False

            result = unit.processLinearMoves("G1 X10 Y20", None, None, None,
                                             10, 20)

            mockIsAnyPointExcluded.assert_called_with(10, 20)
            self.assertEqual(
                result, ["G1 X10 Y20"],
                "A list containing the provided command 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.")
    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