Patchwork tests: use ui.warn() instead of print() in test-extension.t

login
register
mail settings
Submitter Pulkit Goyal
Date June 18, 2020, 12:37 p.m.
Message ID <5c4adcb9e188a83a0e5d.1592483842@workspace>
Download mbox | patch
Permalink /patch/46527/
State Superseded
Headers show

Comments

Pulkit Goyal - June 18, 2020, 12:37 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1592483079 -19800
#      Thu Jun 18 17:54:39 2020 +0530
# Node ID 5c4adcb9e188a83a0e5daaa81db2ea0d467cc1df
# Parent  9bc86abdc75bd009d908cd6f5b6fc7fcff82a60c
# EXP-Topic chg-test
tests: use ui.warn() instead of print() in test-extension.t

I was debugging this test failure on python3 + chg. I get the following hunk as
test failure:

```
@@ -206,6 +206,18 @@ Check normal command's load order of ext
   4) bar uipopulate
   5) foo reposetup
   5) bar reposetup
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  5) foo reposetup (chg !)
+  5) bar reposetup (chg !)
   0:c24b9ac61126
```

After hours of debugging and head scracthing, I figured out the python2 with chg
output is wrong. `print(.., flush=True)` is not printing things. I converted it
into `ui.warn()` and now it shows the extra output on py2 also.

I am not sure whether the fix is correct, or what's the correct way to fix this.

Also, I guess using ui.write() instead of ui.warn() will prevent the extra test
changes which happened.
Yuya Nishihara - June 18, 2020, 1:49 p.m.
On Thu, 18 Jun 2020 18:07:22 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1592483079 -19800
> #      Thu Jun 18 17:54:39 2020 +0530
> # Node ID 5c4adcb9e188a83a0e5daaa81db2ea0d467cc1df
> # Parent  9bc86abdc75bd009d908cd6f5b6fc7fcff82a60c
> # EXP-Topic chg-test
> tests: use ui.warn() instead of print() in test-extension.t

> diff --git a/tests/test-extension.t b/tests/test-extension.t
> --- a/tests/test-extension.t
> +++ b/tests/test-extension.t
> @@ -153,20 +153,21 @@ Check that extensions are loaded in phas
>    > import os
>    > from mercurial import exthelper
>    > name = os.path.basename(__file__).rsplit('.', 1)[0]
> +  > bytesname = name.encode('utf-8')
>    > print("1) %s imported" % name, flush=True)

It's probably better to rewrite this print() with procutil.stdout|err.write()
so the output will be displayed in order.

> -  >     print("2) %s uisetup" % name, flush=True)
> +  >     ui.warn(b"2) %s uisetup\n" % bytesname)

>    $ PATH_INFO='/' SCRIPT_NAME='' "$PYTHON" hgweb.cgi \
>    >    | grep '^[0-9]) ' # ignores HTML output
> -  1) foo imported
> -  1) bar imported
>    2) foo uisetup
>    2) bar uisetup
>    3) foo extsetup
> @@ -234,6 +244,8 @@ Check hgweb's load order of extensions a
>    4) bar uipopulate
>    5) foo reposetup
>    5) bar reposetup
> +  1) foo imported
> +  1) bar imported

> @@ -245,6 +257,16 @@ Check hgweb's load order of extensions a
>    $ export PATH_INFO
>    $ SCRIPT_NAME='' QUERY_STRING='rev=foo() and bar()' "$PYTHON" hgweb.cgi \
>    >     | grep '<a href="/rev/[0-9a-z]*">'
> +  2) foo uisetup
> +  2) bar uisetup
> +  3) foo extsetup
> +  3) bar extsetup
> +  4) foo uipopulate
> +  4) bar uipopulate
> +  4) foo uipopulate
> +  4) bar uipopulate
> +  5) foo reposetup
> +  5) bar reposetup

And this is because of ui.warn(). Since the output looks uninteresting,
it can be suppressed by either 2>/dev/null or using ui.write().

Patch

diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -153,20 +153,21 @@  Check that extensions are loaded in phas
   > import os
   > from mercurial import exthelper
   > name = os.path.basename(__file__).rsplit('.', 1)[0]
+  > bytesname = name.encode('utf-8')
   > print("1) %s imported" % name, flush=True)
   > eh = exthelper.exthelper()
   > @eh.uisetup
   > def _uisetup(ui):
-  >     print("2) %s uisetup" % name, flush=True)
+  >     ui.warn(b"2) %s uisetup\n" % bytesname)
   > @eh.extsetup
   > def _extsetup(ui):
-  >     print("3) %s extsetup" % name, flush=True)
+  >     ui.warn(b"3) %s extsetup\n" % bytesname)
   > @eh.uipopulate
   > def _uipopulate(ui):
-  >     print("4) %s uipopulate" % name, flush=True)
+  >     ui.warn(b"4) %s uipopulate\n" % bytesname)
   > @eh.reposetup
   > def _reposetup(ui, repo):
-  >     print("5) %s reposetup" % name, flush=True)
+  >     ui.warn(b"5) %s reposetup\n" % bytesname)
   > 
   > extsetup = eh.finalextsetup
   > reposetup = eh.finalreposetup
@@ -174,7 +175,6 @@  Check that extensions are loaded in phas
   > uisetup = eh.finaluisetup
   > revsetpredicate = eh.revsetpredicate
   > 
-  > bytesname = name.encode('utf-8')
   > # custom predicate to check registration of functions at loading
   > from mercurial import (
   >     smartset,
@@ -206,6 +206,18 @@  Check normal command's load order of ext
   4) bar uipopulate
   5) foo reposetup
   5) bar reposetup
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  4) foo uipopulate (chg !)
+  4) bar uipopulate (chg !)
+  5) foo reposetup (chg !)
+  5) bar reposetup (chg !)
   0:c24b9ac61126
 
 Check hgweb's load order of extensions and registration of functions
@@ -222,8 +234,6 @@  Check hgweb's load order of extensions a
 
   $ PATH_INFO='/' SCRIPT_NAME='' "$PYTHON" hgweb.cgi \
   >    | grep '^[0-9]) ' # ignores HTML output
-  1) foo imported
-  1) bar imported
   2) foo uisetup
   2) bar uisetup
   3) foo extsetup
@@ -234,6 +244,8 @@  Check hgweb's load order of extensions a
   4) bar uipopulate
   5) foo reposetup
   5) bar reposetup
+  1) foo imported
+  1) bar imported
 
 (check that revset predicate foo() and bar() are available)
 
@@ -245,6 +257,16 @@  Check hgweb's load order of extensions a
   $ export PATH_INFO
   $ SCRIPT_NAME='' QUERY_STRING='rev=foo() and bar()' "$PYTHON" hgweb.cgi \
   >     | grep '<a href="/rev/[0-9a-z]*">'
+  2) foo uisetup
+  2) bar uisetup
+  3) foo extsetup
+  3) bar extsetup
+  4) foo uipopulate
+  4) bar uipopulate
+  4) foo uipopulate
+  4) bar uipopulate
+  5) foo reposetup
+  5) bar reposetup
      <a href="/rev/c24b9ac61126">add file</a>
 
   $ echo 'foo = !' >> $HGRCPATH