Beispiel #1
0
    def test_get_next_task(self):
        class NextA(object):
            def run(self): pass
        class NextB(object):
            def run(self): pass
        class Last(object):
            def run(self): pass

        nexta = NextA()
        nextb = NextB()
        last_task = Last()

        class ReturnSingle(object):
            def run(self): return nexta
        class ReturnList(object):
            def run(self): return [nexta, nextb]

        returnsingle = ReturnSingle()
        returnlist = ReturnList()

        runner = main.TaskRunner()
        runner.run(returnsingle, last_task)
        self.assertEqual(runner.history, [returnsingle,nexta,last_task])

        runner = main.TaskRunner()
        runner.run(returnlist, last_task)
        self.assertEqual(runner.history, [returnlist,nexta,nextb,last_task])
Beispiel #2
0
    def test_accept_task_class(self):
        side_effect = {"was_run": False}
        class TaskClass(object):
            def run(self, **kwargs):
                side_effect["was_run"] = True

        runner = main.TaskRunner()
        runner.run(TaskClass)
        self.assertTrue(side_effect["was_run"])
Beispiel #3
0
    def test_run_task(self):
        class MockTask(object):
            def __init__(self): self._was_run = False
            def run(self, **kwargs): self._was_run = True

        task = MockTask()

        runner = main.TaskRunner()
        runner.run(task)
        self.assertTrue(task._was_run)
        self.assertNotEqual(main.wdt._feed_count, 0, "WDT should have been fed")
Beispiel #4
0
    def test_runner_tasks(self):

        class OkTask(object):
            def run(self): pass
        class FailTask(object):
            def run(self): raise Exception("Test Exception")

        main.nvs_task_log = main.NvsTaskLog()
        main.nvs_task_log.register(OkTask)
        main.nvs_task_log.register(FailTask)

        runner = main.TaskRunner()
        runner.run(OkTask, FailTask)

        self.assertEqual(main.nvs_task_log.read_run_log(), [
            (OkTask, "START", 1),
            (OkTask, "OK", 1),
            (FailTask, "START", 1),
            (FailTask, "FAIL", 1),
            ])
Beispiel #5
0
    def test_suppress_error(self):
        class MockException(Exception): pass
        exc_val = MockException()

        class ErrorTask(object):
            def run(self, **kwargs):
                raise exc_val
        task = ErrorTask()

        runner = main.TaskRunner()
        try:
            runner.run(task)
        except MockException:
            self.fail("MockException should not be allowed to pass through")

        class KeyboardTask(object):
            def run(self, **kwargs):
                raise KeyboardInterrupt()

        with self.assertRaises(KeyboardInterrupt):
            runner.run(KeyboardTask)
Beispiel #6
0
"""
Top level shell file

This file should contain as little logic as possible.
Its goal is to never lose control of the device into an unrecoverable state (like the REPL).

- The unit should never crash out to the REPL except for a KeyboardInterrupt.
- All other exceptions should result in going back to sleep for a few minutes
  and then trying again.
- In the worst case scenario, the watchdog timer (WDT) will cause a reset.

All allocation and logic should defer to co2unit_main.py.
The exception of this is to set the hw variable to make it easier to work with
if we do exit to the REPL.

Note that the hw object does not actually touch the hardware unless we start
accessing its members.
"""

import co2unit_main2 as main

with main.MainWrapper():

    runner = main.TaskRunner()
    runner.run(main.BootUp, main.SleepUntilScheduled)