D927: test-hook: make test compatible with chg

singhsrb (Saurabh Singh) phabricator at mercurial-scm.org
Tue Oct 3 21:37:27 UTC 2017


singhsrb created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The test uses the 'print' method instead of writing to stdout using
  'ui.write' which leads to incompatibility with chg. This commit modifies the
  test to use 'ui' instead which fixes the problem.

TEST PLAN
  Ran the test 'test-hook.t' with and without '--chg' option.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D927

AFFECTED FILES
  tests/test-hook.t

CHANGE DETAILS

diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -413,20 +413,18 @@
   > 
   > uncallable = 0
   > 
-  > def printargs(args):
-  >     args.pop('ui', None)
-  >     args.pop('repo', None)
+  > def printargs(ui, args):
   >     a = list(args.items())
   >     a.sort()
-  >     print('hook args:')
+  >     ui.write('hook args:\n')
   >     for k, v in a:
-  >        print(' ', k, v)
+  >        ui.write('  %s %s\n' % (k, v))
   > 
-  > def passhook(**args):
-  >     printargs(args)
+  > def passhook(ui, repo, **args):
+  >     printargs(ui, args)
   > 
-  > def failhook(**args):
-  >     printargs(args)
+  > def failhook(ui, repo, **args):
+  >     printargs(ui, args)
   >     return True
   > 
   > class LocalException(Exception):
@@ -445,7 +443,7 @@
   >     ui.note('verbose output from hook\n')
   > 
   > def printtags(ui, repo, **args):
-  >     print(sorted(repo.tags()))
+  >     ui.write('%s\n' % sorted(repo.tags()))
   > 
   > class container:
   >     unreachable = 1
@@ -629,8 +627,8 @@
   $ cd c
 
   $ cat > hookext.py <<EOF
-  > def autohook(**args):
-  >     print("Automatically installed hook")
+  > def autohook(ui, **args):
+  >     ui.write('Automatically installed hook\n')
   > 
   > def reposetup(ui, repo):
   >     repo.ui.setconfig("hooks", "commit.auto", autohook)
@@ -666,8 +664,8 @@
 
   $ cd hooks
   $ cat > testhooks.py <<EOF
-  > def testhook(**args):
-  >     print('hook works')
+  > def testhook(ui, **args):
+  >     ui.write('hook works\n')
   > EOF
   $ echo '[hooks]' > ../repo/.hg/hgrc
   $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc



To: singhsrb, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list