PageRenderTime 68ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/examples/test_examples.py

https://github.com/kindkaktus/cxxtest
Python | 68 lines | 52 code | 4 blank | 12 comment | 0 complexity | 96a521504f155747eff7fb5a7597303c MD5 | raw file
Possible License(s): LGPL-3.0
  1. #-------------------------------------------------------------------------
  2. # CxxTest: A lightweight C++ unit testing library.
  3. # Copyright (c) 2008 Sandia Corporation.
  4. # This software is distributed under the LGPL License v3
  5. # For more information, see the COPYING file in the top CxxTest directory.
  6. # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  7. # the U.S. Government retains certain rights in this software.
  8. #-------------------------------------------------------------------------
  9. # Imports
  10. import pyutilib.th as unittest
  11. import glob
  12. import os
  13. from os.path import dirname, abspath, basename
  14. import sys
  15. import re
  16. currdir = dirname(abspath(__file__))+os.sep
  17. datadir = currdir
  18. compilerre = re.compile("^(?P<path>[^:]+)(?P<rest>:.*)$")
  19. dirre = re.compile("^([^%s]*/)*" % re.escape(os.sep))
  20. xmlre = re.compile("\"(?P<path>[^\"]*/[^\"]*)\"")
  21. datere = re.compile("date=\"[^\"]*\"")
  22. failure = re.compile("^(?P<prefix>.+)file=\"(?P<path>[^\"]+)\"(?P<suffix>.*)$")
  23. #print "FOO", dirre
  24. def filter(line):
  25. # for xml, remove prefixes from everything that looks like a
  26. # file path inside ""
  27. line = xmlre.sub(
  28. lambda match: '"'+re.sub("^[^/]+/", "", match.group(1))+'"',
  29. line
  30. )
  31. # Remove date info
  32. line = datere.sub( lambda match: 'date=""', line)
  33. if 'Running' in line:
  34. return False
  35. if "IGNORE" in line:
  36. return True
  37. pathmatch = compilerre.match(line) # see if we can remove the basedir
  38. failmatch = failure.match(line) # see if we can remove the basedir
  39. #print "HERE", pathmatch, failmatch
  40. if failmatch:
  41. parts = failmatch.groupdict()
  42. #print "X", parts
  43. line = "%s file=\"%s\" %s" % (parts['prefix'], dirre.sub("", parts['path']), parts['suffix'])
  44. elif pathmatch:
  45. parts = pathmatch.groupdict()
  46. #print "Y", parts
  47. line = dirre.sub("", parts['path']) + parts['rest']
  48. return line
  49. # Declare an empty TestCase class
  50. class Test(unittest.TestCase): pass
  51. if not sys.platform.startswith('win'):
  52. # Find all *.sh files, and use them to define baseline tests
  53. for file in glob.glob(datadir+'*.sh'):
  54. bname = basename(file)
  55. name=bname.split('.')[0]
  56. if os.path.exists(datadir+name+'.txt'):
  57. Test.add_baseline_test(cwd=datadir, cmd=file, baseline=datadir+name+'.txt', name=name, filter=filter)
  58. # Execute the tests
  59. if __name__ == '__main__':
  60. unittest.main()