Skip to content

Commit

Permalink
Backwards compat unittest regex assertions
Browse files Browse the repository at this point in the history
Signed-off-by: javrin <jawabiscuit@users.noreply.github.com>
  • Loading branch information
Jawabiscuit committed Sep 15, 2023
1 parent 519c462 commit 89fa4ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/rez/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ def test_already_posix_style_paths(self):
)
self.assertEqual(
cygpath.to_posix_path("/d/projects/python"), "/d/projects/python")
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to posix path: '.*' "
"Please ensure that the path is absolute",
cygpath.to_posix_path,
"/home/john/documents"
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to posix path: '.*' "
"Please ensure that the path is absolute",
Expand All @@ -174,15 +174,15 @@ def test_already_posix_style_paths(self):

@platform_dependent(["windows"])
def test_relative_paths(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to posix path: '.*' "
"Please ensure that the path is absolute",
cygpath.to_posix_path,
"jane/documents"
)

self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to posix path: '.*' "
"Please ensure that the path is absolute",
Expand Down Expand Up @@ -222,14 +222,14 @@ def test_windows_malformed_paths(self):
self.assertEqual(
cygpath.to_posix_path("D:\\projects/python"), "/d/projects/python"
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to posix path: '.*' "
"This is most likely due to a malformed path",
cygpath.to_posix_path,
"D:\\..\\Projects"
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to posix path: '.*' "
"This is most likely due to a malformed path",
Expand All @@ -245,7 +245,7 @@ def test_dotted_paths(self):
self.assertEqual(cygpath.to_posix_path(
"/c/users/./jane"), "/c/users/jane"
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to posix path: '.*' "
"Please ensure that the path is absolute",
Expand Down Expand Up @@ -349,23 +349,23 @@ def test_paths_with_mixed_slashes(self):

@platform_dependent(["windows"])
def test_paths_with_no_drive_letter(self):
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to mixed path: '.*' "
"Please ensure that the path is absolute",
cygpath.to_mixed_path,
'\\foo\\bar'
)

self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to mixed path: '.*' "
"Please ensure that the path is absolute",
cygpath.to_mixed_path,
'\\\\my_folder\\my_file.txt'
)

self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to mixed path: '.*' "
"Please ensure that the path is absolute",
Expand All @@ -387,7 +387,7 @@ def test_dotted_paths(self):
self.assertEqual(cygpath.to_mixed_path(
"C:/users/./jane"), "C:/users/jane"
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
ValueError,
"Cannot convert path to posix path: '.*' "
"Please ensure that the path is absolute",
Expand Down
8 changes: 8 additions & 0 deletions src/rez/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
except ImportError:
use_parameterized = False

# For py2 backwards compatibility
if not hasattr(unittest.TestCase, 'assertRaisesRegex'):
setattr(
unittest.TestCase,
'assertRaisesRegex',
unittest.TestCase.assertRaisesRegexp
)


class TestBase(unittest.TestCase):
"""Unit test base class."""
Expand Down

0 comments on commit 89fa4ac

Please sign in to comment.