home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Lib / test / test_rgbimg.py < prev    next >
Text File  |  1997-09-07  |  2KB  |  76 lines

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