Skip to content

Commit 2946047

Browse files
committed
Backwards compat unittest regex assertions
Signed-off-by: javrin <[email protected]>
1 parent 47b81d6 commit 2946047

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/rez/tests/test_utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ def test_already_posix_style_paths(self):
157157
)
158158
self.assertEqual(
159159
cygpath.to_posix_path("/d/projects/python"), "/d/projects/python")
160-
self.assertRaisesRegexp(
160+
self.assertRaisesRegex(
161161
ValueError,
162162
"Cannot convert path to posix path: '.*' "
163163
"Please ensure that the path is absolute",
164164
cygpath.to_posix_path,
165165
"/home/john/documents"
166166
)
167-
self.assertRaisesRegexp(
167+
self.assertRaisesRegex(
168168
ValueError,
169169
"Cannot convert path to posix path: '.*' "
170170
"Please ensure that the path is absolute",
@@ -174,15 +174,15 @@ def test_already_posix_style_paths(self):
174174

175175
@platform_dependent(["windows"])
176176
def test_relative_paths(self):
177-
self.assertRaisesRegexp(
177+
self.assertRaisesRegex(
178178
ValueError,
179179
"Cannot convert path to posix path: '.*' "
180180
"Please ensure that the path is absolute",
181181
cygpath.to_posix_path,
182182
"jane/documents"
183183
)
184184

185-
self.assertRaisesRegexp(
185+
self.assertRaisesRegex(
186186
ValueError,
187187
"Cannot convert path to posix path: '.*' "
188188
"Please ensure that the path is absolute",
@@ -222,14 +222,14 @@ def test_windows_malformed_paths(self):
222222
self.assertEqual(
223223
cygpath.to_posix_path("D:\\projects/python"), "/d/projects/python"
224224
)
225-
self.assertRaisesRegexp(
225+
self.assertRaisesRegex(
226226
ValueError,
227227
"Cannot convert path to posix path: '.*' "
228228
"This is most likely due to a malformed path",
229229
cygpath.to_posix_path,
230230
"D:\\..\\Projects"
231231
)
232-
self.assertRaisesRegexp(
232+
self.assertRaisesRegex(
233233
ValueError,
234234
"Cannot convert path to posix path: '.*' "
235235
"This is most likely due to a malformed path",
@@ -245,7 +245,7 @@ def test_dotted_paths(self):
245245
self.assertEqual(cygpath.to_posix_path(
246246
"/c/users/./jane"), "/c/users/jane"
247247
)
248-
self.assertRaisesRegexp(
248+
self.assertRaisesRegex(
249249
ValueError,
250250
"Cannot convert path to posix path: '.*' "
251251
"Please ensure that the path is absolute",
@@ -349,23 +349,23 @@ def test_paths_with_mixed_slashes(self):
349349

350350
@platform_dependent(["windows"])
351351
def test_paths_with_no_drive_letter(self):
352-
self.assertRaisesRegexp(
352+
self.assertRaisesRegex(
353353
ValueError,
354354
"Cannot convert path to mixed path: '.*' "
355355
"Please ensure that the path is absolute",
356356
cygpath.to_mixed_path,
357357
'\\foo\\bar'
358358
)
359359

360-
self.assertRaisesRegexp(
360+
self.assertRaisesRegex(
361361
ValueError,
362362
"Cannot convert path to mixed path: '.*' "
363363
"Please ensure that the path is absolute",
364364
cygpath.to_mixed_path,
365365
'\\\\my_folder\\my_file.txt'
366366
)
367367

368-
self.assertRaisesRegexp(
368+
self.assertRaisesRegex(
369369
ValueError,
370370
"Cannot convert path to mixed path: '.*' "
371371
"Please ensure that the path is absolute",
@@ -387,7 +387,7 @@ def test_dotted_paths(self):
387387
self.assertEqual(cygpath.to_mixed_path(
388388
"C:/users/./jane"), "C:/users/jane"
389389
)
390-
self.assertRaisesRegexp(
390+
self.assertRaisesRegex(
391391
ValueError,
392392
"Cannot convert path to posix path: '.*' "
393393
"Please ensure that the path is absolute",

src/rez/tests/util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
except ImportError:
2929
use_parameterized = False
3030

31+
# For py2 backwards compatibility
32+
if not hasattr(unittest.TestCase, 'assertRaisesRegex'):
33+
setattr(
34+
unittest.TestCase,
35+
'assertRaisesRegex',
36+
unittest.TestCase.assertRaisesRegexp
37+
)
38+
3139

3240
class TestBase(unittest.TestCase):
3341
"""Unit test base class."""

0 commit comments

Comments
 (0)