Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 1 | # Testing rgbimg module |
| 2 | |
| 3 | import rgbimg, os |
| 4 | |
| 5 | error = 'test_rgbimg.error' |
| 6 | |
| 7 | print 'RGBimg test suite:' |
| 8 | |
Guido van Rossum | b19d862 | 1994-03-09 12:54:32 +0000 | [diff] [blame] | 9 | def findfile(file): |
| 10 | if os.path.isabs(file): return file |
| 11 | import sys |
| 12 | for dn in sys.path: |
| 13 | fn = os.path.join(dn, file) |
| 14 | if os.path.exists(fn): return fn |
| 15 | return file |
| 16 | |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 17 | def testimg(rgb_file, raw_file): |
Guido van Rossum | b19d862 | 1994-03-09 12:54:32 +0000 | [diff] [blame] | 18 | rgb_file = findfile(rgb_file) |
| 19 | raw_file = findfile(raw_file) |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 20 | width, height = rgbimg.sizeofimage(rgb_file) |
| 21 | rgb = rgbimg.longimagedata(rgb_file) |
| 22 | if len(rgb) != width * height * 4: |
| 23 | raise error, 'bad image length' |
| 24 | raw = open(raw_file, 'r').read() |
| 25 | if rgb != raw: |
| 26 | raise error, 'images don\'t match for '+rgb_file+' and '+raw_file |
| 27 | for depth in [1, 3, 4]: |
| 28 | rgbimg.longstoimage(rgb, width, height, depth, '@.rgb') |
| 29 | os.unlink('@.rgb') |
| 30 | |
| 31 | ttob = rgbimg.ttob(0) |
| 32 | if ttob != 0: |
| 33 | raise error, 'ttob should start out as zero' |
| 34 | |
| 35 | testimg('test.rgb', 'test.rawimg') |
| 36 | |
| 37 | ttob = rgbimg.ttob(1) |
| 38 | if ttob != 0: |
| 39 | raise error, 'ttob should be zero' |
| 40 | |
| 41 | testimg('test.rgb', 'test.rawimg.rev') |
| 42 | |
| 43 | ttob = rgbimg.ttob(0) |
| 44 | if ttob != 1: |
| 45 | raise error, 'ttob should be one' |
| 46 | |
| 47 | ttob = rgbimg.ttob(0) |
| 48 | if ttob != 0: |
| 49 | raise error, 'ttob should be zero' |