-
Notifications
You must be signed in to change notification settings - Fork 1
/
ppmlib_test.py
52 lines (42 loc) · 1.24 KB
/
ppmlib_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
import unittest
import StringIO
import ppmlib
import imglib
class TestPpmWriter(unittest.TestCase):
def setUp(self):
self.klass = ppmlib.PpmWriter
def test_init(self):
bitmap = imglib.RgbBitmap(10, 5)
obj = self.klass(bitmap)
self.assertEqual(bitmap, obj.bitmap)
def test_write__minimum(self):
sio = StringIO.StringIO()
bitmap = imglib.RgbBitmap(1, 1)
bitmap.set_pixel(0, 0, (1, 2, 3))
obj = self.klass(bitmap)
obj.write(sio)
expected = "P3\n"
expected += "1 1\n"
expected += "255\n"
expected += "1 2 3\n"
self.assertEqual(expected, sio.getvalue())
def test_write__3x2(self):
sio = StringIO.StringIO()
bitmap = imglib.RgbBitmap(3, 2)
bitmap.set_pixel(0, 0, (1, 2, 3))
bitmap.set_pixel(1, 0, (4, 5, 6))
bitmap.set_pixel(2, 0, (7, 8, 9))
bitmap.set_pixel(0, 1, (10, 11, 12))
bitmap.set_pixel(1, 1, (13, 14, 15))
bitmap.set_pixel(2, 1, (16, 17, 18))
obj = self.klass(bitmap)
obj.write(sio)
expected = "P3\n"
expected += "3 2\n"
expected += "255\n"
expected += "1 2 3 4 5 6 7 8 9\n"
expected += "10 11 12 13 14 15 16 17 18\n"
self.assertEqual(expected, sio.getvalue())
if __name__ == "__main__":
unittest.main()