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

login
register
mail settings
Submitter Pulkit Goyal
Date June 18, 2020, 2:19 p.m.
Message ID <aa21ff5dc30e7b05086b.1592489941@workspace>
Download mbox | patch
Permalink /patch/46529/
State New
Headers show

Comments

Pulkit Goyal - June 18, 2020, 2:19 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1592483079 -19800
#      Thu Jun 18 17:54:39 2020 +0530
# Node ID aa21ff5dc30e7b05086b34f513410e1043c02642
# 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.

Patch

diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -152,21 +152,25 @@  Check that extensions are loaded in phas
   > from __future__ import print_function
   > import os
   > from mercurial import exthelper
+  > from mercurial.utils import procutil
+  > 
+  > write = procutil.stdout.write
   > name = os.path.basename(__file__).rsplit('.', 1)[0]
-  > print("1) %s imported" % name, flush=True)
+  > bytesname = name.encode('utf-8')
+  > write(b"1) %s imported\n" % bytesname)
   > eh = exthelper.exthelper()
   > @eh.uisetup
   > def _uisetup(ui):
-  >     print("2) %s uisetup" % name, flush=True)
+  >     write(b"2) %s uisetup\n" % bytesname)
   > @eh.extsetup
   > def _extsetup(ui):
-  >     print("3) %s extsetup" % name, flush=True)
+  >     write(b"3) %s extsetup\n" % bytesname)
   > @eh.uipopulate
   > def _uipopulate(ui):
-  >     print("4) %s uipopulate" % name, flush=True)
+  >     write(b"4) %s uipopulate\n" % bytesname)
   > @eh.reposetup
   > def _reposetup(ui, repo):
-  >     print("5) %s reposetup" % name, flush=True)
+  >     write(b"5) %s reposetup\n" % bytesname)
   > 
   > extsetup = eh.finalextsetup
   > reposetup = eh.finalreposetup
@@ -174,7 +178,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,