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_SUPPORT.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  1.7 KB  |  74 lines

  1. """Supporting definitions for the Python regression test."""
  2.  
  3.  
  4. class Error(Exception):
  5.         """Base class for regression test exceptions."""
  6.  
  7. class TestFailed(Error):
  8.         """Test failed."""
  9.  
  10. class TestSkipped(Error):
  11.         """Test skipped.
  12.  
  13.         This can be raised to indicate that a test was deliberatly
  14.         skipped, but not because a feature wasn't available.  For
  15.         example, if some resource can't be used, such as the network
  16.         appears to be unavailable, this should be raised instead of
  17.         TestFailed.
  18.  
  19.         """
  20.  
  21.  
  22. verbose = 1                # Flag set to 0 by regrtest.py
  23. use_large_resources = 1 # Flag set to 0 by regrtest.py
  24.  
  25. def unload(name):
  26.     import sys
  27.     try:
  28.         del sys.modules[name]
  29.     except KeyError:
  30.         pass
  31.  
  32. def forget(modname):
  33.     unload(modname)
  34.     import sys, os
  35.     for dirname in sys.path:
  36.         try:
  37.             os.unlink(os.path.join(dirname, modname + '.pyc'))
  38.         except os.error:
  39.             pass
  40.  
  41. FUZZ = 1e-6
  42.  
  43. def fcmp(x, y): # fuzzy comparison function
  44.     if type(x) == type(0.0) or type(y) == type(0.0):
  45.         try:
  46.             x, y = coerce(x, y)
  47.             fuzz = (abs(x) + abs(y)) * FUZZ
  48.             if abs(x-y) <= fuzz:
  49.                 return 0
  50.         except:
  51.             pass
  52.     elif type(x) == type(y) and type(x) in (type(()), type([])):
  53.         for i in range(min(len(x), len(y))):
  54.             outcome = fcmp(x[i], y[i])
  55.             if outcome <> 0:
  56.                 return outcome
  57.         return cmp(len(x), len(y))
  58.     return cmp(x, y)
  59.  
  60. TESTFN = '@test' # Filename used for testing
  61. from os import unlink
  62.  
  63. def findfile(file, here=__file__):
  64.     import os
  65.     if os.path.isabs(file):
  66.         return file
  67.     import sys
  68.     path = sys.path
  69.     path = [os.path.dirname(here)] + path
  70.     for dn in path:
  71.         fn = os.path.join(dn, file)
  72.         if os.path.exists(fn): return fn
  73.     return file
  74.