Skip to content

Commit

Permalink
Add compatibility for Python < 3.2
Browse files Browse the repository at this point in the history
Previous commit renamed `assertRegexpMatches` to `assertRegex` as
the former has been removed in Python 3.12.

However, at the time of writing, not all CI build agents have been
upgraded to Python >= 3.2. At the same time, some agents have
Python 3.12 and cannot be easily downgraded (e.g., RISC-V).

This commit provides a compatibility with Python < 3.2 by implementing
`assertRegex` by means of `assertRegexpMatches` if `assertRegex` is not
available.

This way, JitBuilder API gen tests should pass everywhere. Once all CI
nodes are upgraded, this commit can be reverted.
  • Loading branch information
janvrany committed Dec 2, 2024
1 parent 9fd2d48 commit 6f14a29
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions jitbuilder/apigen/test/cppgentests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
import genutils
import cppgen

# Method assertRegexpMatches has been deprecated in Python 3.2 and compatibility
# alias was apparently removed in Python 3.12.
#
# However not all CI build agents have been upgraded to Python 3.2 while some
# only have Python 3.12+ and cannot be easily downgraded (e.g., RISC-V agents).
#
# The code belows provides compatibility for Python < 3.2
if not hasattr(unittest.TestCase, "assertRegex") and hasattr(unittest.TestCase, "assertRegexpMatches"):
setattr(unittest.TestCase, "assertRegex", unittest.TestCase.assertRegexpMatches)

class CppGeneratorTest(unittest.TestCase):
"""Tests for CppGenerator class"""

Expand Down

0 comments on commit 6f14a29

Please sign in to comment.