def test_single_yields_that(self): composite = AlarmComposite() alarm = Alarm() composite.add_alarm(alarm) alarm.add_target_day(Days.MONDAY) self.assertEqual(Days.MONDAY, composite.next_day)
def test__alarm_with_day_set__remove_target_day__unsets_that_days_flag( days_set, day_to_remove): alarm = Alarm() alarm.add_target_day(days_set) alarm.remove_target_day(day_to_remove) assert alarm.target_days & day_to_remove == Days( 0 ) # There should be no overlap between still set bits and the day to remove
def test__mock_date__next_day__returns_expected_day(mock_datetime, set_days, expected_day, freezer): freezer.move_to(mock_datetime) alarm = Alarm() alarm.add_target_day(set_days) alarm.target_hour = 6 alarm.target_minute = 0 next_day = alarm.next_day assert expected_day == next_day
def test__alarm_with_day__add_target_day__target_days_matches_union( day1, day2): alarm = Alarm() alarm.add_target_day(day1) alarm.add_target_day(day2) assert all([ day1 & alarm.target_days, # day1 flag got set day2 & alarm.target_days, # day2 flag got set ])
def test__mock_date__taget_datetime__returns_expected_value( mock_datetime, set_days, expected_target, freezer): freezer.move_to(mock_datetime) alarm = Alarm() alarm.add_target_day(set_days) alarm.target_hour = 6 alarm.target_minute = 0 target = alarm.target_datetime assert expected_target == target
def test_double_yields_or(self): composite = AlarmComposite() alarm1 = Alarm() alarm2 = Alarm() composite.add_alarms(alarm1, alarm2) alarm1.add_target_day(Days.MONDAY | Days.TUESDAY) self.assertEqual(Days.MONDAY | Days.TUESDAY, composite.target_days) alarm2.add_target_day(Days.MONDAY | Days.FRIDAY) self.assertEqual(Days.MONDAY | Days.TUESDAY | Days.FRIDAY, composite.target_days)
def test_double_yields_nearest(self): from datetime import datetime with patch("utilities.TestableDateTime") as mock_date: mock_date.now.return_value = datetime( 2006, 1, 1, 6, 0) # 6:00, Sunday, Jan 1st, 2006 composite = AlarmComposite() alarm1 = Alarm() alarm2 = Alarm() composite.add_alarms(alarm1, alarm2) alarm1.add_target_day(Days.FRIDAY) alarm2.add_target_day(Days.SATURDAY) self.assertEqual(Days.FRIDAY, composite.next_day)
def test_single_yields_that(self): from datetime import datetime with patch("utilities.TestableDateTime") as mock_date: mock_date.now.return_value = datetime( 2006, 1, 1, 6, 0) # 6:00, Sunday, Jan 1st, 2006 composite = AlarmComposite() alarm = Alarm() composite.add_alarm(alarm) alarm.add_target_day(Days.SUNDAY) alarm.target_hour = 6 alarm.target_minute = 5 self.assertEqual(alarm.get_desired_brightness(), composite.get_desired_brightness())
def test_double_yields_nearest(self): from datetime import datetime with patch("utilities.TestableDateTime") as mock_date: mock_date.now.return_value = datetime( 2006, 1, 1, 6, 0) # 6:00, Sunday, Jan 1st, 2006 composite = AlarmComposite() alarm1 = Alarm() alarm2 = Alarm() composite.add_alarms(alarm1, alarm2) alarm1.add_target_day(Days.FRIDAY) alarm1.target_hour = 6 alarm1.target_minute = 0 alarm2.add_target_day(Days.SUNDAY) alarm2.target_hour = 6 alarm2.target_minute = 20 self.assertEqual(alarm2.get_desired_brightness(), composite.get_desired_brightness())
def test_single_yields_that(self): composite = AlarmComposite() alarm = Alarm() composite.add_alarm(alarm) self.assertEqual(Days(0), composite.target_days) alarm.add_target_day(Days.MONDAY) self.assertEqual(Days.MONDAY, composite.target_days) alarm.remove_target_day(Days.MONDAY) self.assertEqual(Days(0), composite.target_days) alarm.add_target_day(Days.ALL) self.assertEqual(Days.ALL, composite.target_days) alarm.remove_target_day(Days.ALL) alarm.add_target_day(Days.WEDNESDAY) self.assertEqual(Days.WEDNESDAY, composite.target_days)
def test__new_alarm__add_target_day__target_days_matches(day): alarm = Alarm() alarm.add_target_day(day) assert day == alarm.target_days
def default_alarm(): alarm = Alarm() alarm.add_target_day(Days.SUNDAY) alarm.target_hour = 6 alarm.target_minute = 0 yield alarm