diff mbox series

[6/7] meta/lib/patchtest: python 3.12 regex

Message ID 20240210131727.342583-7-adrian.freihofer@siemens.com
State Accepted, archived
Commit fe58da13930638037283f9a96fc103835b15f919
Headers show
Series python 3.12 related fixes 2 | expand

Commit Message

Adrian Freihofer Feb. 10, 2024, 1:15 p.m. UTC
Python 3 interprets string literals as Unicode strings, and therefore
\s is treated as an escaped Unicode character which is not correct.
Declaring the RegEx pattern as a raw string instead of unicode is
required for Python 3.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/lib/patchtest/tests/base.py | 4 ++--
 meta/lib/patchtest/utils.py      | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/patchtest/tests/base.py b/meta/lib/patchtest/tests/base.py
index aecbbc4aae5..424e61b5be2 100644
--- a/meta/lib/patchtest/tests/base.py
+++ b/meta/lib/patchtest/tests/base.py
@@ -34,8 +34,8 @@  class PatchtestOEError(Exception):
 class Base(unittest.TestCase):
     # if unit test fails, fail message will throw at least the following JSON: {"id": <testid>}
 
-    endcommit_messages_regex = re.compile('\(From \w+-\w+ rev:|(?<!\S)Signed-off-by|(?<!\S)---\n')
-    patchmetadata_regex   = re.compile('-{3} \S+|\+{3} \S+|@{2} -\d+,\d+ \+\d+,\d+ @{2} \S+')
+    endcommit_messages_regex = re.compile(r'\(From \w+-\w+ rev:|(?<!\S)Signed-off-by|(?<!\S)---\n')
+    patchmetadata_regex   = re.compile(r'-{3} \S+|\+{3} \S+|@{2} -\d+,\d+ \+\d+,\d+ @{2} \S+')
 
 
     @staticmethod
diff --git a/meta/lib/patchtest/utils.py b/meta/lib/patchtest/utils.py
index a4a523b4e25..dd0abc22d9b 100644
--- a/meta/lib/patchtest/utils.py
+++ b/meta/lib/patchtest/utils.py
@@ -132,7 +132,7 @@  def get_subject_prefix(path):
     if len(mbox):
         subject = mbox[0]['subject']
         if subject:
-            pattern = re.compile("(\[.*\])", re.DOTALL)
+            pattern = re.compile(r"(\[.*\])", re.DOTALL)
             match = pattern.search(subject)
             if match:
                 prefix = match.group(1)
@@ -146,8 +146,8 @@  def valid_branch(branch):
     invalid  = lbranch.startswith('patch') or \
                lbranch.startswith('rfc') or \
                lbranch.startswith('resend') or \
-               re.search('^v\d+', lbranch) or \
-               re.search('^\d+/\d+', lbranch)
+               re.search(r'^v\d+', lbranch) or \
+               re.search(r'^\d+/\d+', lbranch)
 
     return not invalid