You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

66 lines
2.5 KiB

  1. """backports of needed unittest2 features"""
  2. #=============================================================================
  3. # imports
  4. #=============================================================================
  5. from __future__ import with_statement
  6. # core
  7. import logging; log = logging.getLogger(__name__)
  8. import re
  9. import sys
  10. ##from warnings import warn
  11. # site
  12. # pkg
  13. from passlib.utils.compat import PY26
  14. # local
  15. __all__ = [
  16. "TestCase",
  17. "skip", "skipIf", "skipUnless"
  18. ]
  19. #=============================================================================
  20. # import latest unittest module available
  21. #=============================================================================
  22. try:
  23. import unittest2 as unittest
  24. except ImportError:
  25. if PY26:
  26. raise ImportError("Passlib's tests require 'unittest2' under Python 2.6 (as of Passlib 1.7)")
  27. # python 2.7 and python 3.2 both have unittest2 features (at least, the ones we use)
  28. import unittest
  29. #=============================================================================
  30. # unittest aliases
  31. #=============================================================================
  32. skip = unittest.skip
  33. skipIf = unittest.skipIf
  34. skipUnless = unittest.skipUnless
  35. SkipTest = unittest.SkipTest
  36. #=============================================================================
  37. # custom test harness
  38. #=============================================================================
  39. class TestCase(unittest.TestCase):
  40. """backports a number of unittest2 features in TestCase"""
  41. #===================================================================
  42. # backport some unittest2 names
  43. #===================================================================
  44. #---------------------------------------------------------------
  45. # backport assertRegex() alias from 3.2 to 2.7
  46. # was present in 2.7 under an alternate name
  47. #---------------------------------------------------------------
  48. if not hasattr(unittest.TestCase, "assertRegex"):
  49. assertRegex = unittest.TestCase.assertRegexpMatches
  50. if not hasattr(unittest.TestCase, "assertRaisesRegex"):
  51. assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
  52. #===================================================================
  53. # eoc
  54. #===================================================================
  55. #=============================================================================
  56. # eof
  57. #=============================================================================