コード例 #1
0
 def test_exception_exit(self):
     class TestException(Exception):
         pass
     with self.assertRaises(TestException):
         with main.MainWrapper():
             raise TestException()
     self.assertTrue(main.machine._deepsleep_called)
     self.assertEqual(main.machine._deepsleep_time_ms, main.LAST_RESORT_DEEPSLEEP_MS)
コード例 #2
0
    def test_wdt_control(self):

        with self.assertRaises(KeyboardInterrupt):
            with main.MainWrapper() as mw:
                self.assertEqual(main.wdt._init_count, 1)
                self.assertEqual(main.wdt._init_timeout_ms, main.RUNNING_WDT_MS)
                raise KeyboardInterrupt()

        self.assertEqual(main.wdt._init_count, 2)
        self.assertEqual(main.wdt._init_timeout_ms, main.REPL_WDT_MS)
コード例 #3
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)
コード例 #4
0
 def test_keyboard_interrupt(self):
     with self.assertRaises(KeyboardInterrupt):
         with main.MainWrapper():
             raise KeyboardInterrupt()
     self.assertFalse(main.machine._deepsleep_called)
     self.assertTrue(main.sys._exit_called)
コード例 #5
0
 def test_normal_exit(self):
     with main.MainWrapper():
         pass
     self.assertTrue(main.machine._deepsleep_called)
     self.assertEqual(main.machine._deepsleep_time_ms, main.LAST_RESORT_DEEPSLEEP_MS)