From 6f14a29b074119b4fb3d2b48a70dbe8b5a009129 Mon Sep 17 00:00:00 2001 From: Jan Vrany Date: Mon, 2 Dec 2024 11:01:36 +0000 Subject: [PATCH] Add compatibility for Python < 3.2 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. --- jitbuilder/apigen/test/cppgentests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jitbuilder/apigen/test/cppgentests.py b/jitbuilder/apigen/test/cppgentests.py index 7e3bcfeb0..a70620b18 100644 --- a/jitbuilder/apigen/test/cppgentests.py +++ b/jitbuilder/apigen/test/cppgentests.py @@ -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"""