home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / parser / test_parser.py < prev    next >
Text File  |  1996-11-27  |  1KB  |  51 lines

  1. #! /usr/bin/env python
  2. #  (Force the script to use the latest build.)
  3. #
  4. #  test_parser.py
  5.  
  6. import parser, traceback
  7.  
  8. _numFailed = 0
  9.  
  10. def testChunk(t, fileName):
  11.     global _numFailed
  12.     print '----', fileName,
  13.     try:
  14.     ast = parser.suite(t)
  15.     tup = parser.ast2tuple(ast)
  16.     # this discards the first AST; a huge memory savings when running
  17.     # against a large source file like Tkinter.py.
  18.     ast = None
  19.     new = parser.tuple2ast(tup)
  20.     except parser.ParserError, err:
  21.     print
  22.     print 'parser module raised exception on input file', fileName + ':'
  23.     traceback.print_exc()
  24.     _numFailed = _numFailed + 1
  25.     else:
  26.     if tup != parser.ast2tuple(new):
  27.         print
  28.         print 'parser module failed on input file', fileName
  29.         _numFailed = _numFailed + 1
  30.     else:
  31.         print 'o.k.'
  32.  
  33. def testFile(fileName):
  34.     t = open(fileName).read()
  35.     testChunk(t, fileName)
  36.  
  37. def test():
  38.     import sys
  39.     args = sys.argv[1:]
  40.     if not args:
  41.     import glob
  42.     args = glob.glob("*.py")
  43.     map(testFile, args)
  44.     sys.exit(_numFailed != 0)
  45.  
  46. if __name__ == '__main__':
  47.     test()
  48.  
  49. #
  50. #  end of file
  51.