home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Numerical / Test / test_all.py next >
Encoding:
Python Source  |  2000-06-23  |  1.3 KB  |  70 lines

  1. #!/usr/bin/env python
  2. print 'Starting Testing Suite'
  3.  
  4. import sys
  5.  
  6. if len(sys.argv) == 2:
  7.     test_file = sys.argv[1]
  8. else:
  9.     test_file = "test_items"
  10.  
  11. lineno = 0
  12.     
  13. def test_lines(lines, expected_outs=None):
  14.         global lineno
  15.     last_out = ""
  16.     start_index = 0
  17.     for i in range(len(lines)):
  18.         if lines[i][:3] == "***":
  19.             start_index = i+1
  20.  
  21.     for i in range(len(lines)):
  22.             lineno = lineno + 1
  23.         line = lines[i]
  24.         if line[:3] == "***": continue
  25.  
  26.         if line[0] == ">":
  27.             #print line, line[1:-1]
  28.             try: test = repr(eval(line[1:]))
  29.             except: test = line[1:-1]
  30.             if test != last_out:
  31.                 print type(last_out)
  32.                 print len(last_out), len(test), last_out, test
  33.                     print '*** Test line', lineno,'failed'
  34.                 raise ValueError, "%s doesn't match expected %s" % (last_out, line[1:-1])
  35.             continue
  36.  
  37.         try:
  38.             try:
  39.                 out = eval(line)
  40.             except(ValueError, IndexError, TypeError, ZeroDivisionError):
  41.                 out = "%s: %s" % (sys.exc_type, sys.exc_value)
  42.                 #print out
  43.             
  44.             if out == None:
  45.                 exec(line)
  46.             else:
  47.                 if type(out) != type(""):
  48.                     out = repr(out)
  49.                 else:
  50.                     try: out = repr(eval(out))
  51.                     except: pass
  52.                 #print out
  53.                 last_out = out
  54.                 if i > start_index:
  55.                     print last_out
  56.  
  57.         except(SyntaxError):
  58.             exec(line)
  59.  
  60. fp = open(test_file)
  61. test_lines(fp.readlines())
  62. fp.close()
  63.  
  64. print
  65. print
  66. print "*"*10+" Test Completed Successfully! "+"*"*10
  67.  
  68. #sys.exit()
  69.  
  70.