Skip to content

Commit

Permalink
Add patch for unittest.TestCase.assertRaisesRegex
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigc committed Feb 25, 2017
1 parent 467bcd1 commit 7cbea7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 2 additions & 10 deletions worker/buildbot_worker/monkeypatches/__init__.py
Expand Up @@ -38,18 +38,10 @@ def patch_bug5079():
bug5079.patch()


def patch_testcase_assert_raises_regexp():
# pythons before 2.7 does not have TestCase.assertRaisesRegexp() method
# add our local implementation if needed
import sys
if sys.version_info[:2] < (2, 7):
from buildbot_worker.monkeypatches import testcase_assert
testcase_assert.patch()


def patch_all(for_tests=False):
if for_tests:
patch_testcase_assert_raises_regexp()
from buildbot_worker.monkeypatches import testcase_assert
testcase_assert.patch()

patch_bug4881()
patch_bug5079()
9 changes: 8 additions & 1 deletion worker/buildbot_worker/monkeypatches/testcase_assert.py
Expand Up @@ -48,4 +48,11 @@ def _assertRaisesRegexp(self, expected_exception, expected_regexp,


def patch():
unittest.TestCase.assertRaisesRegexp = _assertRaisesRegexp
hasAssertRaisesRegexp = getattr(unittest.TestCase, "assertRaisesRegexp", None)
hasAssertRaisesRegex = getattr(unittest.TestCase, "assertRaisesRegex", None)
if not hasAssertRaisesRegexp:
# Python 2.6
unittest.TestCase.assertRaisesRegexp = _assertRaisesRegexp
if not hasAssertRaisesRegex:
# Python 2.6 and Python 2.7
unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp

0 comments on commit 7cbea7d

Please sign in to comment.