Example #1
0
    def test_delete_alarm(self):
        al, alarm_list = create_alarm_list_and_test_alarm()
        for alarm, activated in TEST_ALARMS:
            alarm_list.add_alarm(alarm, activated)

        sample_alarm = alarm_list.get_active_alarms()[0]

        button_control = buttons.ButtonControl()
        button_control.set_sequence([False, False, True], buttons.DELETE)
        app = init_alarm_app(alarm_list, button_control)
        app.setup()

        for i in range(2):
            active_alarms = app.alarm_list.get_active_alarms()
            self.assertIn(sample_alarm,
                          active_alarms,
                          msg="Alarm deleted too early")

            button_control.update()
            nav, child = app.update()
            self.assertIsNone(child, msg="Unexpected child")
            self.assertEqual(nav,
                             MenuNode.NO_NAVIGATION,
                             msg="Expected NO_NAVIGATION")

        active_alarms = app.alarm_list.get_active_alarms()
        self.assertNotIn(sample_alarm, active_alarms, msg="Alarm not deleted")
Example #2
0
def init_alarm_app(alarm_list=None, button_control=None):
    """
    Inits an alarm app.

    void -> AlarmApplication
    AlarmList -> ButtonControl -> AlarmApplication
    """
    if alarm_list is None:
        _, alarm_list = create_alarm_list_and_test_alarm()
    display_ = display.Display()
    led_control = ledcontrol.LEDControl()
    if button_control is None:
        button_control = buttons.ButtonControl()
    return alarm_app.AlarmApplication(display_, led_control, alarm_list,
                                      button_control)
Example #3
0
    def test_activate_alarm(self):
        al, alarm_list = create_alarm_list_and_test_alarm()
        for alarm, activated in TEST_ALARMS:
            alarm_list.add_alarm(alarm, activated)

        # needs to be the last one
        sample_alarm = alarm_list.get_inactive_alarms()[-1]

        button_control = buttons.ButtonControl()
        button_control.set_sequence([False, False, True], buttons.SET)

        # navigate left to the last inactivated alarm
        button_control.set_sequence([True, True, False], buttons.LEFT)
        app = init_alarm_app(alarm_list, button_control)
        app.setup()

        for i in range(2):
            inactive_alarms = app.alarm_list.get_inactive_alarms()
            active_alarms = app.alarm_list.get_active_alarms()
            self.assertIn(sample_alarm,
                          inactive_alarms,
                          msg="Alarm changed too early")
            self.assertNotIn(sample_alarm,
                             active_alarms,
                             msg="Alarm changed too early")

            nav, child = app.update()
            self.assertIsNone(child, msg="Unexpected child")
            self.assertEqual(nav,
                             MenuNode.NO_NAVIGATION,
                             msg="Expected NO_NAVIGATION")
            button_control.update()

        nav, child = app.update()
        self.assertIsNone(child, msg="Unexpected child")
        self.assertEqual(nav,
                         MenuNode.NO_NAVIGATION,
                         msg="Expected NO_NAVIGATION")

        inactive_alarms = app.alarm_list.get_inactive_alarms()
        active_alarms = app.alarm_list.get_active_alarms()
        self.assertNotIn(sample_alarm,
                         inactive_alarms,
                         msg="Alarm not removed from inactive")
        self.assertIn(sample_alarm,
                      active_alarms,
                      msg="Alarm not added to active")
Example #4
0
    def test_create_new_alarm(self):
        al, alarm_list = create_alarm_list_and_test_alarm()
        for alarm, activated in TEST_ALARMS:
            alarm_list.add_alarm(alarm, activated)

        old_num_alarms = alarm_list.num_alarms()
        old_num_activated = alarm_list.num_active_alarms()

        button_control = buttons.ButtonControl()

        # press the "new"-button
        button_control.set_sequence([False, True], buttons.ENTER)

        # navigate left to the new-option
        button_control.set_sequence([True, False], buttons.LEFT)

        app = init_alarm_app(alarm_list, button_control)
        app.setup()

        num_alarms = app.alarm_list.num_alarms()
        num_activated = app.alarm_list.num_active_alarms()
        self.assertEqual(num_alarms,
                         old_num_alarms,
                         msg="Alarm added too soon")
        self.assertEqual(num_activated,
                         old_num_activated,
                         msg="Alarm added too soon")

        nav, child = app.update()
        self.assertIsNone(child, msg="Unexpected child")
        self.assertEqual(nav,
                         MenuNode.NO_NAVIGATION,
                         msg="Expected NO_NAVIGATION")

        button_control.update()

        nav, child = app.update()
        self.assertIsNotNone(child, msg="Child should not be None")
        self.assertEqual(nav, MenuNode.ENTER, msg="Expected NO_NAVIGATION")

        num_alarms = app.alarm_list.num_alarms()
        num_activated = app.alarm_list.num_active_alarms()
        self.assertEqual(num_alarms, old_num_alarms + 1, msg="Alarm not added")
        self.assertEqual(num_activated,
                         old_num_activated + 1,
                         msg="Alarm not active or added")