Patchwork [U-Boot,2/2] patman: Allow tests to run even if patman is in the path

login
register
mail settings
Submitter Doug Anderson
Date Nov. 27, 2012, 1:21 a.m.
Message ID <1353979300-13927-2-git-send-email-dianders@chromium.org>
Download mbox | patch
Permalink /patch/202066/
State Accepted
Commit a970048e755768e7d7d10c6b209999133ef75814
Delegated to: Simon Glass
Headers show

Comments

Doug Anderson - Nov. 27, 2012, 1:21 a.m.
Several of the patman doctests assume that patman was run with:
  ./patman

Fix them so that they work even if patman is run with just "patman"
(because patman is in the path).

Signed-off-by: Doug Anderson <dianders@chromium.org>
---
 tools/patman/gitutil.py |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
Simon Glass - Nov. 28, 2012, 11:50 p.m.
On Mon, Nov 26, 2012 at 5:21 PM, Doug Anderson <dianders@chromium.org> wrote:
> Several of the patman doctests assume that patman was run with:
>   ./patman
>
> Fix them so that they work even if patman is run with just "patman"
> (because patman is in the path).
>
> Signed-off-by: Doug Anderson <dianders@chromium.org>

Acked-by: Simon Glass <sjg@chromium.org>
Simon Glass - Jan. 31, 2013, 11:49 p.m.
On Thu, Nov 29, 2012 at 12:50 PM, Simon Glass <sjg@chromium.org> wrote:
> On Mon, Nov 26, 2012 at 5:21 PM, Doug Anderson <dianders@chromium.org> wrote:
>> Several of the patman doctests assume that patman was run with:
>>   ./patman
>>
>> Fix them so that they work even if patman is run with just "patman"
>> (because patman is in the path).
>>
>> Signed-off-by: Doug Anderson <dianders@chromium.org>
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-x86, thanks.

Patch

diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py
index 72d37a0..41a74a5 100644
--- a/tools/patman/gitutil.py
+++ b/tools/patman/gitutil.py
@@ -217,6 +217,10 @@  def EmailPatches(series, cover_fname, args, dry_run, cc_fname,
     Returns:
         Git command that was/would be run
 
+    # For the duration of this doctest pretend that we ran patman with ./patman
+    >>> _old_argv0 = sys.argv[0]
+    >>> sys.argv[0] = './patman'
+
     >>> alias = {}
     >>> alias['fred'] = ['f.bloggs@napier.co.nz']
     >>> alias['john'] = ['j.bloggs@napier.co.nz']
@@ -244,6 +248,9 @@  def EmailPatches(series, cover_fname, args, dry_run, cc_fname,
     '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 --cc-cmd cc-fname" cover p1 p2'
+
+    # Restore argv[0] since we clobbered it.
+    >>> sys.argv[0] = _old_argv0
     """
     to = BuildEmailList(series.get('to'), '--to', alias)
     if not to:
@@ -340,8 +347,8 @@  def GetTopLevel():
 
     This test makes sure that we are running tests in the right subdir
 
-    >>> os.path.realpath(os.getcwd()) == \
-            os.path.join(GetTopLevel(), 'tools', 'scripts', 'patman')
+    >>> os.path.realpath(os.path.dirname(__file__)) == \
+            os.path.join(GetTopLevel(), 'tools', 'patman')
     True
     """
     return command.OutputOneLine('git', 'rev-parse', '--show-toplevel')