source: trunk/essentials/dev-lang/python/Lib/test/test_rgbimg.py

Last change on this file was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 1.8 KB
Line 
1# Testing rgbimg module
2
3import warnings
4warnings.filterwarnings("ignore",
5 "the rgbimg module is deprecated",
6 DeprecationWarning,
7 ".*test_rgbimg$")
8import rgbimg
9
10import os, uu
11
12from test.test_support import verbose, unlink, findfile
13
14class error(Exception):
15 pass
16
17print 'RGBimg test suite:'
18
19def 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
34table = [
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 ]
39for 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
46if verbose:
47 print "testing..."
48
49ttob = rgbimg.ttob(0)
50if ttob != 0:
51 raise error, 'ttob should start out as zero'
52
53testimg('test'+os.extsep+'rgb', 'test'+os.extsep+'rawimg')
54
55ttob = rgbimg.ttob(1)
56if ttob != 0:
57 raise error, 'ttob should be zero'
58
59testimg('test'+os.extsep+'rgb', 'test'+os.extsep+'rawimg'+os.extsep+'rev')
60
61ttob = rgbimg.ttob(0)
62if ttob != 1:
63 raise error, 'ttob should be one'
64
65ttob = rgbimg.ttob(0)
66if ttob != 0:
67 raise error, 'ttob should be zero'
68
69for source, target in table:
70 unlink(findfile(target))
Note: See TracBrowser for help on using the repository browser.