@@ -12,43 +12,38 @@ def __init__(self, width, height, colors):
12
12
13
13
logging .getLogger ().setLevel (logging .INFO )
14
14
15
- class TestPbmP1 (TestCase ):
15
+ class TestPnmLoad (TestCase ):
16
16
17
17
def test_load_fails_with_no_header_data (self ):
18
18
f = BytesIO (b"some initial binary data: \x00 \x01 " )
19
19
try :
20
- pnm .load (f , b'P1' )
20
+ pnm .load (f , b'P1' , bitmap = Bitmap )
21
21
self .fail ('should have failed' )
22
22
except Exception as e :
23
23
if "Unsupported image format" not in str (e ):
24
24
raise
25
25
26
- def _test_load_works_p1_ascii (self ):
26
+ def test_load_works_p1_ascii (self ):
27
27
test_file = os .path .join (os .path .dirname (__file__ ), '..' , '..' , 'examples' , 'images' , 'netpbm_p1_mono.pbm' )
28
- with open (test_file ) as f :
29
- f .seek (2 )
30
- bitmap , palette = pnm .load (f , b'P1' )
31
- self .assertTrue (isinstance (bitmap , Bitmap ))
32
- self .fail (bitmap )
28
+ with open (test_file , 'rb' ) as f :
29
+ bitmap , palette = pnm .load (f , b'P1' , bitmap = Bitmap )
30
+ self .assertTrue (isinstance (bitmap , Bitmap ), bitmap )
33
31
self .assertEqual (1 , bitmap .colors )
34
- self .assertEqual (20 , bitmap .width )
32
+ self .assertEqual (13 , bitmap .width )
33
+ self .assertEqual (21 , bitmap .height )
35
34
36
35
def test_load_works_p4_binary (self ):
37
36
test_file = os .path .join (os .path .dirname (__file__ ), '..' , '..' , 'examples' , 'images' , 'netpbm_p4_mono.pbm' )
38
-
39
37
with open (test_file , 'rb' ) as f :
40
- f .seek (2 )
41
38
bitmap , palette = pnm .load (f , b'P4' , bitmap = Bitmap )
42
39
self .assertTrue (isinstance (bitmap , Bitmap ))
43
40
self .assertEqual (1 , bitmap .colors )
44
41
self .assertEqual (8 , bitmap .width )
45
42
self .assertEqual (8 , bitmap .height )
46
43
47
- def test_load_works_p4_binary_big (self ):
44
+ def test_load_works_p4_binary_high_res (self ):
48
45
test_file = os .path .join (os .path .dirname (__file__ ), '..' , '..' , 'examples' , 'images' , 'MARBLES.PBM' )
49
-
50
46
with open (test_file , 'rb' ) as f :
51
- f .seek (2 )
52
47
bitmap , palette = pnm .load (f , b'P4' , bitmap = Bitmap )
53
48
self .assertTrue (isinstance (bitmap , Bitmap ))
54
49
self .assertEqual (1 , bitmap .colors )
0 commit comments