changeset 43334:4128ffba4431 stable

tests: handle Message-Id email header possible wrapping The "Message-Id" header will get wrapped with a new line when exceeding 75 characters on Python 3 (see changeset 7d4f2e4899c5 introducing usage of email.header.Header.encode and respective doc). This will occur in an unpredictable manner depending on the hostname's length. To make the test output consistent across Python versions and hostname configuration, we add a filter to unwrap this header value.
author Denis Laxalde <denis@laxalde.org>
date Sun, 27 Oct 2019 18:12:24 +0100
parents 91c746a77fa3
children 242ad45b60b3
files tests/test-keyword.t tests/test-notify.t tests/unwrap-message-id.py
diffstat 3 files changed, 42 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-keyword.t	Sun Oct 27 12:51:53 2019 +0900
+++ b/tests/test-keyword.t	Sun Oct 27 18:12:24 2019 +0100
@@ -256,7 +256,8 @@
 
 Pull from bundle and trigger notify
 
-  $ hg pull -u ../kw.hg
+  $ hg pull -u ../kw.hg | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py
   pulling from ../kw.hg
   requesting all changes
   adding changesets
--- a/tests/test-notify.t	Sun Oct 27 12:51:53 2019 +0900
+++ b/tests/test-notify.t	Sun Oct 27 18:12:24 2019 +0100
@@ -196,7 +196,9 @@
 of the very long subject line
 pull (minimal config)
 
-  $ hg --traceback --cwd b --config notify.domain=example.com --config notify.messageidseed=example pull ../a | "$PYTHON" $TESTTMP/filter.py
+  $ hg --traceback --cwd b --config notify.domain=example.com --config notify.messageidseed=example pull ../a | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   pulling from ../a
   searching for changes
   adding changesets
@@ -211,8 +213,7 @@
   Subject: changeset in $TESTTMP/b: b
   From: test@example.com
   X-Hg-Notification: changeset 00a13f371396
-  Message-Id: <hg.ba3098a36bd4c297288d16788623a841f81f618ea961a0f0fd65de7eb1191b66@example.com> (no-py3 !)
-  Message-Id:  <hg.ba3098a36bd4c297288d16788623a841f81f618ea961a0f0fd65de7eb1191b66@example.com> (py3 !)
+  Message-Id: <hg.ba3098a36bd4c297288d16788623a841f81f618ea961a0f0fd65de7eb1191b66@example.com>
   To: baz@example.com, foo@bar
   
   changeset 00a13f371396 in $TESTTMP/b
@@ -256,7 +257,9 @@
 
   $ hg --cwd b rollback
   repository tip rolled back to revision 0 (undo pull)
-  $ hg --traceback --cwd b pull ../a  | "$PYTHON" $TESTTMP/filter.py
+  $ hg --traceback --cwd b pull ../a | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   pulling from ../a
   searching for changes
   adding changesets
@@ -304,7 +307,9 @@
 
   $ hg --cwd b rollback
   repository tip rolled back to revision 0 (undo pull)
-  $ hg --traceback --config notify.maxdiffstat=1 --cwd b pull ../a | "$PYTHON" $TESTTMP/filter.py
+  $ hg --traceback --config notify.maxdiffstat=1 --cwd b pull ../a | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   pulling from ../a
   searching for changes
   adding changesets
@@ -355,7 +360,9 @@
   (branch merge, don't forget to commit)
   $ hg ci -m merge -d '3 0'
   $ cd ..
-  $ hg --traceback --cwd b pull ../a | "$PYTHON" $TESTTMP/filter.py
+  $ hg --traceback --cwd b pull ../a | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   pulling from ../a
   searching for changes
   adding changesets
@@ -421,6 +428,7 @@
   $ hg --cwd a --encoding utf-8 commit -A -d '0 0' \
   >   -m `"$PYTHON" -c 'import sys; getattr(sys.stdout, "buffer", sys.stdout).write(b"\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4")'`
   $ hg --traceback --cwd b --encoding utf-8 pull ../a | \
+  >   "$PYTHON" $TESTDIR/unwrap-message-id.py | \
   >   "$PYTHON" $TESTTMP/filter.py
   pulling from ../a
   searching for changes
@@ -475,7 +483,7 @@
   new changesets a846b5f6ebb7
   notify: sending 2 subscribers 1 changes
   (run 'hg update' to get a working copy)
-  $ "$PYTHON" $TESTTMP/filter.py < b/mbox
+  $ cat b/mbox | "$PYTHON" $TESTDIR/unwrap-message-id.py | "$PYTHON" $TESTTMP/filter.py
   From test@test.com ... ... .. ..:..:.. .... (re)
   MIME-Version: 1.0
   Content-Type: text/plain; charset="*" (glob)
@@ -535,7 +543,9 @@
   (branches are permanent and global, did you want a bookmark?)
   $ echo a >> a/a
   $ hg --cwd a ci -m test -d '1 0'
-  $ hg --traceback --cwd b pull ../a | "$PYTHON" $TESTTMP/filter.py
+  $ hg --traceback --cwd b pull ../a | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   pulling from ../a
   searching for changes
   adding changesets
@@ -565,7 +575,9 @@
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ echo a >> a/a
   $ hg --cwd a ci -m test -d '1 0'
-  $ hg --traceback --cwd b pull ../a | "$PYTHON" $TESTTMP/filter.py
+  $ hg --traceback --cwd b pull ../a | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   pulling from ../a
   searching for changes
   adding changesets
@@ -594,7 +606,9 @@
   $ mv "$HGRCPATH.new" $HGRCPATH
   $ echo a >> a/a
   $ hg --cwd a commit -m 'default template'
-  $ hg --cwd b pull ../a -q | "$PYTHON" $TESTTMP/filter.py
+  $ hg --cwd b pull ../a -q | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
@@ -623,7 +637,9 @@
   > EOF
   $ echo a >> a/a
   $ hg --cwd a commit -m 'with style'
-  $ hg --cwd b pull ../a -q | "$PYTHON" $TESTTMP/filter.py
+  $ hg --cwd b pull ../a -q | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
@@ -646,7 +662,9 @@
   > EOF
   $ echo a >> a/a
   $ hg --cwd a commit -m 'with template'
-  $ hg --cwd b pull ../a -q | "$PYTHON" $TESTTMP/filter.py
+  $ hg --cwd b pull ../a -q | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py | \
+  >  "$PYTHON" $TESTTMP/filter.py
   MIME-Version: 1.0
   Content-Type: text/plain; charset="us-ascii"
   Content-Transfer-Encoding: 7bit
@@ -677,7 +695,8 @@
   > EOF
   $ hg commit -Am addfunction
   adding f1
-  $ hg --cwd ../b pull ../a
+  $ hg --cwd ../b pull ../a | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py
   pulling from ../a
   searching for changes
   adding changesets
@@ -720,7 +739,8 @@
   > }
   > EOF
   $ hg commit -m changefunction
-  $ hg --cwd ../b --config notify.showfunc=True pull ../a
+  $ hg --cwd ../b --config notify.showfunc=True pull ../a | \
+  >  "$PYTHON" $TESTDIR/unwrap-message-id.py
   pulling from ../a
   searching for changes
   adding changesets
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/unwrap-message-id.py	Sun Oct 27 18:12:24 2019 +0100
@@ -0,0 +1,6 @@
+from __future__ import absolute_import, print_function
+
+import re
+import sys
+
+print(re.sub(r"(?<=Message-Id:) \n ", " ", sys.stdin.read()), end="")