home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_RGBIMG.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  1.6 KB  |  64 lines

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