Mercurial > hg
comparison tests/test-mq-qimport.t @ 41328:13ccb03f2145
tests: handle string escaping/encoding on Python 3
This code was failing on Python 3 for a few reasons:
1) sys.argv is str and str doesn't have a .decode()
2) the "string_escape" encoding was renamed to "unicode_escape"
It is wonky casting to bytes to str to bytes. But this is test
code, so meh. I don't believe we exercise any code paths in these
tests where the arguments aren't ascii.
Differential Revision: https://phab.mercurial-scm.org/D5667
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 23 Jan 2019 17:41:46 -0800 |
parents | 5abc47d4ca6b |
children | c70bdd222dcd |
comparison
equal
deleted
inserted
replaced
41327:1281b2265ff5 | 41328:13ccb03f2145 |
---|---|
1 $ cat > writelines.py <<EOF | 1 $ cat > writelines.py <<EOF |
2 > import sys | 2 > import sys |
3 > if sys.version_info[0] >= 3: | |
4 > encode = lambda x: x.encode('utf-8').decode('unicode_escape').encode('utf-8') | |
5 > else: | |
6 > encode = lambda x: x.decode('string_escape') | |
3 > path = sys.argv[1] | 7 > path = sys.argv[1] |
4 > args = sys.argv[2:] | 8 > args = sys.argv[2:] |
5 > assert (len(args) % 2) == 0 | 9 > assert (len(args) % 2) == 0 |
6 > | 10 > |
7 > f = open(path, 'wb') | 11 > f = open(path, 'wb') |
8 > for i in range(len(args)//2): | 12 > for i in range(len(args)//2): |
9 > count, s = args[2*i:2*i+2] | 13 > count, s = args[2*i:2*i+2] |
10 > count = int(count) | 14 > count = int(count) |
11 > s = s.decode('string_escape') | 15 > s = encode(s) |
12 > f.write(s*count) | 16 > f.write(s*count) |
13 > f.close() | 17 > f.close() |
14 > | 18 > |
15 > EOF | 19 > EOF |
16 > cat <<EOF >> $HGRCPATH | 20 > cat <<EOF >> $HGRCPATH |