Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CircuitPython 7 no longer allows StopIteration fallback #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions adafruit_imageload/gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,20 @@ def lzw_decode(data, code_size):
"""Decode LZW-compressed data."""
dictionary = LZWDict(code_size)
bit = 0
byte = next(data) # pylint: disable=stop-iteration-return
try:
while True:
code = 0
for i in range(dictionary.code_len):
code |= ((byte >> bit) & 0x01) << i
bit += 1
if bit >= 8:
bit = 0
byte = next(data) # pylint: disable=stop-iteration-return
yield dictionary.decode(code)
except EndOfData:
while True:
next(data) # pylint: disable=stop-iteration-return
byte = next(data) # pylint: disable=stop-iteration-return
try:
while True:
code = 0
for i in range(dictionary.code_len):
code |= ((byte >> bit) & 0x01) << i
bit += 1
if bit >= 8:
bit = 0
byte = next(data) # pylint: disable=stop-iteration-return
yield dictionary.decode(code)
except EndOfData:
while True:
next(data) # pylint: disable=stop-iteration-return
except StopIteration:
pass
4 changes: 2 additions & 2 deletions tests/displayio_shared_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ def __str__(self):
print(str(palette))
"""
out = "\nPalette:\n"
for y in range(len(self.colors)):
out += f" [{y}] {self.colors[y]}\n"
for i, color in enumerate(self.colors):
out += f" [{i}] {color}\n"
return out
24 changes: 8 additions & 16 deletions tests/test_bitmap_c_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_init(self):

def test_abs(self):
b = Bitmap_C_Interface(5, 2, 1)
self.assertEqual(9, b._abs_pos(4, 1))
self.assertEqual(9, b._abs_pos(4, 1)) # pylint: disable=protected-access

def test_set_tuple(self):
b = Bitmap_C_Interface(2, 4, 1)
Expand All @@ -65,11 +65,8 @@ def test_non_zero(self):

def test_throws_x_out_of_range(self):
b = Bitmap_C_Interface(2, 4, 1)
try:
with self.assertRaises(ValueError):
b[2, 1] = 100
self.fail("should have thrown")
except ValueError:
pass

def test_max(self):
b = Bitmap_C_Interface(2, 4, 1)
Expand All @@ -78,18 +75,13 @@ def test_max(self):

def test_uninitialized(self):
b = Bitmap_C_Interface(2, 4, 1)
try:
b[1, 1]
self.fail("should have thrown")
except RuntimeError:
pass
with self.assertRaises(RuntimeError):
b[1, 1] # pylint: disable=pointless-statement

def test_validate_throws(self):
b = Bitmap_C_Interface(2, 4, 1)
try:
with self.assertRaises(ValueError):
b.validate()
except ValueError:
pass

def test_repr(self):
b = Bitmap_C_Interface(3, 2, 1)
Expand All @@ -103,6 +95,6 @@ def test_repr(self):

def test_decode(self):
b = Bitmap_C_Interface(4, 4, 1)
self.assertEqual((0, 0), b._decode(0))
encoded = b._abs_pos(3, 3)
self.assertEqual((3, 3), b._decode(encoded))
self.assertEqual((0, 0), b._decode(0)) # pylint: disable=protected-access
encoded = b._abs_pos(3, 3) # pylint: disable=protected-access
self.assertEqual((3, 3), b._decode(encoded)) # pylint: disable=protected-access
4 changes: 3 additions & 1 deletion tests/test_bmp_indexed_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def test_order_bgra_to_rgba(self):
)

bitmap, palette = load(
filename=test_file, bitmap=Bitmap_C_Interface, palette=Palette_C_Interface
file_or_filename=test_file,
bitmap=Bitmap_C_Interface,
palette=Palette_C_Interface,
)
self.assertTrue(isinstance(bitmap, Bitmap_C_Interface), bitmap)
self.assertEqual(16, bitmap.colors)
Expand Down