home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / Python / Lib / Python1.5 / test / test_support.py < prev    next >
Encoding:
Python Source  |  1998-06-09  |  1.1 KB  |  56 lines

  1. # Python test set -- supporting definitions.
  2.  
  3. TestFailed = 'test_support -- test failed'    # Exception
  4.  
  5. verbose = 1                # Flag set to 0 by regrtest.py
  6.  
  7. def unload(name):
  8.     import sys
  9.     try:
  10.         del sys.modules[name]
  11.     except KeyError:
  12.         pass
  13.  
  14. def forget(modname):
  15.     unload(modname)
  16.     import sys, os
  17.     for dirname in sys.path:
  18.         try:
  19.             os.unlink(os.path.join(dirname, modname + '.pyc'))
  20.         except os.error:
  21.             pass
  22.  
  23. FUZZ = 1e-6
  24.  
  25. def fcmp(x, y): # fuzzy comparison function
  26.     if type(x) == type(0.0) or type(y) == type(0.0):
  27.         try:
  28.             x, y = coerce(x, y)
  29.             fuzz = (abs(x) + abs(y)) * FUZZ
  30.             if abs(x-y) <= fuzz:
  31.                 return 0
  32.         except:
  33.             pass
  34.     elif type(x) == type(y) and type(x) in (type(()), type([])):
  35.         for i in range(min(len(x), len(y))):
  36.             outcome = fcmp(x[i], y[i])
  37.             if outcome <> 0:
  38.                 return outcome
  39.         return cmp(len(x), len(y))
  40.     return cmp(x, y)
  41.  
  42. TESTFN = '@test' # Filename used for testing
  43. from os import unlink
  44.  
  45. def findfile(file, here=__file__):
  46.     import os
  47.     if os.path.isabs(file):
  48.         return file
  49.     import sys
  50.     path = sys.path
  51.     path = [os.path.dirname(here)] + path
  52.     for dn in path:
  53.         fn = os.path.join(dn, file)
  54.         if os.path.exists(fn): return fn
  55.     return file
  56.