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
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.")
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