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.")
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.")
def test_exitExcludedRegion_unitMultiplier(self): """Test exitExcludedRegion when a non-native unit multiplier is in effect.""" mockLogger = mock.Mock() unit = ExcludeRegionState(mockLogger) unit.excluding = True unit.excludeStartTime = time.time() unit.feedRate = 1000 unit.feedRateUnitMultiplier = INCH_TO_MM_FACTOR unit.lastPosition = create_position(x=1, y=2, z=3, extruderPosition=4, unitMultiplier=INCH_TO_MM_FACTOR) unit.position = create_position(x=10, y=20, z=30, extruderPosition=40, unitMultiplier=INCH_TO_MM_FACTOR) with mock.patch.object( unit, '_processPendingCommands') as mockProcessPendingCommands: mockProcessPendingCommands.return_value = [] result = unit.exitExcludedRegion("G1 X1 Y2") mockProcessPendingCommands.assert_called_with() self.assertEqual( result, [ "G92 E%s" % (40 / INCH_TO_MM_FACTOR), "G0 F%s Z%s" % (1000 / INCH_TO_MM_FACTOR, 30 / INCH_TO_MM_FACTOR), "G0 F%s X%s Y%s" % (1000 / INCH_TO_MM_FACTOR, 10 / INCH_TO_MM_FACTOR, 20 / INCH_TO_MM_FACTOR) ], "The result should be a list of the expected commands.") self.assertFalse(unit.excluding, "The excluding flag should be cleared.")