class TestLED(TestCase):
    PIN = 20
    BRIGHTNESS = 75

    def setUp(self):
        from datacom.week02 import LED
        MockRPi.GPIO.reset_mock()
        self.uut = LED(self.PIN, self.BRIGHTNESS)

    @patch("datacom.week01.LED.__init__")
    def test_init(self, mock_super):
        from datacom.week01 import LED as BaseLED
        from datacom.week02 import LED
        assert self.uut._brightness == self.BRIGHTNESS, "Brightness member variable set incorrectly"
        self.assertEqual(self.uut._pwm, MockRPi.GPIO.PWM(),
                         "PWM protected member variable not set correctly")
        assert MockRPi.GPIO.PWM.call_args_list[0] == call(
            self.PIN, 1000), "PWM object not setup correctly"
        self.uut._pwm.start.assert_called_once_with(
            0), "Missing call to start PWM object"
        MockRPi.reset_mock()
        led = LED(self.PIN)
        assert isinstance(led, BaseLED), "Invalid class inheritance"
        assert led._brightness == 100, "Brightness member variable default value incorrect"
        mock_super.assert_called_once_with(
            self.PIN), "Missing call to superclass init"

    def test_brightness(self):
        from datacom.week02 import LED
        self.assertIsInstance(LED.brightness, property,
                              "LED.brightness is not a property")
        self.assertEqual(self.uut.brightness, self.BRIGHTNESS,
                         "LED.brightness getter failed")
        MockRPi.reset_mock()
        self.uut.brightness = 34
        self.assertEqual(self.uut.brightness, 34,
                         "LED.brightness setter failed")
        self.assertEqual(self.uut._brightness, 34,
                         "LED.brightness setter failed")
        self.uut._pwm.ChangeDutyCycle.assert_called_once_with(34)

    def test_on(self):
        MockRPi.reset_mock()
        self.uut.on()
        self.uut._pwm.start.assert_called_once_with(
            self.BRIGHTNESS), "Missing call to start PWM object"

    def test_off(self):
        self.uut.off()
        self.uut._pwm.stop.assert_called_once_with(
        ), "Missing call to stop PWM object"

    def test_del(self):
        from datacom.week02 import LED
        led = LED(self.PIN)
        del led
        self.uut._pwm.stop.assert_called_once_with(
        ), "Missing call to stop PWM object"
 def test_init(self, mock_super):
     from datacom.week01 import LED as BaseLED
     from datacom.week02 import LED
     assert self.uut._brightness == self.BRIGHTNESS, "Brightness member variable set incorrectly"
     self.assertEqual(self.uut._pwm, MockRPi.GPIO.PWM(),
                      "PWM protected member variable not set correctly")
     assert MockRPi.GPIO.PWM.call_args_list[0] == call(
         self.PIN, 1000), "PWM object not setup correctly"
     self.uut._pwm.start.assert_called_once_with(
         0), "Missing call to start PWM object"
     MockRPi.reset_mock()
     led = LED(self.PIN)
     assert isinstance(led, BaseLED), "Invalid class inheritance"
     assert led._brightness == 100, "Brightness member variable default value incorrect"
     mock_super.assert_called_once_with(
         self.PIN), "Missing call to superclass init"
Beispiel #3
0
 def setUp(self):
     from datacom.week02 import LED
     MockRPi.GPIO.reset_mock()
     self.uut = LED(self.PIN, self.BRIGHTNESS)
Beispiel #4
0
 def test_del(self):
     from datacom.week02 import LED
     led = LED(self.PIN)
     del led
     self.uut._pwm.stop.assert_called_once_with(
     ), "Missing call to stop PWM object"