diff options
author | Simon Glass <sjg@chromium.org> | 2020-10-29 21:46:29 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2020-11-05 09:11:31 -0700 |
commit | 8c17f8c5d21842bc95ca6e27680009b6bc650b0f (patch) | |
tree | c9245b03dd5a019e3e96048cdc2128af1e8bce35 /tools | |
parent | 4af99874562f2ae26e84a9904009c7ce121d540d (diff) | |
download | u-boot-8c17f8c5d21842bc95ca6e27680009b6bc650b0f.tar.gz |
patman: Convert testBasic() to use an interator
On balance it is easier to use an iterator here, particularly if we need
to insert lines due to new functionality. The only niggle is the need to
keep the previous iterator value around in one case.
Convert this test to use iter().
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/patman/func_test.py | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py index 02d46ae5f7..b39e3f671d 100644 --- a/tools/patman/func_test.py +++ b/tools/patman/func_test.py @@ -212,40 +212,39 @@ class TestFunctional(unittest.TestCase): cc_lines = open(cc_file, encoding='utf-8').read().splitlines() os.remove(cc_file) - lines = out[0].getvalue().splitlines() - self.assertEqual('Cleaned %s patches' % len(series.commits), lines[0]) - self.assertEqual('Change log missing for v2', lines[1]) - self.assertEqual('Change log missing for v3', lines[2]) - self.assertEqual('Change log for unknown version v4', lines[3]) - self.assertEqual("Alias 'pci' not found", lines[4]) - self.assertIn('Dry run', lines[5]) - self.assertIn('Send a total of %d patches' % count, lines[7]) - line = 8 - for i in range(len(series.commits)): - self.assertEqual(' %s' % args[i], lines[line + 0]) - line += 1 - while 'Cc:' in lines[line]: - line += 1 - self.assertEqual('To: u-boot@lists.denx.de', lines[line]) - self.assertEqual('Cc: %s' % tools.FromUnicode(stefan), - lines[line + 1]) - self.assertEqual('Version: 3', lines[line + 2]) - self.assertEqual('Prefix:\t RFC', lines[line + 3]) - self.assertEqual('Cover: 4 lines', lines[line + 4]) - line += 5 - self.assertEqual(' Cc: %s' % self.fred, lines[line + 0]) + lines = iter(out[0].getvalue().splitlines()) + self.assertEqual('Cleaned %s patches' % len(series.commits), + next(lines)) + self.assertEqual('Change log missing for v2', next(lines)) + self.assertEqual('Change log missing for v3', next(lines)) + self.assertEqual('Change log for unknown version v4', next(lines)) + self.assertEqual("Alias 'pci' not found", next(lines)) + self.assertIn('Dry run', next(lines)) + self.assertEqual('', next(lines)) + self.assertIn('Send a total of %d patches' % count, next(lines)) + prev = next(lines) + for i, commit in enumerate(series.commits): + self.assertEqual(' %s' % args[i], prev) + while True: + prev = next(lines) + if 'Cc:' not in prev: + break + self.assertEqual('To: u-boot@lists.denx.de', prev) + self.assertEqual('Cc: %s' % tools.FromUnicode(stefan), next(lines)) + self.assertEqual('Version: 3', next(lines)) + self.assertEqual('Prefix:\t RFC', next(lines)) + self.assertEqual('Cover: 4 lines', next(lines)) + self.assertEqual(' Cc: %s' % self.fred, next(lines)) self.assertEqual(' Cc: %s' % tools.FromUnicode(self.leb), - lines[line + 1]) - self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), - lines[line + 2]) - self.assertEqual(' Cc: %s' % rick, lines[line + 3]) + next(lines)) + self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), next(lines)) + self.assertEqual(' Cc: %s' % rick, next(lines)) expected = ('Git command: git send-email --annotate ' '--in-reply-to="%s" --to "u-boot@lists.denx.de" ' '--cc "%s" --cc-cmd "%s --cc-cmd %s" %s %s' % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname, ' '.join(args))) - line += 4 - self.assertEqual(expected, tools.ToUnicode(lines[line])) + self.assertEqual(expected, tools.ToUnicode(next(lines))) self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), tools.ToUnicode(cc_lines[0])) |