home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / diveintopython / examples / regression.py < prev    next >
Encoding:
Python Source  |  2004-05-05  |  1.3 KB  |  35 lines

  1. """Regression testing framework
  2.  
  3. This module will search for scripts in the same directory named
  4. XYZtest.py.  Each such script should be a test suite that tests a
  5. module through PyUnit.  (As of Python 2.1, PyUnit is included in
  6. the standard library as 'unittest'.)  This script will aggregate all
  7. found test suites into one big test suite and run them all at once.
  8.  
  9. This program is part of "Dive Into Python", a free Python book for
  10. experienced programmers.  Visit http://diveintopython.org/ for the
  11. latest version.
  12. """
  13.  
  14. __author__ = "Mark Pilgrim (mark@diveintopython.org)"
  15. __version__ = "$Revision: 1.4 $"
  16. __date__ = "$Date: 2004/05/05 21:57:19 $"
  17. __copyright__ = "Copyright (c) 2001 Mark Pilgrim"
  18. __license__ = "Python"
  19.  
  20. import sys, os, re, unittest
  21.  
  22. def regressionTest():
  23.     path = os.path.abspath(os.path.dirname(sys.argv[0]))
  24.     files = os.listdir(path)
  25.     test = re.compile("test\.py$", re.IGNORECASE)
  26.     files = filter(test.search, files)
  27.     filenameToModuleName = lambda f: os.path.splitext(f)[0]
  28.     moduleNames = map(filenameToModuleName, files)
  29.     modules = map(__import__, moduleNames)
  30.     load = unittest.defaultTestLoader.loadTestsFromModule
  31.     return unittest.TestSuite(map(load, modules))
  32.  
  33. if __name__ == "__main__":
  34.     unittest.main(defaultTest="regressionTest")
  35.