Skip to content

Commit 8e385b4

Browse files
author
Matt Land
committed
test it
1 parent d984ca0 commit 8e385b4

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

adafruit_imageload/tests/test_pnm_load.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __str__(self):
6161
out += "\n"
6262
return out
6363

64+
6465
class Palette_C_Interface(object):
6566
def __init__(self, num_colors):
6667
self.num_colors = num_colors
@@ -143,8 +144,9 @@ def test_decode(self):
143144
encoded = b._abs_pos(3, 3)
144145
self.assertEqual((3, 3), b._decode(encoded))
145146

146-
class testPgmLoad(TestCase):
147-
def test_load_works_p1_ascii(self):
147+
148+
class TestPgmLoad(TestCase):
149+
def test_load_works_p2_ascii(self):
148150
test_file = os.path.join(
149151
os.path.dirname(__file__),
150152
"..",
@@ -160,8 +162,25 @@ def test_load_works_p1_ascii(self):
160162
self.assertEqual(8, bitmap.width)
161163
self.assertEqual(8, bitmap.height)
162164
bitmap.validate()
163-
self.fail(str(bitmap))
165+
self.assertEqual(6, palette.num_colors)
164166

167+
def test_load_works_p5_binary(self):
168+
test_file = os.path.join(
169+
os.path.dirname(__file__),
170+
"..",
171+
"..",
172+
"examples",
173+
"images",
174+
"netpbm_p5_binary.pgm",
175+
)
176+
with open(test_file, "rb") as f:
177+
bitmap, palette = pnm.load(f, b"P5", bitmap=Bitmap_C_Interface, palette=Palette_C_Interface)
178+
self.assertTrue(isinstance(bitmap, Bitmap_C_Interface), bitmap)
179+
self.assertEqual(255, bitmap.colors)
180+
self.assertEqual(8, bitmap.width)
181+
self.assertEqual(8, bitmap.height)
182+
bitmap.validate()
183+
self.assertEqual(6, palette.colors)
165184

166185

167186
class TestPnmLoad(TestCase):

0 commit comments

Comments
 (0)