LED Stimulus

This test will just turn on some of the pyboard’s onboard LEDs, nothing is actually asserted.

The concept of creating a bench TestCase class is introduced.

Bench Setup

The only requirement for this test is a pyboard connected via USB.

The setup of the bench is absracted to a BenchTest class.

class BenchTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.pyb_a = upytester.project.get_device('pyb_a')

    @classmethod
    def tearDownClass(cls):
        cls.pyb_a.close()

The setUpClass() and tearDownClass() methods are used to configure the pyboard for all tests in any inheriting class.

Test Case

The LEDTest class inherits from BenchTest, giving each test contextual access to the configured pyboard as self.pyb_a.

class LEDTest(BenchTest):

    def test_blink(self):
        """
        Turn red LED on for 500ms (non-blocking)
        """
        self.pyb_a.blink_led(duration=500)
        time.sleep(0.5)  # just wait so tests don't run at the same time

    def test_led_set(self):
        """
        Turn green LED on for 500ms (blocking)
        """
        self.pyb_a.set_led(led=2, intensity=0xff)  # on
        time.sleep(0.5)
        self.pyb_a.set_led(led=2, intensity=0x00)  # off

Each test simply turns on a LED for 500ms. No evalution is performed, so both tests pass as long as no exceptions are raised due to communication problems.