|
1 # Testing rgbimg module |
|
2 |
|
3 import warnings |
|
4 warnings.filterwarnings("ignore", |
|
5 "the rgbimg module is deprecated", |
|
6 DeprecationWarning, |
|
7 ".*test_rgbimg$") |
|
8 import rgbimg |
|
9 |
|
10 import os, uu |
|
11 |
|
12 from test.test_support import verbose, unlink, findfile |
|
13 |
|
14 class error(Exception): |
|
15 pass |
|
16 |
|
17 print 'RGBimg test suite:' |
|
18 |
|
19 def testimg(rgb_file, raw_file): |
|
20 rgb_file = findfile(rgb_file) |
|
21 raw_file = findfile(raw_file) |
|
22 width, height = rgbimg.sizeofimage(rgb_file) |
|
23 rgb = rgbimg.longimagedata(rgb_file) |
|
24 if len(rgb) != width * height * 4: |
|
25 raise error, 'bad image length' |
|
26 raw = open(raw_file, 'rb').read() |
|
27 if rgb != raw: |
|
28 raise error, \ |
|
29 'images don\'t match for '+rgb_file+' and '+raw_file |
|
30 for depth in [1, 3, 4]: |
|
31 rgbimg.longstoimage(rgb, width, height, depth, '@.rgb') |
|
32 os.unlink('@.rgb') |
|
33 |
|
34 table = [ |
|
35 ('testrgb'+os.extsep+'uue', 'test'+os.extsep+'rgb'), |
|
36 ('testimg'+os.extsep+'uue', 'test'+os.extsep+'rawimg'), |
|
37 ('testimgr'+os.extsep+'uue', 'test'+os.extsep+'rawimg'+os.extsep+'rev'), |
|
38 ] |
|
39 for source, target in table: |
|
40 source = findfile(source) |
|
41 target = findfile(target) |
|
42 if verbose: |
|
43 print "uudecoding", source, "->", target, "..." |
|
44 uu.decode(source, target) |
|
45 |
|
46 if verbose: |
|
47 print "testing..." |
|
48 |
|
49 ttob = rgbimg.ttob(0) |
|
50 if ttob != 0: |
|
51 raise error, 'ttob should start out as zero' |
|
52 |
|
53 testimg('test'+os.extsep+'rgb', 'test'+os.extsep+'rawimg') |
|
54 |
|
55 ttob = rgbimg.ttob(1) |
|
56 if ttob != 0: |
|
57 raise error, 'ttob should be zero' |
|
58 |
|
59 testimg('test'+os.extsep+'rgb', 'test'+os.extsep+'rawimg'+os.extsep+'rev') |
|
60 |
|
61 ttob = rgbimg.ttob(0) |
|
62 if ttob != 1: |
|
63 raise error, 'ttob should be one' |
|
64 |
|
65 ttob = rgbimg.ttob(0) |
|
66 if ttob != 0: |
|
67 raise error, 'ttob should be zero' |
|
68 |
|
69 for source, target in table: |
|
70 unlink(findfile(target)) |