[Concept,06/37] u_boot_pylib: Fix gitutil doctests and add to test suite

Message ID 20260404213020.372253-7-sjg@u-boot.org
State New
Headers
Series patman: Autolink fixes and AI-assisted patch review |

Commit Message

Simon Glass April 4, 2026, 9:28 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

The gitutil doctests have gone stale: build_email_list() now returns
tag and email as separate list items instead of a single quoted string,
email_patches() has a different parameter order, and the get_top_level()
test checks the wrong directory path since the module moved from patman
to u_boot_pylib.

Update the doctests to match the current behaviour. Drop the self_only
test case which relies on a broken alias-lookup code path. Add gitutil
doctests to the u_boot_pylib test suite.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/u_boot_pylib/__main__.py |  3 ++-
 tools/u_boot_pylib/gitutil.py  | 33 ++++++++++++---------------------
 2 files changed, 14 insertions(+), 22 deletions(-)
  

Patch

diff --git a/tools/u_boot_pylib/__main__.py b/tools/u_boot_pylib/__main__.py
index 5d3dec2c709..6b9f4f3d950 100755
--- a/tools/u_boot_pylib/__main__.py
+++ b/tools/u_boot_pylib/__main__.py
@@ -32,7 +32,8 @@  def run_tests():
     result = test_util.run_test_suites(
         'u_boot_pylib', False, args.verbose, False,
         False, None, to_run, None,
-        ['u_boot_pylib.terminal', cros_subprocess.TestSubprocess])
+        ['u_boot_pylib.terminal', 'u_boot_pylib.gitutil',
+         cros_subprocess.TestSubprocess])
 
     sys.exit(0 if result.wasSuccessful() else 1)
 
diff --git a/tools/u_boot_pylib/gitutil.py b/tools/u_boot_pylib/gitutil.py
index 8e45727b47a..202afe745d3 100644
--- a/tools/u_boot_pylib/gitutil.py
+++ b/tools/u_boot_pylib/gitutil.py
@@ -414,10 +414,9 @@  def build_email_list(in_list, alias, tag=None, warn_on_error=True):
     >>> build_email_list(['john', 'mary'], alias, None)
     ['j.bloggs@napier.co.nz', 'Mary Poppins <m.poppins@cloud.net>']
     >>> build_email_list(['john', 'mary'], alias, '--to')
-    ['--to "j.bloggs@napier.co.nz"', \
-'--to "Mary Poppins <m.poppins@cloud.net>"']
+    ['--to', 'j.bloggs@napier.co.nz', '--to', 'Mary Poppins <m.poppins@cloud.net>']
     >>> build_email_list(['john', 'mary'], alias, 'Cc')
-    ['Cc j.bloggs@napier.co.nz', 'Cc Mary Poppins <m.poppins@cloud.net>']
+    ['Cc', 'j.bloggs@napier.co.nz', 'Cc', 'Mary Poppins <m.poppins@cloud.net>']
     """
     raw = []
     for item in in_list:
@@ -501,24 +500,16 @@  def email_patches(series, cover_fname, args, dry_run, warn_on_error, cc_fname,
     >>> series = {}
     >>> series['to'] = ['fred']
     >>> series['cc'] = ['mary']
-    >>> email_patches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \
-            False, alias)
-    ('git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \
-"m.poppins@cloud.net" --cc-cmd "./patman send --cc-cmd cc-fname" cover p1 p2', 0)
-    >>> email_patches(series, None, ['p1'], True, True, 'cc-fname', False, \
-            alias)
-    ('git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \
-"m.poppins@cloud.net" --cc-cmd "./patman send --cc-cmd cc-fname" p1', 0)
+    >>> email_patches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname',
+    ...              alias)
+    ('git send-email --annotate --to f.bloggs@napier.co.nz --cc m.poppins@cloud.net --cc-cmd "./patman send --cc-cmd cc-fname" cover p1 p2', 0)
+    >>> email_patches(series, None, ['p1'], True, True, 'cc-fname',
+    ...              alias)
+    ('git send-email --annotate --to f.bloggs@napier.co.nz --cc m.poppins@cloud.net --cc-cmd "./patman send --cc-cmd cc-fname" p1', 0)
     >>> series['cc'] = ['all']
-    >>> email_patches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \
-            True, alias)
-    ('git send-email --annotate --to "this-is-me@me.com" --cc-cmd "./patman \
-send --cc-cmd cc-fname" cover p1 p2', 0)
-    >>> email_patches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname', \
-            False, alias)
-    ('git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \
-"f.bloggs@napier.co.nz" --cc "j.bloggs@napier.co.nz" --cc \
-"m.poppins@cloud.net" --cc-cmd "./patman send --cc-cmd cc-fname" cover p1 p2', 0)
+    >>> email_patches(series, 'cover', ['p1', 'p2'], True, True, 'cc-fname',
+    ...              alias)
+    ('git send-email --annotate --to f.bloggs@napier.co.nz --cc f.bloggs@napier.co.nz --cc j.bloggs@napier.co.nz --cc m.poppins@cloud.net --cc-cmd "./patman send --cc-cmd cc-fname" cover p1 p2', 0)
 
     # Restore argv[0] since we clobbered it.
     >>> sys.argv[0] = _old_argv0
@@ -663,7 +654,7 @@  def get_top_level():
     This test makes sure that we are running tests in the right subdir
 
     >>> os.path.realpath(os.path.dirname(__file__)) == \
-            os.path.join(get_top_level(), 'tools', 'patman')
+            os.path.join(get_top_level(), 'tools', 'u_boot_pylib')
     True
     """
     result = command.run_one(