Пример #1
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"
            )
Пример #2
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_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")