diff --git a/spec/python/test_eof_exception_bytes.py b/spec/python/test_eof_exception_bytes.py index 7ed3f1316..d0a10f0bf 100644 --- a/spec/python/test_eof_exception_bytes.py +++ b/spec/python/test_eof_exception_bytes.py @@ -3,8 +3,15 @@ from eof_exception_bytes import EofExceptionBytes +# Python 2 has only assertRaisesRegexp method +# Python 3.11 and below have both assertRaisesRegex and assertRaisesRegexp +# Python 2.12 and above has only assertRaisesRegex +# The tests run on both Python 2 & 3, so we add missing method for compatibility +if not hasattr(unittest.TestCase, 'assertRaisesRegex'): + setattr(unittest.TestCase, 'assertRaisesRegex', unittest.TestCase.assertRaisesRegexp) + class TestEofExceptionBytes(unittest.TestCase): def test_eof_exception_bytes(self): - with self.assertRaisesRegexp(EOFError, "^requested \d+ bytes, but only \d+ bytes available$"): + with self.assertRaisesRegex(EOFError, "^requested \d+ bytes, but only \d+ bytes available$"): with EofExceptionBytes.from_file('src/term_strz.bin') as r: pass diff --git a/spec/python/test_eof_exception_u4.py b/spec/python/test_eof_exception_u4.py index 261c35c9c..cc05e9f67 100644 --- a/spec/python/test_eof_exception_u4.py +++ b/spec/python/test_eof_exception_u4.py @@ -3,8 +3,15 @@ from eof_exception_u4 import EofExceptionU4 +# Python 2 has only assertRaisesRegexp method +# Python 3.11 and below have both assertRaisesRegex and assertRaisesRegexp +# Python 2.12 and above has only assertRaisesRegex +# The tests run on both Python 2 & 3, so we add missing method for compatibility +if not hasattr(unittest.TestCase, 'assertRaisesRegex'): + setattr(unittest.TestCase, 'assertRaisesRegex', unittest.TestCase.assertRaisesRegexp) + class TestEofExceptionU4(unittest.TestCase): def test_eof_exception_u4(self): - with self.assertRaisesRegexp(EOFError, "^requested \d+ bytes, but only \d+ bytes available$"): + with self.assertRaisesRegex(EOFError, "^requested \d+ bytes, but only \d+ bytes available$"): with EofExceptionU4.from_file('src/term_strz.bin') as r: pass diff --git a/spec/python/test_eos_exception_bytes.py b/spec/python/test_eos_exception_bytes.py index 92543f87a..c816669ec 100644 --- a/spec/python/test_eos_exception_bytes.py +++ b/spec/python/test_eos_exception_bytes.py @@ -3,8 +3,15 @@ from eos_exception_bytes import EosExceptionBytes +# Python 2 has only assertRaisesRegexp method +# Python 3.11 and below have both assertRaisesRegex and assertRaisesRegexp +# Python 2.12 and above has only assertRaisesRegex +# The tests run on both Python 2 & 3, so we add missing method for compatibility +if not hasattr(unittest.TestCase, 'assertRaisesRegex'): + setattr(unittest.TestCase, 'assertRaisesRegex', unittest.TestCase.assertRaisesRegexp) + class TestEosExceptionBytes(unittest.TestCase): def test_eos_exception_bytes(self): - with self.assertRaisesRegexp(EOFError, "^requested \d+ bytes, but only \d+ bytes available$"): + with self.assertRaisesRegex(EOFError, "^requested \d+ bytes, but only \d+ bytes available$"): with EosExceptionBytes.from_file('src/term_strz.bin') as r: pass diff --git a/spec/python/test_eos_exception_u4.py b/spec/python/test_eos_exception_u4.py index f7e3d2795..6d8011074 100644 --- a/spec/python/test_eos_exception_u4.py +++ b/spec/python/test_eos_exception_u4.py @@ -3,8 +3,15 @@ from eos_exception_u4 import EosExceptionU4 +# Python 2 has only assertRaisesRegexp method +# Python 3.11 and below have both assertRaisesRegex and assertRaisesRegexp +# Python 2.12 and above has only assertRaisesRegex +# The tests run on both Python 2 & 3, so we add missing method for compatibility +if not hasattr(unittest.TestCase, 'assertRaisesRegex'): + setattr(unittest.TestCase, 'assertRaisesRegex', unittest.TestCase.assertRaisesRegexp) + class TestEosExceptionU4(unittest.TestCase): def test_eos_exception_u4(self): - with self.assertRaisesRegexp(EOFError, "^requested \d+ bytes, but only \d+ bytes available$"): + with self.assertRaisesRegex(EOFError, "^requested \d+ bytes, but only \d+ bytes available$"): with EosExceptionU4.from_file('src/term_strz.bin') as r: pass