"""Unit testing lessons 3 and 4."""importunittestfromunittest.mockimportMagicMockfromlessons.lesson_3_and_4.mainimport(get_val,NUMBERS,PINS,set_pin_val,set_all_pins)
[docs]classLesson3and4TestCase(unittest.TestCase):""" Lessons 3 and 4 test case. """
[docs]deftest_set_all_pins_off(self):""" Testing set_all_pins function. Turn off all pins. :return: """val=(0,0,0,0)set_all_pins(val)forpinPINS:p.value=MagicMock()p.value.return_value=0self.assertEqual(p.value(),0)
[docs]deftest_set_all_pins_on(self):""" Testing set_all_pins function. Turn on all pins :return: """val=(1,1,1,1)set_all_pins(val)forpinPINS:p.value=MagicMock()p.value.return_value=1self.assertEqual(p.value(),1)
[docs]deftest_set_pin_value_off(self):""" Pin value should return 0 after it was updated by set_pin_value function :return: """led=PINS[0]set_pin_val(led,0)led.value=MagicMock()led.value.return_value=0self.assertEqual(led.value(),0)
[docs]deftest_set_pin_value_on(self):""" Pin value should return 1 after it was updated by set_pin_value function :return: """led=PINS[0]set_pin_val(led,1)led.value=MagicMock()led.value.return_value=1self.assertEqual(led.value(),1)
[docs]deftest_numbers_data_type(self):""" Testing numbers dictionary -> datatype should be dict :return: """self.assertIsInstance(NUMBERS,dict)