Patchwork D5667: tests: handle string escaping/encoding on Python 3

login
register
mail settings
Submitter phabricator
Date Jan. 24, 2019, 2:27 a.m.
Message ID <2c4adfc0e9935fac2af58c45f13632d0@localhost.localdomain>
Download mbox | patch
Permalink /patch/37949/
State Not Applicable
Headers show

Comments

phabricator - Jan. 24, 2019, 2:27 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG13ccb03f2145: tests: handle string escaping/encoding on Python 3 (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5667?vs=13379&id=13385

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

AFFECTED FILES
  tests/test-mq-missingfiles.t
  tests/test-mq-qimport.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-mq-qimport.t b/tests/test-mq-qimport.t
--- a/tests/test-mq-qimport.t
+++ b/tests/test-mq-qimport.t
@@ -1,14 +1,18 @@ 
   $ cat > writelines.py <<EOF
   > import sys
+  > if sys.version_info[0] >= 3:
+  >     encode = lambda x: x.encode('utf-8').decode('unicode_escape').encode('utf-8')
+  > else:
+  >     encode = lambda x: x.decode('string_escape')
   > path = sys.argv[1]
   > args = sys.argv[2:]
   > assert (len(args) % 2) == 0
   > 
   > f = open(path, 'wb')
   > for i in range(len(args)//2):
   >    count, s = args[2*i:2*i+2]
   >    count = int(count)
-  >    s = s.decode('string_escape')
+  >    s = encode(s)
   >    f.write(s*count)
   > f.close()
   > 
diff --git a/tests/test-mq-missingfiles.t b/tests/test-mq-missingfiles.t
--- a/tests/test-mq-missingfiles.t
+++ b/tests/test-mq-missingfiles.t
@@ -5,15 +5,19 @@ 
 
   $ cat > writelines.py <<EOF
   > import sys
+  > if sys.version_info[0] >= 3:
+  >     encode = lambda x: x.encode('utf-8').decode('unicode_escape').encode('utf-8')
+  > else:
+  >     encode = lambda x: x.decode('string_escape')
   > path = sys.argv[1]
   > args = sys.argv[2:]
   > assert (len(args) % 2) == 0
   > 
   > f = open(path, 'wb')
   > for i in range(len(args) // 2):
   >    count, s = args[2*i:2*i+2]
   >    count = int(count)
-  >    s = s.decode('string_escape')
+  >    s = encode(s)
   >    f.write(s*count)
   > f.close()
   > EOF