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_isExclusionEnabled_disabled(self):
        """Test the isExclusionEnabled method when exclusion is disabled."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        unit.disableExclusion("Disable for test")

        self.assertFalse(unit.isExclusionEnabled(),
                         "isExclusionEnabled should report False")
    def test_enableExclusion_exclusionDisabled(self):
        """Test the enableExclusion method when exclusion is disabled."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.disableExclusion("Disable for test")

        unit.enableExclusion("Re-enable for test")

        self.assertTrue(unit.isExclusionEnabled(),
                        "isExclusionEnabled should report True")
    def test_isAnyPointExcluded_exclusionDisabled(self):
        """Test the isAnyPointExcluded method when exclusion is disabled."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        aRegion = RectangularRegion(x1=0, y1=0, x2=5, y2=5)
        unit.addRegion(aRegion)
        unit.disableExclusion("Disable for test")

        self.assertFalse(unit.isAnyPointExcluded(0, 0),
                         "(0,0) should NOT be excluded (exclusion disabled)")
        self.assertFalse(
            unit.isAnyPointExcluded(10, 10),
            "(10,10) should NOT be excluded (exclusion disabled)")
    def test_disableExclusion_exclusionDisabled(self, mockExitExcludedRegion):
        """Test the disableExclusion method when exclusion is already disabled."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)
        unit.disableExclusion("Initial disable for test")
        mockLogger.reset_mock()

        returnedCommands = unit.disableExclusion(
            "Second disable call, should be ignored")

        mockLogger.debug.assert_called_with(
            RegexMatcher("^Exclusion already disabled"), mock.ANY)
        mockExitExcludedRegion.assert_not_called()
        self.assertFalse(unit.isExclusionEnabled(),
                         "isExclusionEnabled should report False")
        self.assertEqual(returnedCommands, [],
                         "An empty list of commands should be returned")
    def test_disableExclusion_exclusionEnabled_notExcluding(
            self, mockExitExcludedRegion):
        """Test the disableExclusion method when exclusion is enabled and not excluding."""
        mockLogger = mock.Mock()
        unit = ExcludeRegionState(mockLogger)

        returnedCommands = unit.disableExclusion("Disable for test")

        self.assertFalse(unit.isExclusionEnabled(),
                         "isExclusionEnabled should report False")
        mockExitExcludedRegion.assert_not_called()
        self.assertEqual(returnedCommands, [],
                         "An empty list of commands should be returned")
    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")