From 89fa4ac10c52ad26e17f9a3660778b7e9c0a5f12 Mon Sep 17 00:00:00 2001 From: javrin Date: Fri, 16 Jun 2023 14:34:27 -0400 Subject: [PATCH] Backwards compat unittest regex assertions Signed-off-by: javrin --- src/rez/tests/test_utils.py | 22 +++++++++++----------- src/rez/tests/util.py | 8 ++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/rez/tests/test_utils.py b/src/rez/tests/test_utils.py index 9c7cc1f33..c3f093729 100644 --- a/src/rez/tests/test_utils.py +++ b/src/rez/tests/test_utils.py @@ -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", @@ -174,7 +174,7 @@ 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", @@ -182,7 +182,7 @@ def test_relative_paths(self): "jane/documents" ) - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, "Cannot convert path to posix path: '.*' " "Please ensure that the path is absolute", @@ -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", @@ -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", @@ -349,7 +349,7 @@ 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", @@ -357,7 +357,7 @@ def test_paths_with_no_drive_letter(self): '\\foo\\bar' ) - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, "Cannot convert path to mixed path: '.*' " "Please ensure that the path is absolute", @@ -365,7 +365,7 @@ def test_paths_with_no_drive_letter(self): '\\\\my_folder\\my_file.txt' ) - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, "Cannot convert path to mixed path: '.*' " "Please ensure that the path is absolute", @@ -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", diff --git a/src/rez/tests/util.py b/src/rez/tests/util.py index 41dfc57ff..ff04e4549 100644 --- a/src/rez/tests/util.py +++ b/src/rez/tests/util.py @@ -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."""