def test_enterExcludedRegion_exclusionDisabled(self):
        """Test enterExcludedRegion when exclusion is disabled should raise an AssertionError."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.disableExclusion("Disable for test")

        with self.assertRaises(AssertionError):
            unit.enterExcludedRegion("G1 X1 Y2")
    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.")