summaryrefslogtreecommitdiffstats
path: root/meta/lib/patchtest/tests/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/patchtest/tests/base.py')
-rw-r--r--meta/lib/patchtest/tests/base.py49
1 files changed, 31 insertions, 18 deletions
diff --git a/meta/lib/patchtest/tests/base.py b/meta/lib/patchtest/tests/base.py
index 424e61b5be..919ca136bb 100644
--- a/meta/lib/patchtest/tests/base.py
+++ b/meta/lib/patchtest/tests/base.py
@@ -8,20 +8,23 @@ import unittest
8import logging 8import logging
9import json 9import json
10import unidiff 10import unidiff
11from data import PatchTestInput 11from patchtest_parser import PatchtestParser
12import mailbox 12import mailbox
13import patchtest_patterns
13import collections 14import collections
14import sys 15import sys
15import os 16import os
16import re 17import re
17 18
18sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pyparsing')) 19logger = logging.getLogger("patchtest")
20debug = logger.debug
21info = logger.info
22warn = logger.warn
23error = logger.error
19 24
20logger = logging.getLogger('patchtest') 25Commit = collections.namedtuple(
21debug=logger.debug 26 "Commit", ["author", "subject", "commit_message", "shortlog", "payload"]
22info=logger.info 27)
23warn=logger.warn
24error=logger.error
25 28
26Commit = collections.namedtuple('Commit', ['author', 'subject', 'commit_message', 'shortlog', 'payload']) 29Commit = collections.namedtuple('Commit', ['author', 'subject', 'commit_message', 'shortlog', 'payload'])
27 30
@@ -34,10 +37,6 @@ class PatchtestOEError(Exception):
34class Base(unittest.TestCase): 37class Base(unittest.TestCase):
35 # if unit test fails, fail message will throw at least the following JSON: {"id": <testid>} 38 # if unit test fails, fail message will throw at least the following JSON: {"id": <testid>}
36 39
37 endcommit_messages_regex = re.compile(r'\(From \w+-\w+ rev:|(?<!\S)Signed-off-by|(?<!\S)---\n')
38 patchmetadata_regex = re.compile(r'-{3} \S+|\+{3} \S+|@{2} -\d+,\d+ \+\d+,\d+ @{2} \S+')
39
40
41 @staticmethod 40 @staticmethod
42 def msg_to_commit(msg): 41 def msg_to_commit(msg):
43 payload = msg.get_payload() 42 payload = msg.get_payload()
@@ -50,7 +49,7 @@ class Base(unittest.TestCase):
50 @staticmethod 49 @staticmethod
51 def commit_message(payload): 50 def commit_message(payload):
52 commit_message = payload.__str__() 51 commit_message = payload.__str__()
53 match = Base.endcommit_messages_regex.search(payload) 52 match = patchtest_patterns.endcommit_messages_regex.search(payload)
54 if match: 53 if match:
55 commit_message = payload[:match.start()] 54 commit_message = payload[:match.start()]
56 return commit_message 55 return commit_message
@@ -66,13 +65,15 @@ class Base(unittest.TestCase):
66 def setUpClass(cls): 65 def setUpClass(cls):
67 66
68 # General objects: mailbox.mbox and patchset 67 # General objects: mailbox.mbox and patchset
69 cls.mbox = mailbox.mbox(PatchTestInput.repo.patch) 68 cls.mbox = mailbox.mbox(PatchtestParser.repo.patch.path)
70 69
71 # Patch may be malformed, so try parsing it 70 # Patch may be malformed, so try parsing it
72 cls.unidiff_parse_error = '' 71 cls.unidiff_parse_error = ''
73 cls.patchset = None 72 cls.patchset = None
74 try: 73 try:
75 cls.patchset = unidiff.PatchSet.from_filename(PatchTestInput.repo.patch, encoding=u'UTF-8') 74 cls.patchset = unidiff.PatchSet.from_filename(
75 PatchtestParser.repo.patch.path, encoding="UTF-8"
76 )
76 except unidiff.UnidiffParseError as upe: 77 except unidiff.UnidiffParseError as upe:
77 cls.patchset = [] 78 cls.patchset = []
78 cls.unidiff_parse_error = str(upe) 79 cls.unidiff_parse_error = str(upe)
@@ -149,7 +150,7 @@ class Metadata(Base):
149 150
150 # import relevant libraries 151 # import relevant libraries
151 try: 152 try:
152 scripts_path = os.path.join(PatchTestInput.repodir, 'scripts', 'lib') 153 scripts_path = os.path.join(PatchtestParser.repodir, "scripts", "lib")
153 if scripts_path not in sys.path: 154 if scripts_path not in sys.path:
154 sys.path.insert(0, scripts_path) 155 sys.path.insert(0, scripts_path)
155 import scriptpath 156 import scriptpath
@@ -224,11 +225,23 @@ class Metadata(Base):
224 for patch in patchset: 225 for patch in patchset:
225 if patch.path.endswith('.bb') or patch.path.endswith('.bbappend') or patch.path.endswith('.inc'): 226 if patch.path.endswith('.bb') or patch.path.endswith('.bbappend') or patch.path.endswith('.inc'):
226 if patch.is_added_file: 227 if patch.is_added_file:
227 added_paths.append(os.path.join(os.path.abspath(PatchTestInput.repodir), patch.path)) 228 added_paths.append(
229 os.path.join(
230 os.path.abspath(PatchtestParser.repodir), patch.path
231 )
232 )
228 elif patch.is_modified_file: 233 elif patch.is_modified_file:
229 modified_paths.append(os.path.join(os.path.abspath(PatchTestInput.repodir), patch.path)) 234 modified_paths.append(
235 os.path.join(
236 os.path.abspath(PatchtestParser.repodir), patch.path
237 )
238 )
230 elif patch.is_removed_file: 239 elif patch.is_removed_file:
231 removed_paths.append(os.path.join(os.path.abspath(PatchTestInput.repodir), patch.path)) 240 removed_paths.append(
241 os.path.join(
242 os.path.abspath(PatchtestParser.repodir), patch.path
243 )
244 )
232 245
233 data = cls.tinfoil.cooker.recipecaches[''].pkg_fn.items() 246 data = cls.tinfoil.cooker.recipecaches[''].pkg_fn.items()
234 247