func_test.py 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. # -*- coding: utf-8 -*-
  2. # SPDX-License-Identifier: GPL-2.0+
  3. #
  4. # Copyright 2017 Google, Inc
  5. #
  6. """Functional tests for checking that patman behaves correctly"""
  7. import os
  8. import re
  9. import shutil
  10. import sys
  11. import tempfile
  12. import unittest
  13. from patman.commit import Commit
  14. from patman import control
  15. from patman import gitutil
  16. from patman import patchstream
  17. from patman.patchstream import PatchStream
  18. from patman.series import Series
  19. from patman import settings
  20. from patman import terminal
  21. from patman import tools
  22. from patman.test_util import capture_sys_output
  23. try:
  24. import pygit2
  25. HAVE_PYGIT2 = True
  26. from patman import status
  27. except ModuleNotFoundError:
  28. HAVE_PYGIT2 = False
  29. class TestFunctional(unittest.TestCase):
  30. """Functional tests for checking that patman behaves correctly"""
  31. leb = (b'Lord Edmund Blackadd\xc3\xabr <weasel@blackadder.org>'.
  32. decode('utf-8'))
  33. fred = 'Fred Bloggs <f.bloggs@napier.net>'
  34. joe = 'Joe Bloggs <joe@napierwallies.co.nz>'
  35. mary = 'Mary Bloggs <mary@napierwallies.co.nz>'
  36. commits = None
  37. patches = None
  38. def setUp(self):
  39. self.tmpdir = tempfile.mkdtemp(prefix='patman.')
  40. self.gitdir = os.path.join(self.tmpdir, 'git')
  41. self.repo = None
  42. def tearDown(self):
  43. shutil.rmtree(self.tmpdir)
  44. terminal.SetPrintTestMode(False)
  45. @staticmethod
  46. def _get_path(fname):
  47. """Get the path to a test file
  48. Args:
  49. fname (str): Filename to obtain
  50. Returns:
  51. str: Full path to file in the test directory
  52. """
  53. return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
  54. 'test', fname)
  55. @classmethod
  56. def _get_text(cls, fname):
  57. """Read a file as text
  58. Args:
  59. fname (str): Filename to read
  60. Returns:
  61. str: Contents of file
  62. """
  63. return open(cls._get_path(fname), encoding='utf-8').read()
  64. @classmethod
  65. def _get_patch_name(cls, subject):
  66. """Get the filename of a patch given its subject
  67. Args:
  68. subject (str): Patch subject
  69. Returns:
  70. str: Filename for that patch
  71. """
  72. fname = re.sub('[ :]', '-', subject)
  73. return fname.replace('--', '-')
  74. def _create_patches_for_test(self, series):
  75. """Create patch files for use by tests
  76. This copies patch files from the test directory as needed by the series
  77. Args:
  78. series (Series): Series containing commits to convert
  79. Returns:
  80. tuple:
  81. str: Cover-letter filename, or None if none
  82. fname_list: list of str, each a patch filename
  83. """
  84. cover_fname = None
  85. fname_list = []
  86. for i, commit in enumerate(series.commits):
  87. clean_subject = self._get_patch_name(commit.subject)
  88. src_fname = '%04d-%s.patch' % (i + 1, clean_subject[:52])
  89. fname = os.path.join(self.tmpdir, src_fname)
  90. shutil.copy(self._get_path(src_fname), fname)
  91. fname_list.append(fname)
  92. if series.get('cover'):
  93. src_fname = '0000-cover-letter.patch'
  94. cover_fname = os.path.join(self.tmpdir, src_fname)
  95. fname = os.path.join(self.tmpdir, src_fname)
  96. shutil.copy(self._get_path(src_fname), fname)
  97. return cover_fname, fname_list
  98. def testBasic(self):
  99. """Tests the basic flow of patman
  100. This creates a series from some hard-coded patches build from a simple
  101. tree with the following metadata in the top commit:
  102. Series-to: u-boot
  103. Series-prefix: RFC
  104. Series-cc: Stefan Brüns <stefan.bruens@rwth-aachen.de>
  105. Cover-letter-cc: Lord Mëlchett <clergy@palace.gov>
  106. Series-version: 3
  107. Patch-cc: fred
  108. Series-process-log: sort, uniq
  109. Series-changes: 4
  110. - Some changes
  111. - Multi
  112. line
  113. change
  114. Commit-changes: 2
  115. - Changes only for this commit
  116. Cover-changes: 4
  117. - Some notes for the cover letter
  118. Cover-letter:
  119. test: A test patch series
  120. This is a test of how the cover
  121. letter
  122. works
  123. END
  124. and this in the first commit:
  125. Commit-changes: 2
  126. - second revision change
  127. Series-notes:
  128. some notes
  129. about some things
  130. from the first commit
  131. END
  132. Commit-notes:
  133. Some notes about
  134. the first commit
  135. END
  136. with the following commands:
  137. git log -n2 --reverse >/path/to/tools/patman/test/test01.txt
  138. git format-patch --subject-prefix RFC --cover-letter HEAD~2
  139. mv 00* /path/to/tools/patman/test
  140. It checks these aspects:
  141. - git log can be processed by patchstream
  142. - emailing patches uses the correct command
  143. - CC file has information on each commit
  144. - cover letter has the expected text and subject
  145. - each patch has the correct subject
  146. - dry-run information prints out correctly
  147. - unicode is handled correctly
  148. - Series-to, Series-cc, Series-prefix, Cover-letter
  149. - Cover-letter-cc, Series-version, Series-changes, Series-notes
  150. - Commit-notes
  151. """
  152. process_tags = True
  153. ignore_bad_tags = True
  154. stefan = b'Stefan Br\xc3\xbcns <stefan.bruens@rwth-aachen.de>'.decode('utf-8')
  155. rick = 'Richard III <richard@palace.gov>'
  156. mel = b'Lord M\xc3\xablchett <clergy@palace.gov>'.decode('utf-8')
  157. add_maintainers = [stefan, rick]
  158. dry_run = True
  159. in_reply_to = mel
  160. count = 2
  161. settings.alias = {
  162. 'fdt': ['simon'],
  163. 'u-boot': ['u-boot@lists.denx.de'],
  164. 'simon': [self.leb],
  165. 'fred': [self.fred],
  166. }
  167. text = self._get_text('test01.txt')
  168. series = patchstream.get_metadata_for_test(text)
  169. cover_fname, args = self._create_patches_for_test(series)
  170. with capture_sys_output() as out:
  171. patchstream.fix_patches(series, args)
  172. if cover_fname and series.get('cover'):
  173. patchstream.insert_cover_letter(cover_fname, series, count)
  174. series.DoChecks()
  175. cc_file = series.MakeCcFile(process_tags, cover_fname,
  176. not ignore_bad_tags, add_maintainers,
  177. None)
  178. cmd = gitutil.EmailPatches(
  179. series, cover_fname, args, dry_run, not ignore_bad_tags,
  180. cc_file, in_reply_to=in_reply_to, thread=None)
  181. series.ShowActions(args, cmd, process_tags)
  182. cc_lines = open(cc_file, encoding='utf-8').read().splitlines()
  183. os.remove(cc_file)
  184. lines = iter(out[0].getvalue().splitlines())
  185. self.assertEqual('Cleaned %s patches' % len(series.commits),
  186. next(lines))
  187. self.assertEqual('Change log missing for v2', next(lines))
  188. self.assertEqual('Change log missing for v3', next(lines))
  189. self.assertEqual('Change log for unknown version v4', next(lines))
  190. self.assertEqual("Alias 'pci' not found", next(lines))
  191. self.assertIn('Dry run', next(lines))
  192. self.assertEqual('', next(lines))
  193. self.assertIn('Send a total of %d patches' % count, next(lines))
  194. prev = next(lines)
  195. for i, commit in enumerate(series.commits):
  196. self.assertEqual(' %s' % args[i], prev)
  197. while True:
  198. prev = next(lines)
  199. if 'Cc:' not in prev:
  200. break
  201. self.assertEqual('To: u-boot@lists.denx.de', prev)
  202. self.assertEqual('Cc: %s' % tools.FromUnicode(stefan), next(lines))
  203. self.assertEqual('Version: 3', next(lines))
  204. self.assertEqual('Prefix:\t RFC', next(lines))
  205. self.assertEqual('Cover: 4 lines', next(lines))
  206. self.assertEqual(' Cc: %s' % self.fred, next(lines))
  207. self.assertEqual(' Cc: %s' % tools.FromUnicode(self.leb),
  208. next(lines))
  209. self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), next(lines))
  210. self.assertEqual(' Cc: %s' % rick, next(lines))
  211. expected = ('Git command: git send-email --annotate '
  212. '--in-reply-to="%s" --to "u-boot@lists.denx.de" '
  213. '--cc "%s" --cc-cmd "%s send --cc-cmd %s" %s %s'
  214. % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname,
  215. ' '.join(args)))
  216. self.assertEqual(expected, tools.ToUnicode(next(lines)))
  217. self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)),
  218. tools.ToUnicode(cc_lines[0]))
  219. self.assertEqual(
  220. '%s %s\0%s\0%s\0%s' % (args[1], self.fred, self.leb, rick, stefan),
  221. tools.ToUnicode(cc_lines[1]))
  222. expected = '''
  223. This is a test of how the cover
  224. letter
  225. works
  226. some notes
  227. about some things
  228. from the first commit
  229. Changes in v4:
  230. - Multi
  231. line
  232. change
  233. - Some changes
  234. - Some notes for the cover letter
  235. Simon Glass (2):
  236. pci: Correct cast for sandbox
  237. fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base()
  238. cmd/pci.c | 3 ++-
  239. fs/fat/fat.c | 1 +
  240. lib/efi_loader/efi_memory.c | 1 +
  241. lib/fdtdec.c | 3 ++-
  242. 4 files changed, 6 insertions(+), 2 deletions(-)
  243. --\x20
  244. 2.7.4
  245. '''
  246. lines = open(cover_fname, encoding='utf-8').read().splitlines()
  247. self.assertEqual(
  248. 'Subject: [RFC PATCH v3 0/2] test: A test patch series',
  249. lines[3])
  250. self.assertEqual(expected.splitlines(), lines[7:])
  251. for i, fname in enumerate(args):
  252. lines = open(fname, encoding='utf-8').read().splitlines()
  253. subject = [line for line in lines if line.startswith('Subject')]
  254. self.assertEqual('Subject: [RFC %d/%d]' % (i + 1, count),
  255. subject[0][:18])
  256. # Check that we got our commit notes
  257. start = 0
  258. expected = ''
  259. if i == 0:
  260. start = 17
  261. expected = '''---
  262. Some notes about
  263. the first commit
  264. (no changes since v2)
  265. Changes in v2:
  266. - second revision change'''
  267. elif i == 1:
  268. start = 17
  269. expected = '''---
  270. Changes in v4:
  271. - Multi
  272. line
  273. change
  274. - Some changes
  275. Changes in v2:
  276. - Changes only for this commit'''
  277. if expected:
  278. expected = expected.splitlines()
  279. self.assertEqual(expected, lines[start:(start+len(expected))])
  280. def make_commit_with_file(self, subject, body, fname, text):
  281. """Create a file and add it to the git repo with a new commit
  282. Args:
  283. subject (str): Subject for the commit
  284. body (str): Body text of the commit
  285. fname (str): Filename of file to create
  286. text (str): Text to put into the file
  287. """
  288. path = os.path.join(self.gitdir, fname)
  289. tools.WriteFile(path, text, binary=False)
  290. index = self.repo.index
  291. index.add(fname)
  292. author = pygit2.Signature('Test user', 'test@email.com')
  293. committer = author
  294. tree = index.write_tree()
  295. message = subject + '\n' + body
  296. self.repo.create_commit('HEAD', author, committer, message, tree,
  297. [self.repo.head.target])
  298. def make_git_tree(self):
  299. """Make a simple git tree suitable for testing
  300. It has three branches:
  301. 'base' has two commits: PCI, main
  302. 'first' has base as upstream and two more commits: I2C, SPI
  303. 'second' has base as upstream and three more: video, serial, bootm
  304. Returns:
  305. pygit2.Repository: repository
  306. """
  307. repo = pygit2.init_repository(self.gitdir)
  308. self.repo = repo
  309. new_tree = repo.TreeBuilder().write()
  310. author = pygit2.Signature('Test user', 'test@email.com')
  311. committer = author
  312. _ = repo.create_commit('HEAD', author, committer, 'Created master',
  313. new_tree, [])
  314. self.make_commit_with_file('Initial commit', '''
  315. Add a README
  316. ''', 'README', '''This is the README file
  317. describing this project
  318. in very little detail''')
  319. self.make_commit_with_file('pci: PCI implementation', '''
  320. Here is a basic PCI implementation
  321. ''', 'pci.c', '''This is a file
  322. it has some contents
  323. and some more things''')
  324. self.make_commit_with_file('main: Main program', '''
  325. Hello here is the second commit.
  326. ''', 'main.c', '''This is the main file
  327. there is very little here
  328. but we can always add more later
  329. if we want to
  330. Series-to: u-boot
  331. Series-cc: Barry Crump <bcrump@whataroa.nz>
  332. ''')
  333. base_target = repo.revparse_single('HEAD')
  334. self.make_commit_with_file('i2c: I2C things', '''
  335. This has some stuff to do with I2C
  336. ''', 'i2c.c', '''And this is the file contents
  337. with some I2C-related things in it''')
  338. self.make_commit_with_file('spi: SPI fixes', '''
  339. SPI needs some fixes
  340. and here they are
  341. Signed-off-by: %s
  342. Series-to: u-boot
  343. Commit-notes:
  344. title of the series
  345. This is the cover letter for the series
  346. with various details
  347. END
  348. ''' % self.leb, 'spi.c', '''Some fixes for SPI in this
  349. file to make SPI work
  350. better than before''')
  351. first_target = repo.revparse_single('HEAD')
  352. target = repo.revparse_single('HEAD~2')
  353. repo.reset(target.oid, pygit2.GIT_CHECKOUT_FORCE)
  354. self.make_commit_with_file('video: Some video improvements', '''
  355. Fix up the video so that
  356. it looks more purple. Purple is
  357. a very nice colour.
  358. ''', 'video.c', '''More purple here
  359. Purple and purple
  360. Even more purple
  361. Could not be any more purple''')
  362. self.make_commit_with_file('serial: Add a serial driver', '''
  363. Here is the serial driver
  364. for my chip.
  365. Cover-letter:
  366. Series for my board
  367. This series implements support
  368. for my glorious board.
  369. END
  370. Series-links: 183237
  371. ''', 'serial.c', '''The code for the
  372. serial driver is here''')
  373. self.make_commit_with_file('bootm: Make it boot', '''
  374. This makes my board boot
  375. with a fix to the bootm
  376. command
  377. ''', 'bootm.c', '''Fix up the bootm
  378. command to make the code as
  379. complicated as possible''')
  380. second_target = repo.revparse_single('HEAD')
  381. repo.branches.local.create('first', first_target)
  382. repo.config.set_multivar('branch.first.remote', '', '.')
  383. repo.config.set_multivar('branch.first.merge', '', 'refs/heads/base')
  384. repo.branches.local.create('second', second_target)
  385. repo.config.set_multivar('branch.second.remote', '', '.')
  386. repo.config.set_multivar('branch.second.merge', '', 'refs/heads/base')
  387. repo.branches.local.create('base', base_target)
  388. return repo
  389. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  390. def testBranch(self):
  391. """Test creating patches from a branch"""
  392. repo = self.make_git_tree()
  393. target = repo.lookup_reference('refs/heads/first')
  394. self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE)
  395. control.setup()
  396. try:
  397. orig_dir = os.getcwd()
  398. os.chdir(self.gitdir)
  399. # Check that it can detect the current branch
  400. self.assertEqual(2, gitutil.CountCommitsToBranch(None))
  401. col = terminal.Color()
  402. with capture_sys_output() as _:
  403. _, cover_fname, patch_files = control.prepare_patches(
  404. col, branch=None, count=-1, start=0, end=0,
  405. ignore_binary=False)
  406. self.assertIsNone(cover_fname)
  407. self.assertEqual(2, len(patch_files))
  408. # Check that it can detect a different branch
  409. self.assertEqual(3, gitutil.CountCommitsToBranch('second'))
  410. with capture_sys_output() as _:
  411. _, cover_fname, patch_files = control.prepare_patches(
  412. col, branch='second', count=-1, start=0, end=0,
  413. ignore_binary=False)
  414. self.assertIsNotNone(cover_fname)
  415. self.assertEqual(3, len(patch_files))
  416. # Check that it can skip patches at the end
  417. with capture_sys_output() as _:
  418. _, cover_fname, patch_files = control.prepare_patches(
  419. col, branch='second', count=-1, start=0, end=1,
  420. ignore_binary=False)
  421. self.assertIsNotNone(cover_fname)
  422. self.assertEqual(2, len(patch_files))
  423. finally:
  424. os.chdir(orig_dir)
  425. def testTags(self):
  426. """Test collection of tags in a patchstream"""
  427. text = '''This is a patch
  428. Signed-off-by: Terminator
  429. Reviewed-by: %s
  430. Reviewed-by: %s
  431. Tested-by: %s
  432. ''' % (self.joe, self.mary, self.leb)
  433. pstrm = PatchStream.process_text(text)
  434. self.assertEqual(pstrm.commit.rtags, {
  435. 'Reviewed-by': {self.joe, self.mary},
  436. 'Tested-by': {self.leb}})
  437. def testMissingEnd(self):
  438. """Test a missing END tag"""
  439. text = '''This is a patch
  440. Cover-letter:
  441. This is the title
  442. missing END after this line
  443. Signed-off-by: Fred
  444. '''
  445. pstrm = PatchStream.process_text(text)
  446. self.assertEqual(["Missing 'END' in section 'cover'"],
  447. pstrm.commit.warn)
  448. def testMissingBlankLine(self):
  449. """Test a missing blank line after a tag"""
  450. text = '''This is a patch
  451. Series-changes: 2
  452. - First line of changes
  453. - Missing blank line after this line
  454. Signed-off-by: Fred
  455. '''
  456. pstrm = PatchStream.process_text(text)
  457. self.assertEqual(["Missing 'blank line' in section 'Series-changes'"],
  458. pstrm.commit.warn)
  459. def testInvalidCommitTag(self):
  460. """Test an invalid Commit-xxx tag"""
  461. text = '''This is a patch
  462. Commit-fred: testing
  463. '''
  464. pstrm = PatchStream.process_text(text)
  465. self.assertEqual(["Line 3: Ignoring Commit-fred"], pstrm.commit.warn)
  466. def testSelfTest(self):
  467. """Test a tested by tag by this user"""
  468. test_line = 'Tested-by: %s@napier.com' % os.getenv('USER')
  469. text = '''This is a patch
  470. %s
  471. ''' % test_line
  472. pstrm = PatchStream.process_text(text)
  473. self.assertEqual(["Ignoring '%s'" % test_line], pstrm.commit.warn)
  474. def testSpaceBeforeTab(self):
  475. """Test a space before a tab"""
  476. text = '''This is a patch
  477. + \tSomething
  478. '''
  479. pstrm = PatchStream.process_text(text)
  480. self.assertEqual(["Line 3/0 has space before tab"], pstrm.commit.warn)
  481. def testLinesAfterTest(self):
  482. """Test detecting lines after TEST= line"""
  483. text = '''This is a patch
  484. TEST=sometest
  485. more lines
  486. here
  487. '''
  488. pstrm = PatchStream.process_text(text)
  489. self.assertEqual(["Found 2 lines after TEST="], pstrm.commit.warn)
  490. def testBlankLineAtEnd(self):
  491. """Test detecting a blank line at the end of a file"""
  492. text = '''This is a patch
  493. diff --git a/lib/fdtdec.c b/lib/fdtdec.c
  494. index c072e54..942244f 100644
  495. --- a/lib/fdtdec.c
  496. +++ b/lib/fdtdec.c
  497. @@ -1200,7 +1200,8 @@ int fdtdec_setup_mem_size_base(void)
  498. }
  499. gd->ram_size = (phys_size_t)(res.end - res.start + 1);
  500. - debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size);
  501. + debug("%s: Initial DRAM size %llx\n", __func__,
  502. + (unsigned long long)gd->ram_size);
  503. +
  504. diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
  505. --
  506. 2.7.4
  507. '''
  508. pstrm = PatchStream.process_text(text)
  509. self.assertEqual(
  510. ["Found possible blank line(s) at end of file 'lib/fdtdec.c'"],
  511. pstrm.commit.warn)
  512. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  513. def testNoUpstream(self):
  514. """Test CountCommitsToBranch when there is no upstream"""
  515. repo = self.make_git_tree()
  516. target = repo.lookup_reference('refs/heads/base')
  517. self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE)
  518. # Check that it can detect the current branch
  519. try:
  520. orig_dir = os.getcwd()
  521. os.chdir(self.gitdir)
  522. with self.assertRaises(ValueError) as exc:
  523. gitutil.CountCommitsToBranch(None)
  524. self.assertIn(
  525. "Failed to determine upstream: fatal: no upstream configured for branch 'base'",
  526. str(exc.exception))
  527. finally:
  528. os.chdir(orig_dir)
  529. @staticmethod
  530. def _fake_patchwork(url, subpath):
  531. """Fake Patchwork server for the function below
  532. This handles accessing a series, providing a list consisting of a
  533. single patch
  534. Args:
  535. url (str): URL of patchwork server
  536. subpath (str): URL subpath to use
  537. """
  538. re_series = re.match(r'series/(\d*)/$', subpath)
  539. if re_series:
  540. series_num = re_series.group(1)
  541. if series_num == '1234':
  542. return {'patches': [
  543. {'id': '1', 'name': 'Some patch'}]}
  544. raise ValueError('Fake Patchwork does not understand: %s' % subpath)
  545. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  546. def testStatusMismatch(self):
  547. """Test Patchwork patches not matching the series"""
  548. series = Series()
  549. with capture_sys_output() as (_, err):
  550. status.collect_patches(series, 1234, None, self._fake_patchwork)
  551. self.assertIn('Warning: Patchwork reports 1 patches, series has 0',
  552. err.getvalue())
  553. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  554. def testStatusReadPatch(self):
  555. """Test handling a single patch in Patchwork"""
  556. series = Series()
  557. series.commits = [Commit('abcd')]
  558. patches = status.collect_patches(series, 1234, None,
  559. self._fake_patchwork)
  560. self.assertEqual(1, len(patches))
  561. patch = patches[0]
  562. self.assertEqual('1', patch.id)
  563. self.assertEqual('Some patch', patch.raw_subject)
  564. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  565. def testParseSubject(self):
  566. """Test parsing of the patch subject"""
  567. patch = status.Patch('1')
  568. # Simple patch not in a series
  569. patch.parse_subject('Testing')
  570. self.assertEqual('Testing', patch.raw_subject)
  571. self.assertEqual('Testing', patch.subject)
  572. self.assertEqual(1, patch.seq)
  573. self.assertEqual(1, patch.count)
  574. self.assertEqual(None, patch.prefix)
  575. self.assertEqual(None, patch.version)
  576. # First patch in a series
  577. patch.parse_subject('[1/2] Testing')
  578. self.assertEqual('[1/2] Testing', patch.raw_subject)
  579. self.assertEqual('Testing', patch.subject)
  580. self.assertEqual(1, patch.seq)
  581. self.assertEqual(2, patch.count)
  582. self.assertEqual(None, patch.prefix)
  583. self.assertEqual(None, patch.version)
  584. # Second patch in a series
  585. patch.parse_subject('[2/2] Testing')
  586. self.assertEqual('Testing', patch.subject)
  587. self.assertEqual(2, patch.seq)
  588. self.assertEqual(2, patch.count)
  589. self.assertEqual(None, patch.prefix)
  590. self.assertEqual(None, patch.version)
  591. # RFC patch
  592. patch.parse_subject('[RFC,3/7] Testing')
  593. self.assertEqual('Testing', patch.subject)
  594. self.assertEqual(3, patch.seq)
  595. self.assertEqual(7, patch.count)
  596. self.assertEqual('RFC', patch.prefix)
  597. self.assertEqual(None, patch.version)
  598. # Version patch
  599. patch.parse_subject('[v2,3/7] Testing')
  600. self.assertEqual('Testing', patch.subject)
  601. self.assertEqual(3, patch.seq)
  602. self.assertEqual(7, patch.count)
  603. self.assertEqual(None, patch.prefix)
  604. self.assertEqual('v2', patch.version)
  605. # All fields
  606. patch.parse_subject('[RESEND,v2,3/7] Testing')
  607. self.assertEqual('Testing', patch.subject)
  608. self.assertEqual(3, patch.seq)
  609. self.assertEqual(7, patch.count)
  610. self.assertEqual('RESEND', patch.prefix)
  611. self.assertEqual('v2', patch.version)
  612. # RFC only
  613. patch.parse_subject('[RESEND] Testing')
  614. self.assertEqual('Testing', patch.subject)
  615. self.assertEqual(1, patch.seq)
  616. self.assertEqual(1, patch.count)
  617. self.assertEqual('RESEND', patch.prefix)
  618. self.assertEqual(None, patch.version)
  619. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  620. def testCompareSeries(self):
  621. """Test operation of compare_with_series()"""
  622. commit1 = Commit('abcd')
  623. commit1.subject = 'Subject 1'
  624. commit2 = Commit('ef12')
  625. commit2.subject = 'Subject 2'
  626. commit3 = Commit('3456')
  627. commit3.subject = 'Subject 2'
  628. patch1 = status.Patch('1')
  629. patch1.subject = 'Subject 1'
  630. patch2 = status.Patch('2')
  631. patch2.subject = 'Subject 2'
  632. patch3 = status.Patch('3')
  633. patch3.subject = 'Subject 2'
  634. series = Series()
  635. series.commits = [commit1]
  636. patches = [patch1]
  637. patch_for_commit, commit_for_patch, warnings = (
  638. status.compare_with_series(series, patches))
  639. self.assertEqual(1, len(patch_for_commit))
  640. self.assertEqual(patch1, patch_for_commit[0])
  641. self.assertEqual(1, len(commit_for_patch))
  642. self.assertEqual(commit1, commit_for_patch[0])
  643. series.commits = [commit1]
  644. patches = [patch1, patch2]
  645. patch_for_commit, commit_for_patch, warnings = (
  646. status.compare_with_series(series, patches))
  647. self.assertEqual(1, len(patch_for_commit))
  648. self.assertEqual(patch1, patch_for_commit[0])
  649. self.assertEqual(1, len(commit_for_patch))
  650. self.assertEqual(commit1, commit_for_patch[0])
  651. self.assertEqual(["Cannot find commit for patch 2 ('Subject 2')"],
  652. warnings)
  653. series.commits = [commit1, commit2]
  654. patches = [patch1]
  655. patch_for_commit, commit_for_patch, warnings = (
  656. status.compare_with_series(series, patches))
  657. self.assertEqual(1, len(patch_for_commit))
  658. self.assertEqual(patch1, patch_for_commit[0])
  659. self.assertEqual(1, len(commit_for_patch))
  660. self.assertEqual(commit1, commit_for_patch[0])
  661. self.assertEqual(["Cannot find patch for commit 2 ('Subject 2')"],
  662. warnings)
  663. series.commits = [commit1, commit2, commit3]
  664. patches = [patch1, patch2]
  665. patch_for_commit, commit_for_patch, warnings = (
  666. status.compare_with_series(series, patches))
  667. self.assertEqual(2, len(patch_for_commit))
  668. self.assertEqual(patch1, patch_for_commit[0])
  669. self.assertEqual(patch2, patch_for_commit[1])
  670. self.assertEqual(1, len(commit_for_patch))
  671. self.assertEqual(commit1, commit_for_patch[0])
  672. self.assertEqual(["Cannot find patch for commit 3 ('Subject 2')",
  673. "Multiple commits match patch 2 ('Subject 2'):\n"
  674. ' Subject 2\n Subject 2'],
  675. warnings)
  676. series.commits = [commit1, commit2]
  677. patches = [patch1, patch2, patch3]
  678. patch_for_commit, commit_for_patch, warnings = (
  679. status.compare_with_series(series, patches))
  680. self.assertEqual(1, len(patch_for_commit))
  681. self.assertEqual(patch1, patch_for_commit[0])
  682. self.assertEqual(2, len(commit_for_patch))
  683. self.assertEqual(commit1, commit_for_patch[0])
  684. self.assertEqual(["Multiple patches match commit 2 ('Subject 2'):\n"
  685. ' Subject 2\n Subject 2',
  686. "Cannot find commit for patch 3 ('Subject 2')"],
  687. warnings)
  688. def _fake_patchwork2(self, url, subpath):
  689. """Fake Patchwork server for the function below
  690. This handles accessing series, patches and comments, providing the data
  691. in self.patches to the caller
  692. Args:
  693. url (str): URL of patchwork server
  694. subpath (str): URL subpath to use
  695. """
  696. re_series = re.match(r'series/(\d*)/$', subpath)
  697. re_patch = re.match(r'patches/(\d*)/$', subpath)
  698. re_comments = re.match(r'patches/(\d*)/comments/$', subpath)
  699. if re_series:
  700. series_num = re_series.group(1)
  701. if series_num == '1234':
  702. return {'patches': self.patches}
  703. elif re_patch:
  704. patch_num = int(re_patch.group(1))
  705. patch = self.patches[patch_num - 1]
  706. return patch
  707. elif re_comments:
  708. patch_num = int(re_comments.group(1))
  709. patch = self.patches[patch_num - 1]
  710. return patch.comments
  711. raise ValueError('Fake Patchwork does not understand: %s' % subpath)
  712. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  713. def testFindNewResponses(self):
  714. """Test operation of find_new_responses()"""
  715. commit1 = Commit('abcd')
  716. commit1.subject = 'Subject 1'
  717. commit2 = Commit('ef12')
  718. commit2.subject = 'Subject 2'
  719. patch1 = status.Patch('1')
  720. patch1.parse_subject('[1/2] Subject 1')
  721. patch1.name = patch1.raw_subject
  722. patch1.content = 'This is my patch content'
  723. comment1a = {'content': 'Reviewed-by: %s\n' % self.joe}
  724. patch1.comments = [comment1a]
  725. patch2 = status.Patch('2')
  726. patch2.parse_subject('[2/2] Subject 2')
  727. patch2.name = patch2.raw_subject
  728. patch2.content = 'Some other patch content'
  729. comment2a = {
  730. 'content': 'Reviewed-by: %s\nTested-by: %s\n' %
  731. (self.mary, self.leb)}
  732. comment2b = {'content': 'Reviewed-by: %s' % self.fred}
  733. patch2.comments = [comment2a, comment2b]
  734. # This test works by setting up commits and patch for use by the fake
  735. # Rest API function _fake_patchwork2(). It calls various functions in
  736. # the status module after setting up tags in the commits, checking that
  737. # things behaves as expected
  738. self.commits = [commit1, commit2]
  739. self.patches = [patch1, patch2]
  740. count = 2
  741. new_rtag_list = [None] * count
  742. review_list = [None, None]
  743. # Check that the tags are picked up on the first patch
  744. status.find_new_responses(new_rtag_list, review_list, 0, commit1,
  745. patch1, None, self._fake_patchwork2)
  746. self.assertEqual(new_rtag_list[0], {'Reviewed-by': {self.joe}})
  747. # Now the second patch
  748. status.find_new_responses(new_rtag_list, review_list, 1, commit2,
  749. patch2, None, self._fake_patchwork2)
  750. self.assertEqual(new_rtag_list[1], {
  751. 'Reviewed-by': {self.mary, self.fred},
  752. 'Tested-by': {self.leb}})
  753. # Now add some tags to the commit, which means they should not appear as
  754. # 'new' tags when scanning comments
  755. new_rtag_list = [None] * count
  756. commit1.rtags = {'Reviewed-by': {self.joe}}
  757. status.find_new_responses(new_rtag_list, review_list, 0, commit1,
  758. patch1, None, self._fake_patchwork2)
  759. self.assertEqual(new_rtag_list[0], {})
  760. # For the second commit, add Ed and Fred, so only Mary should be left
  761. commit2.rtags = {
  762. 'Tested-by': {self.leb},
  763. 'Reviewed-by': {self.fred}}
  764. status.find_new_responses(new_rtag_list, review_list, 1, commit2,
  765. patch2, None, self._fake_patchwork2)
  766. self.assertEqual(new_rtag_list[1], {'Reviewed-by': {self.mary}})
  767. # Check that the output patches expectations:
  768. # 1 Subject 1
  769. # Reviewed-by: Joe Bloggs <joe@napierwallies.co.nz>
  770. # 2 Subject 2
  771. # Tested-by: Lord Edmund Blackaddër <weasel@blackadder.org>
  772. # Reviewed-by: Fred Bloggs <f.bloggs@napier.net>
  773. # + Reviewed-by: Mary Bloggs <mary@napierwallies.co.nz>
  774. # 1 new response available in patchwork
  775. series = Series()
  776. series.commits = [commit1, commit2]
  777. terminal.SetPrintTestMode()
  778. status.check_patchwork_status(series, '1234', None, None, False, False,
  779. None, self._fake_patchwork2)
  780. lines = iter(terminal.GetPrintTestLines())
  781. col = terminal.Color()
  782. self.assertEqual(terminal.PrintLine(' 1 Subject 1', col.BLUE),
  783. next(lines))
  784. self.assertEqual(
  785. terminal.PrintLine(' Reviewed-by: ', col.GREEN, newline=False,
  786. bright=False),
  787. next(lines))
  788. self.assertEqual(terminal.PrintLine(self.joe, col.WHITE, bright=False),
  789. next(lines))
  790. self.assertEqual(terminal.PrintLine(' 2 Subject 2', col.BLUE),
  791. next(lines))
  792. self.assertEqual(
  793. terminal.PrintLine(' Reviewed-by: ', col.GREEN, newline=False,
  794. bright=False),
  795. next(lines))
  796. self.assertEqual(terminal.PrintLine(self.fred, col.WHITE, bright=False),
  797. next(lines))
  798. self.assertEqual(
  799. terminal.PrintLine(' Tested-by: ', col.GREEN, newline=False,
  800. bright=False),
  801. next(lines))
  802. self.assertEqual(terminal.PrintLine(self.leb, col.WHITE, bright=False),
  803. next(lines))
  804. self.assertEqual(
  805. terminal.PrintLine(' + Reviewed-by: ', col.GREEN, newline=False),
  806. next(lines))
  807. self.assertEqual(terminal.PrintLine(self.mary, col.WHITE),
  808. next(lines))
  809. self.assertEqual(terminal.PrintLine(
  810. '1 new response available in patchwork (use -d to write them to a new branch)',
  811. None), next(lines))
  812. def _fake_patchwork3(self, url, subpath):
  813. """Fake Patchwork server for the function below
  814. This handles accessing series, patches and comments, providing the data
  815. in self.patches to the caller
  816. Args:
  817. url (str): URL of patchwork server
  818. subpath (str): URL subpath to use
  819. """
  820. re_series = re.match(r'series/(\d*)/$', subpath)
  821. re_patch = re.match(r'patches/(\d*)/$', subpath)
  822. re_comments = re.match(r'patches/(\d*)/comments/$', subpath)
  823. if re_series:
  824. series_num = re_series.group(1)
  825. if series_num == '1234':
  826. return {'patches': self.patches}
  827. elif re_patch:
  828. patch_num = int(re_patch.group(1))
  829. patch = self.patches[patch_num - 1]
  830. return patch
  831. elif re_comments:
  832. patch_num = int(re_comments.group(1))
  833. patch = self.patches[patch_num - 1]
  834. return patch.comments
  835. raise ValueError('Fake Patchwork does not understand: %s' % subpath)
  836. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  837. def testCreateBranch(self):
  838. """Test operation of create_branch()"""
  839. repo = self.make_git_tree()
  840. branch = 'first'
  841. dest_branch = 'first2'
  842. count = 2
  843. gitdir = os.path.join(self.gitdir, '.git')
  844. # Set up the test git tree. We use branch 'first' which has two commits
  845. # in it
  846. series = patchstream.get_metadata_for_list(branch, gitdir, count)
  847. self.assertEqual(2, len(series.commits))
  848. patch1 = status.Patch('1')
  849. patch1.parse_subject('[1/2] %s' % series.commits[0].subject)
  850. patch1.name = patch1.raw_subject
  851. patch1.content = 'This is my patch content'
  852. comment1a = {'content': 'Reviewed-by: %s\n' % self.joe}
  853. patch1.comments = [comment1a]
  854. patch2 = status.Patch('2')
  855. patch2.parse_subject('[2/2] %s' % series.commits[1].subject)
  856. patch2.name = patch2.raw_subject
  857. patch2.content = 'Some other patch content'
  858. comment2a = {
  859. 'content': 'Reviewed-by: %s\nTested-by: %s\n' %
  860. (self.mary, self.leb)}
  861. comment2b = {
  862. 'content': 'Reviewed-by: %s' % self.fred}
  863. patch2.comments = [comment2a, comment2b]
  864. # This test works by setting up patches for use by the fake Rest API
  865. # function _fake_patchwork3(). The fake patch comments above should
  866. # result in new review tags that are collected and added to the commits
  867. # created in the destination branch.
  868. self.patches = [patch1, patch2]
  869. count = 2
  870. # Expected output:
  871. # 1 i2c: I2C things
  872. # + Reviewed-by: Joe Bloggs <joe@napierwallies.co.nz>
  873. # 2 spi: SPI fixes
  874. # + Reviewed-by: Fred Bloggs <f.bloggs@napier.net>
  875. # + Reviewed-by: Mary Bloggs <mary@napierwallies.co.nz>
  876. # + Tested-by: Lord Edmund Blackaddër <weasel@blackadder.org>
  877. # 4 new responses available in patchwork
  878. # 4 responses added from patchwork into new branch 'first2'
  879. # <unittest.result.TestResult run=8 errors=0 failures=0>
  880. terminal.SetPrintTestMode()
  881. status.check_patchwork_status(series, '1234', branch, dest_branch,
  882. False, False, None, self._fake_patchwork3,
  883. repo)
  884. lines = terminal.GetPrintTestLines()
  885. self.assertEqual(12, len(lines))
  886. self.assertEqual(
  887. "4 responses added from patchwork into new branch 'first2'",
  888. lines[11].text)
  889. # Check that the destination branch has the new tags
  890. new_series = patchstream.get_metadata_for_list(dest_branch, gitdir,
  891. count)
  892. self.assertEqual(
  893. {'Reviewed-by': {self.joe}},
  894. new_series.commits[0].rtags)
  895. self.assertEqual(
  896. {'Tested-by': {self.leb},
  897. 'Reviewed-by': {self.fred, self.mary}},
  898. new_series.commits[1].rtags)
  899. # Now check the actual test of the first commit message. We expect to
  900. # see the new tags immediately below the old ones.
  901. stdout = patchstream.get_list(dest_branch, count=count, git_dir=gitdir)
  902. lines = iter([line.strip() for line in stdout.splitlines()
  903. if '-by:' in line])
  904. # First patch should have the review tag
  905. self.assertEqual('Reviewed-by: %s' % self.joe, next(lines))
  906. # Second patch should have the sign-off then the tested-by and two
  907. # reviewed-by tags
  908. self.assertEqual('Signed-off-by: %s' % self.leb, next(lines))
  909. self.assertEqual('Reviewed-by: %s' % self.fred, next(lines))
  910. self.assertEqual('Reviewed-by: %s' % self.mary, next(lines))
  911. self.assertEqual('Tested-by: %s' % self.leb, next(lines))
  912. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  913. def testParseSnippets(self):
  914. """Test parsing of review snippets"""
  915. text = '''Hi Fred,
  916. This is a comment from someone.
  917. Something else
  918. On some recent date, Fred wrote:
  919. > This is why I wrote the patch
  920. > so here it is
  921. Now a comment about the commit message
  922. A little more to say
  923. Even more
  924. > diff --git a/file.c b/file.c
  925. > Some more code
  926. > Code line 2
  927. > Code line 3
  928. > Code line 4
  929. > Code line 5
  930. > Code line 6
  931. > Code line 7
  932. > Code line 8
  933. > Code line 9
  934. And another comment
  935. > @@ -153,8 +143,13 @@ def CheckPatch(fname, show_types=False):
  936. > further down on the file
  937. > and more code
  938. > +Addition here
  939. > +Another addition here
  940. > codey
  941. > more codey
  942. and another thing in same file
  943. > @@ -253,8 +243,13 @@
  944. > with no function context
  945. one more thing
  946. > diff --git a/tools/patman/main.py b/tools/patman/main.py
  947. > +line of code
  948. now a very long comment in a different file
  949. line2
  950. line3
  951. line4
  952. line5
  953. line6
  954. line7
  955. line8
  956. '''
  957. pstrm = PatchStream.process_text(text, True)
  958. self.assertEqual([], pstrm.commit.warn)
  959. # We expect to the filename and up to 5 lines of code context before
  960. # each comment. The 'On xxx wrote:' bit should be removed.
  961. self.assertEqual(
  962. [['Hi Fred,',
  963. 'This is a comment from someone.',
  964. 'Something else'],
  965. ['> This is why I wrote the patch',
  966. '> so here it is',
  967. 'Now a comment about the commit message',
  968. 'A little more to say', 'Even more'],
  969. ['> File: file.c', '> Code line 5', '> Code line 6',
  970. '> Code line 7', '> Code line 8', '> Code line 9',
  971. 'And another comment'],
  972. ['> File: file.c',
  973. '> Line: 153 / 143: def CheckPatch(fname, show_types=False):',
  974. '> and more code', '> +Addition here', '> +Another addition here',
  975. '> codey', '> more codey', 'and another thing in same file'],
  976. ['> File: file.c', '> Line: 253 / 243',
  977. '> with no function context', 'one more thing'],
  978. ['> File: tools/patman/main.py', '> +line of code',
  979. 'now a very long comment in a different file',
  980. 'line2', 'line3', 'line4', 'line5', 'line6', 'line7', 'line8']],
  981. pstrm.snippets)
  982. @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2')
  983. def testReviewSnippets(self):
  984. """Test showing of review snippets"""
  985. def _to_submitter(who):
  986. m_who = re.match('(.*) <(.*)>', who)
  987. return {
  988. 'name': m_who.group(1),
  989. 'email': m_who.group(2)
  990. }
  991. commit1 = Commit('abcd')
  992. commit1.subject = 'Subject 1'
  993. commit2 = Commit('ef12')
  994. commit2.subject = 'Subject 2'
  995. patch1 = status.Patch('1')
  996. patch1.parse_subject('[1/2] Subject 1')
  997. patch1.name = patch1.raw_subject
  998. patch1.content = 'This is my patch content'
  999. comment1a = {'submitter': _to_submitter(self.joe),
  1000. 'content': '''Hi Fred,
  1001. On some date Fred wrote:
  1002. > diff --git a/file.c b/file.c
  1003. > Some code
  1004. > and more code
  1005. Here is my comment above the above...
  1006. Reviewed-by: %s
  1007. ''' % self.joe}
  1008. patch1.comments = [comment1a]
  1009. patch2 = status.Patch('2')
  1010. patch2.parse_subject('[2/2] Subject 2')
  1011. patch2.name = patch2.raw_subject
  1012. patch2.content = 'Some other patch content'
  1013. comment2a = {
  1014. 'content': 'Reviewed-by: %s\nTested-by: %s\n' %
  1015. (self.mary, self.leb)}
  1016. comment2b = {'submitter': _to_submitter(self.fred),
  1017. 'content': '''Hi Fred,
  1018. On some date Fred wrote:
  1019. > diff --git a/tools/patman/commit.py b/tools/patman/commit.py
  1020. > @@ -41,6 +41,9 @@ class Commit:
  1021. > self.rtags = collections.defaultdict(set)
  1022. > self.warn = []
  1023. >
  1024. > + def __str__(self):
  1025. > + return self.subject
  1026. > +
  1027. > def AddChange(self, version, info):
  1028. > """Add a new change line to the change list for a version.
  1029. >
  1030. A comment
  1031. Reviewed-by: %s
  1032. ''' % self.fred}
  1033. patch2.comments = [comment2a, comment2b]
  1034. # This test works by setting up commits and patch for use by the fake
  1035. # Rest API function _fake_patchwork2(). It calls various functions in
  1036. # the status module after setting up tags in the commits, checking that
  1037. # things behaves as expected
  1038. self.commits = [commit1, commit2]
  1039. self.patches = [patch1, patch2]
  1040. # Check that the output patches expectations:
  1041. # 1 Subject 1
  1042. # Reviewed-by: Joe Bloggs <joe@napierwallies.co.nz>
  1043. # 2 Subject 2
  1044. # Tested-by: Lord Edmund Blackaddër <weasel@blackadder.org>
  1045. # Reviewed-by: Fred Bloggs <f.bloggs@napier.net>
  1046. # + Reviewed-by: Mary Bloggs <mary@napierwallies.co.nz>
  1047. # 1 new response available in patchwork
  1048. series = Series()
  1049. series.commits = [commit1, commit2]
  1050. terminal.SetPrintTestMode()
  1051. status.check_patchwork_status(series, '1234', None, None, False, True,
  1052. None, self._fake_patchwork2)
  1053. lines = iter(terminal.GetPrintTestLines())
  1054. col = terminal.Color()
  1055. self.assertEqual(terminal.PrintLine(' 1 Subject 1', col.BLUE),
  1056. next(lines))
  1057. self.assertEqual(
  1058. terminal.PrintLine(' + Reviewed-by: ', col.GREEN, newline=False),
  1059. next(lines))
  1060. self.assertEqual(terminal.PrintLine(self.joe, col.WHITE), next(lines))
  1061. self.assertEqual(terminal.PrintLine('Review: %s' % self.joe, col.RED),
  1062. next(lines))
  1063. self.assertEqual(terminal.PrintLine(' Hi Fred,', None), next(lines))
  1064. self.assertEqual(terminal.PrintLine('', None), next(lines))
  1065. self.assertEqual(terminal.PrintLine(' > File: file.c', col.MAGENTA),
  1066. next(lines))
  1067. self.assertEqual(terminal.PrintLine(' > Some code', col.MAGENTA),
  1068. next(lines))
  1069. self.assertEqual(terminal.PrintLine(' > and more code', col.MAGENTA),
  1070. next(lines))
  1071. self.assertEqual(terminal.PrintLine(
  1072. ' Here is my comment above the above...', None), next(lines))
  1073. self.assertEqual(terminal.PrintLine('', None), next(lines))
  1074. self.assertEqual(terminal.PrintLine(' 2 Subject 2', col.BLUE),
  1075. next(lines))
  1076. self.assertEqual(
  1077. terminal.PrintLine(' + Reviewed-by: ', col.GREEN, newline=False),
  1078. next(lines))
  1079. self.assertEqual(terminal.PrintLine(self.fred, col.WHITE),
  1080. next(lines))
  1081. self.assertEqual(
  1082. terminal.PrintLine(' + Reviewed-by: ', col.GREEN, newline=False),
  1083. next(lines))
  1084. self.assertEqual(terminal.PrintLine(self.mary, col.WHITE),
  1085. next(lines))
  1086. self.assertEqual(
  1087. terminal.PrintLine(' + Tested-by: ', col.GREEN, newline=False),
  1088. next(lines))
  1089. self.assertEqual(terminal.PrintLine(self.leb, col.WHITE),
  1090. next(lines))
  1091. self.assertEqual(terminal.PrintLine('Review: %s' % self.fred, col.RED),
  1092. next(lines))
  1093. self.assertEqual(terminal.PrintLine(' Hi Fred,', None), next(lines))
  1094. self.assertEqual(terminal.PrintLine('', None), next(lines))
  1095. self.assertEqual(terminal.PrintLine(
  1096. ' > File: tools/patman/commit.py', col.MAGENTA), next(lines))
  1097. self.assertEqual(terminal.PrintLine(
  1098. ' > Line: 41 / 41: class Commit:', col.MAGENTA), next(lines))
  1099. self.assertEqual(terminal.PrintLine(
  1100. ' > + return self.subject', col.MAGENTA), next(lines))
  1101. self.assertEqual(terminal.PrintLine(
  1102. ' > +', col.MAGENTA), next(lines))
  1103. self.assertEqual(
  1104. terminal.PrintLine(' > def AddChange(self, version, info):',
  1105. col.MAGENTA),
  1106. next(lines))
  1107. self.assertEqual(terminal.PrintLine(
  1108. ' > """Add a new change line to the change list for a version.',
  1109. col.MAGENTA), next(lines))
  1110. self.assertEqual(terminal.PrintLine(
  1111. ' >', col.MAGENTA), next(lines))
  1112. self.assertEqual(terminal.PrintLine(
  1113. ' A comment', None), next(lines))
  1114. self.assertEqual(terminal.PrintLine('', None), next(lines))
  1115. self.assertEqual(terminal.PrintLine(
  1116. '4 new responses available in patchwork (use -d to write them to a new branch)',
  1117. None), next(lines))