PyXR

c:\python24\lib \ test \ test_rgbimg.py



0001 # Testing rgbimg module
0002 
0003 import rgbimg, os, uu
0004 
0005 from test.test_support import verbose, unlink, findfile
0006 
0007 class error(Exception):
0008     pass
0009 
0010 print 'RGBimg test suite:'
0011 
0012 def testimg(rgb_file, raw_file):
0013     rgb_file = findfile(rgb_file)
0014     raw_file = findfile(raw_file)
0015     width, height = rgbimg.sizeofimage(rgb_file)
0016     rgb = rgbimg.longimagedata(rgb_file)
0017     if len(rgb) != width * height * 4:
0018         raise error, 'bad image length'
0019     raw = open(raw_file, 'rb').read()
0020     if rgb != raw:
0021         raise error, \
0022               'images don\'t match for '+rgb_file+' and '+raw_file
0023     for depth in [1, 3, 4]:
0024         rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
0025     os.unlink('@.rgb')
0026 
0027 table = [
0028     ('testrgb'+os.extsep+'uue', 'test'+os.extsep+'rgb'),
0029     ('testimg'+os.extsep+'uue', 'test'+os.extsep+'rawimg'),
0030     ('testimgr'+os.extsep+'uue', 'test'+os.extsep+'rawimg'+os.extsep+'rev'),
0031     ]
0032 for source, target in table:
0033     source = findfile(source)
0034     target = findfile(target)
0035     if verbose:
0036         print "uudecoding", source, "->", target, "..."
0037     uu.decode(source, target)
0038 
0039 if verbose:
0040     print "testing..."
0041 
0042 ttob = rgbimg.ttob(0)
0043 if ttob != 0:
0044     raise error, 'ttob should start out as zero'
0045 
0046 testimg('test'+os.extsep+'rgb', 'test'+os.extsep+'rawimg')
0047 
0048 ttob = rgbimg.ttob(1)
0049 if ttob != 0:
0050     raise error, 'ttob should be zero'
0051 
0052 testimg('test'+os.extsep+'rgb', 'test'+os.extsep+'rawimg'+os.extsep+'rev')
0053 
0054 ttob = rgbimg.ttob(0)
0055 if ttob != 1:
0056     raise error, 'ttob should be one'
0057 
0058 ttob = rgbimg.ttob(0)
0059 if ttob != 0:
0060     raise error, 'ttob should be zero'
0061 
0062 for source, target in table:
0063     unlink(findfile(target))
0064 

Generated by PyXR 0.9.4
SourceForge.net Logo