patman: Add a test for PatchStream tags

The current functional tests run most of patman. Add a smaller test that
just checks tag handling with the PatchStream class.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-10-29 21:46:27 -06:00
parent 47f62952cc
commit 7457051e41
2 changed files with 44 additions and 5 deletions

View file

@ -31,6 +31,9 @@ except ModuleNotFoundError:
class TestFunctional(unittest.TestCase): class TestFunctional(unittest.TestCase):
"""Functional tests for checking that patman behaves correctly""" """Functional tests for checking that patman behaves correctly"""
leb = (b'Lord Edmund Blackadd\xc3\xabr <weasel@blackadder.org>'.
decode('utf-8'))
def setUp(self): def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='patman.') self.tmpdir = tempfile.mkdtemp(prefix='patman.')
self.gitdir = os.path.join(self.tmpdir, 'git') self.gitdir = os.path.join(self.tmpdir, 'git')
@ -177,8 +180,6 @@ class TestFunctional(unittest.TestCase):
stefan = b'Stefan Br\xc3\xbcns <stefan.bruens@rwth-aachen.de>'.decode('utf-8') stefan = b'Stefan Br\xc3\xbcns <stefan.bruens@rwth-aachen.de>'.decode('utf-8')
rick = 'Richard III <richard@palace.gov>' rick = 'Richard III <richard@palace.gov>'
mel = b'Lord M\xc3\xablchett <clergy@palace.gov>'.decode('utf-8') mel = b'Lord M\xc3\xablchett <clergy@palace.gov>'.decode('utf-8')
leb = (b'Lond Edmund Blackadd\xc3\xabr <weasel@blackadder.org'.
decode('utf-8'))
fred = 'Fred Bloggs <f.bloggs@napier.net>' fred = 'Fred Bloggs <f.bloggs@napier.net>'
add_maintainers = [stefan, rick] add_maintainers = [stefan, rick]
dry_run = True dry_run = True
@ -187,7 +188,7 @@ class TestFunctional(unittest.TestCase):
settings.alias = { settings.alias = {
'fdt': ['simon'], 'fdt': ['simon'],
'u-boot': ['u-boot@lists.denx.de'], 'u-boot': ['u-boot@lists.denx.de'],
'simon': [leb], 'simon': [self.leb],
'fred': [fred], 'fred': [fred],
} }
@ -231,7 +232,7 @@ class TestFunctional(unittest.TestCase):
self.assertEqual('Cover: 4 lines', lines[line + 4]) self.assertEqual('Cover: 4 lines', lines[line + 4])
line += 5 line += 5
self.assertEqual(' Cc: %s' % fred, lines[line + 0]) self.assertEqual(' Cc: %s' % fred, lines[line + 0])
self.assertEqual(' Cc: %s' % tools.FromUnicode(leb), self.assertEqual(' Cc: %s' % tools.FromUnicode(self.leb),
lines[line + 1]) lines[line + 1])
self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), self.assertEqual(' Cc: %s' % tools.FromUnicode(mel),
lines[line + 2]) lines[line + 2])
@ -247,7 +248,7 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)),
tools.ToUnicode(cc_lines[0])) tools.ToUnicode(cc_lines[0]))
self.assertEqual( self.assertEqual(
'%s %s\0%s\0%s\0%s' % (args[1], fred, leb, rick, stefan), '%s %s\0%s\0%s\0%s' % (args[1], fred, self.leb, rick, stefan),
tools.ToUnicode(cc_lines[1])) tools.ToUnicode(cc_lines[1]))
expected = ''' expected = '''
@ -480,3 +481,18 @@ complicated as possible''')
self.assertEqual(2, len(patch_files)) self.assertEqual(2, len(patch_files))
finally: finally:
os.chdir(orig_dir) os.chdir(orig_dir)
def testTags(self):
"""Test collection of tags in a patchstream"""
text = '''This is a patch
Signed-off-by: Terminator
Reviewed-by: Joe Bloggs <joe@napierwallies.co.nz>
Reviewed-by: Mary Bloggs <mary@napierwallies.co.nz>
Tested-by: %s
''' % self.leb
pstrm = PatchStream.process_text(text)
self.assertEqual(pstrm.commit.rtags, {
'Reviewed-by': {'Mary Bloggs <mary@napierwallies.co.nz>',
'Joe Bloggs <joe@napierwallies.co.nz>'},
'Tested-by': {self.leb}})

View file

@ -5,6 +5,7 @@
"""Handles parsing a stream of commits/emails from 'git log' or other source""" """Handles parsing a stream of commits/emails from 'git log' or other source"""
import datetime import datetime
import io
import math import math
import os import os
import re import re
@ -81,6 +82,28 @@ class PatchStream:
self.state = STATE_MSG_HEADER # What state are we in? self.state = STATE_MSG_HEADER # What state are we in?
self.commit = None # Current commit self.commit = None # Current commit
@staticmethod
def process_text(text, is_comment=False):
"""Process some text through this class using a default Commit/Series
Args:
text (str): Text to parse
is_comment (bool): True if this is a comment rather than a patch.
If True, PatchStream doesn't expect a patch subject at the
start, but jumps straight into the body
Returns:
PatchStream: object with results
"""
pstrm = PatchStream(Series())
pstrm.commit = commit.Commit(None)
infd = io.StringIO(text)
outfd = io.StringIO()
if is_comment:
pstrm.state = STATE_PATCH_HEADER
pstrm.process_stream(infd, outfd)
return pstrm
def _add_warn(self, warn): def _add_warn(self, warn):
"""Add a new warning to report to the user about the current commit """Add a new warning to report to the user about the current commit