run.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. """
  3. Pygments unit tests
  4. ~~~~~~~~~~~~~~~~~~
  5. Usage::
  6. python run.py [testfile ...]
  7. :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
  8. :license: BSD, see LICENSE for details.
  9. """
  10. import sys, os
  11. if sys.version_info >= (3,):
  12. # copy test suite over to "build/lib" and convert it
  13. print ('Copying and converting sources to build/lib/test...')
  14. from distutils.util import copydir_run_2to3
  15. testroot = os.path.dirname(__file__)
  16. newroot = os.path.join(testroot, '..', 'build/lib/test')
  17. copydir_run_2to3(testroot, newroot)
  18. # make nose believe that we run from the converted dir
  19. os.chdir(newroot)
  20. else:
  21. # only find tests in this directory
  22. os.chdir(os.path.dirname(__file__))
  23. try:
  24. import nose
  25. except ImportError:
  26. print ('nose is required to run the Pygments test suite')
  27. sys.exit(1)
  28. try:
  29. # make sure the current source is first on sys.path
  30. sys.path.insert(0, '..')
  31. import pygments
  32. except ImportError:
  33. print ('Cannot find Pygments to test: %s' % sys.exc_info()[1])
  34. sys.exit(1)
  35. else:
  36. print ('Pygments %s test suite running (Python %s)...' %
  37. (pygments.__version__, sys.version.split()[0]))
  38. nose.main()