From 7cbea7da5c230a2ab34b501ac00516bde3f39fba Mon Sep 17 00:00:00 2001 From: Craig Rodrigues Date: Sat, 25 Feb 2017 14:44:04 -0800 Subject: [PATCH] Add patch for unittest.TestCase.assertRaisesRegex --- worker/buildbot_worker/monkeypatches/__init__.py | 12 ++---------- .../buildbot_worker/monkeypatches/testcase_assert.py | 9 ++++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/worker/buildbot_worker/monkeypatches/__init__.py b/worker/buildbot_worker/monkeypatches/__init__.py index 0e4fb0a9e1f..daf59ff9f86 100644 --- a/worker/buildbot_worker/monkeypatches/__init__.py +++ b/worker/buildbot_worker/monkeypatches/__init__.py @@ -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() diff --git a/worker/buildbot_worker/monkeypatches/testcase_assert.py b/worker/buildbot_worker/monkeypatches/testcase_assert.py index 09f63023c64..6db3b819290 100644 --- a/worker/buildbot_worker/monkeypatches/testcase_assert.py +++ b/worker/buildbot_worker/monkeypatches/testcase_assert.py @@ -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