@@ -114,6 +114,80 @@ class = Mpd
114114
115115 mock_class .create .assert_called_once_with ("Foo" , parser ["check.Foo" ])
116116
117+ def test_error_behavior_defaults_to_active (self , mocker : MockerFixture ) -> None :
118+ mock_class = mocker .patch ("autosuspend.checks.activity.Mpd" )
119+ check = mocker .MagicMock (spec = autosuspend .checks .Activity )
120+ mock_class .create .return_value = check
121+
122+ parser = configparser .ConfigParser ()
123+ parser .read_string ("""
124+ [check.Foo]
125+ class = Mpd
126+ enabled = True
127+ """ )
128+
129+ autosuspend .set_up_checks (
130+ parser , "check" , "activity" , autosuspend .Activity # type: ignore
131+ )
132+
133+ assert check .error_behavior == autosuspend .ErrorBehavior .ACTIVE
134+
135+ def test_error_behavior_can_be_set_to_ignore (self , mocker : MockerFixture ) -> None :
136+ mock_class = mocker .patch ("autosuspend.checks.activity.Mpd" )
137+ check = mocker .MagicMock (spec = autosuspend .checks .Activity )
138+ mock_class .create .return_value = check
139+
140+ parser = configparser .ConfigParser ()
141+ parser .read_string ("""
142+ [check.Foo]
143+ class = Mpd
144+ enabled = True
145+ error_behavior = ignore
146+ """ )
147+
148+ autosuspend .set_up_checks (
149+ parser , "check" , "activity" , autosuspend .Activity # type: ignore
150+ )
151+
152+ assert check .error_behavior == autosuspend .ErrorBehavior .IGNORE
153+
154+ def test_error_behavior_rejects_invalid_value (self , mocker : MockerFixture ) -> None :
155+ mock_class = mocker .patch ("autosuspend.checks.activity.Mpd" )
156+ mock_class .create .return_value = mocker .MagicMock (
157+ spec = autosuspend .checks .Activity
158+ )
159+
160+ parser = configparser .ConfigParser ()
161+ parser .read_string ("""
162+ [check.Foo]
163+ class = Mpd
164+ enabled = True
165+ error_behavior = bogus
166+ """ )
167+
168+ with pytest .raises (autosuspend .ConfigurationError ):
169+ autosuspend .set_up_checks (
170+ parser , "check" , "activity" , autosuspend .Activity # type: ignore
171+ )
172+
173+ def test_error_behavior_not_set_for_wakeups (self , mocker : MockerFixture ) -> None :
174+ mock_class = mocker .patch ("autosuspend.checks.wakeup.File" )
175+ check = mocker .MagicMock (spec = autosuspend .checks .Wakeup )
176+ mock_class .create .return_value = check
177+
178+ parser = configparser .ConfigParser ()
179+ parser .read_string ("""
180+ [wakeup.Foo]
181+ class = File
182+ enabled = True
183+ """ )
184+
185+ autosuspend .set_up_checks (
186+ parser , "wakeup" , "wakeup" , autosuspend .Wakeup # type: ignore
187+ )
188+
189+ assert not hasattr (check , "error_behavior" )
190+
117191 def test_external_class (self , mocker : MockerFixture ) -> None :
118192 mock_class = mocker .patch ("os.path.TestCheck" , create = True )
119193 mock_class .create .return_value = mocker .MagicMock (
@@ -290,6 +364,7 @@ def test_all_called(self, mocker: MockerFixture) -> None:
290364 def test_treat_temporary_errors_as_activity (self , mocker : MockerFixture ) -> None :
291365 matching_check = mocker .MagicMock (spec = autosuspend .Activity )
292366 matching_check .name = "foo"
367+ matching_check .error_behavior = autosuspend .ErrorBehavior .ACTIVE
293368 matching_check .check .side_effect = autosuspend .TemporaryCheckError ()
294369
295370 assert (
@@ -298,6 +373,20 @@ def test_treat_temporary_errors_as_activity(self, mocker: MockerFixture) -> None
298373 )
299374 matching_check .check .assert_called_once_with ()
300375
376+ def test_ignore_temporary_errors_when_configured (
377+ self , mocker : MockerFixture
378+ ) -> None :
379+ matching_check = mocker .MagicMock (spec = autosuspend .Activity )
380+ matching_check .name = "foo"
381+ matching_check .error_behavior = autosuspend .ErrorBehavior .IGNORE
382+ matching_check .check .side_effect = autosuspend .TemporaryCheckError ()
383+
384+ assert (
385+ autosuspend .execute_checks ([matching_check ], False , mocker .MagicMock ())
386+ is False
387+ )
388+ matching_check .check .assert_called_once_with ()
389+
301390
302391class TestExecuteWakeups :
303392 def test_no_wakeups (self , mocker : MockerFixture ) -> None :
0 commit comments