From ad4a9fe6c543deca1de8c6db8cda18eba7153ca4 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 1 Jan 2024 21:17:55 +0100 Subject: add responsibility offset When the number of responsibilities is not a factor of 52 the next year has to start with an offset to continue the ongoing cycle. Since the event notifier is state less we pass the needed offset for the current year on the command line. --- test.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'test.py') diff --git a/test.py b/test.py index 5fbdd25..5ca77ea 100644 --- a/test.py +++ b/test.py @@ -8,6 +8,7 @@ import unittest import signal_event_notifier as sen DUMMY_CYCLIC_RESPONSIBILITIES = "alice:+1234\nbob:+5678,charlie:+5679" +DUMMY_CYCLIC_RESPONSIBILITIES_3 = "alice:+1234\nbob:+5678\ncharlie:+5679" TEST_CAL = "test/cal.ics" @@ -33,11 +34,38 @@ class TestCyclicRespLoading(unittest.TestCase): expected = [['alice:+1234'], ['bob:+5678', 'charlie:+5679']] day = datetime.date(year=2013, month=1, day=1) delta = datetime.timedelta(days=7) - for week in range(52): + for week in range(52 * 2): resp = sen.load_responsibilities(day) self.assertEqual(resp, expected[(week % 2)]) day += delta +# pragma pylint: disable=missing-function-docstring,missing-class-docstring,invalid-name +class TestCyclicUnevenRespLoading(unittest.TestCase): + + def setUp(self): + os.environ[ + sen. + RESPONSIBILITIES_ENV_VAR_NAME] = DUMMY_CYCLIC_RESPONSIBILITIES_3 + + def test_cyclic_resp_all_weeks(self): + expected = [['alice:+1234'], ['bob:+5678'], ['charlie:+5679']] + day = datetime.date(year=2013, month=1, day=1) + delta = datetime.timedelta(days=7) + for week in range(52): + resp = sen.load_responsibilities(day) + self.assertEqual(resp, expected[(week % 3)]) + day += delta + + # Second year + expected = [['bob:+5678'], ['charlie:+5679'], ['alice:+1234']] + offset = 1 + + for week in range(52): + resp = sen.load_responsibilities(day, offset=offset) + self.assertEqual(resp, expected[(week % 3)]) + day += delta + + if __name__ == '__main__': unittest.main() -- cgit v1.2.3