def test_pack_with_iterable(self, mock_class): spi = GPIO(channel=0, frequency=25000, library="wiringPi") it = list(range(0, 10)) data_packet, length = spi.pack(data=it) self.assertEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], list(data_packet)) self.assertEqual(len(it), length)
def test_pack_with_iterable(self, mock_class): spi = GPIO(channel=0, frequency=25000, library="wiringPi") data = list(range(0, 4)) data_packet, length = spi.pack(data) self.assertEqual([0, 1, 2, 3], list(data_packet)) self.assertEqual(4, length)
def test_pack_with_empty_list(self, mock_class): spi = GPIO(channel=0, frequency=25000, library="wiringPi") data = [] data_packet, length = spi.pack(data) self.assertEqual([], list(data_packet)) self.assertEqual(0, length)
def test_pack_with_two_elements(self, mock_class): spi = GPIO(channel=0, frequency=25000, library="wiringPi") data = [1, 2] data_packet, length = spi.pack(data) self.assertEqual([1, 2], list(data_packet)) self.assertEqual(2, length)
def test_pack_with_iterable(mock_class): spi = GPIO(channel=0, frequency=25000, library='wiringPi') it = list(range(0, 10)) data_packet, length = spi.pack(data=it) assert [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] == list(data_packet) assert len(it) == length
def test_pack_with_large_bytes(mock_class): spi = GPIO(channel=0, frequency=25000, library='wiringPi') data = [-10, -1, 0, 255, 256, 266] with pytest.raises(ValueError): spi.pack(data=data)
def test_pack_with_two_elements(mock_class): spi = GPIO(channel=0, frequency=25000, library='wiringPi') data = [1, 2] data_packet, length = spi.pack(data) assert [1, 2] == list(data_packet) assert 2 == length
def test_pack_with_empty_list(mock_class): spi = GPIO(channel=0, frequency=25000, library='wiringPi') data = [] data_packet, length = spi.pack(data) assert [] == list(data_packet) assert length == 0
def test_pack_with_one_element(self, mock_class): spi = GPIO(channel=0, frequency=25000, library='wiringPi') data = [1] data_packet, length = spi.pack(data) self.assertEqual([1], list(data_packet)) self.assertEqual(1, length)
def test_gpio_context_manager(self, mock_loader): g = GPIO(channel=0, frequency=10000, library='None', interrupt=0) l = [128] result, length = g.pack(l) self.assertEqual(list(result), l)