From 8953b2237f139ae362b76062aac92fbb00c93f5b Mon Sep 17 00:00:00 2001 From: deltragon Date: Sun, 25 Aug 2024 22:36:38 +0200 Subject: [PATCH] reorder methods --- safeeyes/tests/test_core.py | 184 ++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 91 deletions(-) diff --git a/safeeyes/tests/test_core.py b/safeeyes/tests/test_core.py index ffa324a..e607325 100644 --- a/safeeyes/tests/test_core.py +++ b/safeeyes/tests/test_core.py @@ -167,97 +167,6 @@ class TestSafeEyesCore: if handle: handle.stop() - def test_create_empty(self): - context = {} - config = { - "short_breaks": [], - "long_breaks": [], - "short_break_interval": 15, - "long_break_interval": 75, - "long_break_duration": 60, - "short_break_duration": 15, - "random_order": False, - "postpone_duration": 5, - } - safe_eyes_core = core.SafeEyesCore(context) - safe_eyes_core.initialize(config) - - - def test_start_empty(self, sequential_threading): - - context = {} - config = { - "short_breaks": [], - "long_breaks": [], - "short_break_interval": 15, - "long_break_interval": 75, - "long_break_duration": 60, - "short_break_duration": 15, - "random_order": False, - "postpone_duration": 5, - } - on_update_next_break = mock.Mock() - safe_eyes_core = core.SafeEyesCore(context) - safe_eyes_core.on_update_next_break += mock - - safe_eyes_core.initialize(config) - - safe_eyes_core.start() - safe_eyes_core.stop() - - on_update_next_break.assert_not_called() - - - def test_start(self, sequential_threading, time_machine): - context = { - "session": {}, - } - config = { - "short_breaks": [ - {"name": "break 1"}, - {"name": "break 2"}, - {"name": "break 3"}, - {"name": "break 4"}, - ], - "long_breaks": [ - {"name": "long break 1"}, - {"name": "long break 2"}, - {"name": "long break 3"}, - ], - "short_break_interval": 15, - "long_break_interval": 75, - "long_break_duration": 60, - "short_break_duration": 15, - "random_order": False, - "postpone_duration": 5, - } - on_update_next_break = mock.Mock() - safe_eyes_core = core.SafeEyesCore(context) - safe_eyes_core.on_update_next_break += on_update_next_break - - safe_eyes_core.initialize(config) - - sequential_threading_handle = sequential_threading(safe_eyes_core) - - safe_eyes_core.start() - - # start __scheduler_job - sequential_threading_handle.next() - - assert context['state'] == model.State.WAITING - - on_update_next_break.assert_called_once() - assert isinstance(on_update_next_break.call_args[0][0], model.Break) - assert on_update_next_break.call_args[0][0].name == "translated!: break 1" - on_update_next_break.reset_mock() - - # wait for end of __scheduler_job - we cannot stop while waiting on the condvar - # this just moves us into waiting for __wait_until_prepare to start - sequential_threading_handle.next() - - safe_eyes_core.stop() - assert context['state'] == model.State.STOPPED - def run_next_break( self, @@ -348,11 +257,104 @@ class TestSafeEyesCore: assert context['state'] == model.State.BREAK + def assert_datetime(self, string): if not string.endswith("+00:00"): string += "+00:00" assert datetime.datetime.now(datetime.timezone.utc) == datetime.datetime.fromisoformat(string) + + def test_create_empty(self): + context = {} + config = { + "short_breaks": [], + "long_breaks": [], + "short_break_interval": 15, + "long_break_interval": 75, + "long_break_duration": 60, + "short_break_duration": 15, + "random_order": False, + "postpone_duration": 5, + } + safe_eyes_core = core.SafeEyesCore(context) + safe_eyes_core.initialize(config) + + + def test_start_empty(self, sequential_threading): + context = {} + config = { + "short_breaks": [], + "long_breaks": [], + "short_break_interval": 15, + "long_break_interval": 75, + "long_break_duration": 60, + "short_break_duration": 15, + "random_order": False, + "postpone_duration": 5, + } + on_update_next_break = mock.Mock() + safe_eyes_core = core.SafeEyesCore(context) + safe_eyes_core.on_update_next_break += mock + + safe_eyes_core.initialize(config) + + safe_eyes_core.start() + safe_eyes_core.stop() + + on_update_next_break.assert_not_called() + + + def test_start(self, sequential_threading, time_machine): + context = { + "session": {}, + } + config = { + "short_breaks": [ + {"name": "break 1"}, + {"name": "break 2"}, + {"name": "break 3"}, + {"name": "break 4"}, + ], + "long_breaks": [ + {"name": "long break 1"}, + {"name": "long break 2"}, + {"name": "long break 3"}, + ], + "short_break_interval": 15, + "long_break_interval": 75, + "long_break_duration": 60, + "short_break_duration": 15, + "random_order": False, + "postpone_duration": 5, + } + on_update_next_break = mock.Mock() + safe_eyes_core = core.SafeEyesCore(context) + safe_eyes_core.on_update_next_break += on_update_next_break + + safe_eyes_core.initialize(config) + + sequential_threading_handle = sequential_threading(safe_eyes_core) + + safe_eyes_core.start() + + # start __scheduler_job + sequential_threading_handle.next() + + assert context['state'] == model.State.WAITING + + on_update_next_break.assert_called_once() + assert isinstance(on_update_next_break.call_args[0][0], model.Break) + assert on_update_next_break.call_args[0][0].name == "translated!: break 1" + on_update_next_break.reset_mock() + + # wait for end of __scheduler_job - we cannot stop while waiting on the condvar + # this just moves us into waiting for __wait_until_prepare to start + sequential_threading_handle.next() + + safe_eyes_core.stop() + assert context['state'] == model.State.STOPPED + + def test_full_run_with_defaults(self, sequential_threading, time_machine): context = { "session": {},