##// END OF EJS Templates
py3: replace file() with open() in test-encoding.t...
Pulkit Goyal -
r36068:035af48b default
parent child Browse files
Show More
@@ -1,286 +1,286
1 Test character encoding
1 Test character encoding
2
2
3 $ hg init t
3 $ hg init t
4 $ cd t
4 $ cd t
5
5
6 we need a repo with some legacy latin-1 changesets
6 we need a repo with some legacy latin-1 changesets
7
7
8 $ hg unbundle "$TESTDIR/bundles/legacy-encoding.hg"
8 $ hg unbundle "$TESTDIR/bundles/legacy-encoding.hg"
9 adding changesets
9 adding changesets
10 adding manifests
10 adding manifests
11 adding file changes
11 adding file changes
12 added 2 changesets with 2 changes to 1 files
12 added 2 changesets with 2 changes to 1 files
13 new changesets 1e78a93102a3:0e5b7e3f9c4a
13 new changesets 1e78a93102a3:0e5b7e3f9c4a
14 (run 'hg update' to get a working copy)
14 (run 'hg update' to get a working copy)
15 $ hg co
15 $ hg co
16 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
16 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
17 $ $PYTHON << EOF
17 $ $PYTHON << EOF
18 > f = file('latin-1', 'w'); f.write("latin-1 e' encoded: \xe9"); f.close()
18 > f = open('latin-1', 'wb'); f.write(b"latin-1 e' encoded: \xe9"); f.close()
19 > f = file('utf-8', 'w'); f.write("utf-8 e' encoded: \xc3\xa9"); f.close()
19 > f = open('utf-8', 'wb'); f.write(b"utf-8 e' encoded: \xc3\xa9"); f.close()
20 > f = file('latin-1-tag', 'w'); f.write("\xe9"); f.close()
20 > f = open('latin-1-tag', 'wb'); f.write(b"\xe9"); f.close()
21 > EOF
21 > EOF
22
22
23 should fail with encoding error
23 should fail with encoding error
24
24
25 $ echo "plain old ascii" > a
25 $ echo "plain old ascii" > a
26 $ hg st
26 $ hg st
27 M a
27 M a
28 ? latin-1
28 ? latin-1
29 ? latin-1-tag
29 ? latin-1-tag
30 ? utf-8
30 ? utf-8
31 $ HGENCODING=ascii hg ci -l latin-1
31 $ HGENCODING=ascii hg ci -l latin-1
32 transaction abort!
32 transaction abort!
33 rollback completed
33 rollback completed
34 abort: decoding near ' encoded: \xe9': 'ascii' codec can't decode byte 0xe9 in position 20: ordinal not in range(128)! (esc)
34 abort: decoding near ' encoded: \xe9': 'ascii' codec can't decode byte 0xe9 in position 20: ordinal not in range(128)! (esc)
35 [255]
35 [255]
36
36
37 these should work
37 these should work
38
38
39 $ echo "latin-1" > a
39 $ echo "latin-1" > a
40 $ HGENCODING=latin-1 hg ci -l latin-1
40 $ HGENCODING=latin-1 hg ci -l latin-1
41 $ echo "utf-8" > a
41 $ echo "utf-8" > a
42 $ HGENCODING=utf-8 hg ci -l utf-8
42 $ HGENCODING=utf-8 hg ci -l utf-8
43 $ HGENCODING=latin-1 hg tag `cat latin-1-tag`
43 $ HGENCODING=latin-1 hg tag `cat latin-1-tag`
44 $ HGENCODING=latin-1 hg branch `cat latin-1-tag`
44 $ HGENCODING=latin-1 hg branch `cat latin-1-tag`
45 marked working directory as branch \xe9 (esc)
45 marked working directory as branch \xe9 (esc)
46 (branches are permanent and global, did you want a bookmark?)
46 (branches are permanent and global, did you want a bookmark?)
47 $ HGENCODING=latin-1 hg ci -m 'latin1 branch'
47 $ HGENCODING=latin-1 hg ci -m 'latin1 branch'
48 $ hg -q rollback
48 $ hg -q rollback
49 $ HGENCODING=latin-1 hg branch
49 $ HGENCODING=latin-1 hg branch
50 \xe9 (esc)
50 \xe9 (esc)
51 $ HGENCODING=latin-1 hg ci -m 'latin1 branch'
51 $ HGENCODING=latin-1 hg ci -m 'latin1 branch'
52 $ rm .hg/branch
52 $ rm .hg/branch
53
53
54 hg log (ascii)
54 hg log (ascii)
55
55
56 $ hg --encoding ascii log
56 $ hg --encoding ascii log
57 changeset: 5:a52c0692f24a
57 changeset: 5:a52c0692f24a
58 branch: ?
58 branch: ?
59 tag: tip
59 tag: tip
60 user: test
60 user: test
61 date: Thu Jan 01 00:00:00 1970 +0000
61 date: Thu Jan 01 00:00:00 1970 +0000
62 summary: latin1 branch
62 summary: latin1 branch
63
63
64 changeset: 4:94db611b4196
64 changeset: 4:94db611b4196
65 user: test
65 user: test
66 date: Thu Jan 01 00:00:00 1970 +0000
66 date: Thu Jan 01 00:00:00 1970 +0000
67 summary: Added tag ? for changeset ca661e7520de
67 summary: Added tag ? for changeset ca661e7520de
68
68
69 changeset: 3:ca661e7520de
69 changeset: 3:ca661e7520de
70 tag: ?
70 tag: ?
71 user: test
71 user: test
72 date: Thu Jan 01 00:00:00 1970 +0000
72 date: Thu Jan 01 00:00:00 1970 +0000
73 summary: utf-8 e' encoded: ?
73 summary: utf-8 e' encoded: ?
74
74
75 changeset: 2:650c6f3d55dd
75 changeset: 2:650c6f3d55dd
76 user: test
76 user: test
77 date: Thu Jan 01 00:00:00 1970 +0000
77 date: Thu Jan 01 00:00:00 1970 +0000
78 summary: latin-1 e' encoded: ?
78 summary: latin-1 e' encoded: ?
79
79
80 changeset: 1:0e5b7e3f9c4a
80 changeset: 1:0e5b7e3f9c4a
81 user: test
81 user: test
82 date: Mon Jan 12 13:46:40 1970 +0000
82 date: Mon Jan 12 13:46:40 1970 +0000
83 summary: koi8-r: ????? = u'\u0440\u0442\u0443\u0442\u044c'
83 summary: koi8-r: ????? = u'\u0440\u0442\u0443\u0442\u044c'
84
84
85 changeset: 0:1e78a93102a3
85 changeset: 0:1e78a93102a3
86 user: test
86 user: test
87 date: Mon Jan 12 13:46:40 1970 +0000
87 date: Mon Jan 12 13:46:40 1970 +0000
88 summary: latin-1 e': ? = u'\xe9'
88 summary: latin-1 e': ? = u'\xe9'
89
89
90
90
91 hg log (latin-1)
91 hg log (latin-1)
92
92
93 $ hg --encoding latin-1 log
93 $ hg --encoding latin-1 log
94 changeset: 5:a52c0692f24a
94 changeset: 5:a52c0692f24a
95 branch: \xe9 (esc)
95 branch: \xe9 (esc)
96 tag: tip
96 tag: tip
97 user: test
97 user: test
98 date: Thu Jan 01 00:00:00 1970 +0000
98 date: Thu Jan 01 00:00:00 1970 +0000
99 summary: latin1 branch
99 summary: latin1 branch
100
100
101 changeset: 4:94db611b4196
101 changeset: 4:94db611b4196
102 user: test
102 user: test
103 date: Thu Jan 01 00:00:00 1970 +0000
103 date: Thu Jan 01 00:00:00 1970 +0000
104 summary: Added tag \xe9 for changeset ca661e7520de (esc)
104 summary: Added tag \xe9 for changeset ca661e7520de (esc)
105
105
106 changeset: 3:ca661e7520de
106 changeset: 3:ca661e7520de
107 tag: \xe9 (esc)
107 tag: \xe9 (esc)
108 user: test
108 user: test
109 date: Thu Jan 01 00:00:00 1970 +0000
109 date: Thu Jan 01 00:00:00 1970 +0000
110 summary: utf-8 e' encoded: \xe9 (esc)
110 summary: utf-8 e' encoded: \xe9 (esc)
111
111
112 changeset: 2:650c6f3d55dd
112 changeset: 2:650c6f3d55dd
113 user: test
113 user: test
114 date: Thu Jan 01 00:00:00 1970 +0000
114 date: Thu Jan 01 00:00:00 1970 +0000
115 summary: latin-1 e' encoded: \xe9 (esc)
115 summary: latin-1 e' encoded: \xe9 (esc)
116
116
117 changeset: 1:0e5b7e3f9c4a
117 changeset: 1:0e5b7e3f9c4a
118 user: test
118 user: test
119 date: Mon Jan 12 13:46:40 1970 +0000
119 date: Mon Jan 12 13:46:40 1970 +0000
120 summary: koi8-r: \xd2\xd4\xd5\xd4\xd8 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
120 summary: koi8-r: \xd2\xd4\xd5\xd4\xd8 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
121
121
122 changeset: 0:1e78a93102a3
122 changeset: 0:1e78a93102a3
123 user: test
123 user: test
124 date: Mon Jan 12 13:46:40 1970 +0000
124 date: Mon Jan 12 13:46:40 1970 +0000
125 summary: latin-1 e': \xe9 = u'\\xe9' (esc)
125 summary: latin-1 e': \xe9 = u'\\xe9' (esc)
126
126
127
127
128 hg log (utf-8)
128 hg log (utf-8)
129
129
130 $ hg --encoding utf-8 log
130 $ hg --encoding utf-8 log
131 changeset: 5:a52c0692f24a
131 changeset: 5:a52c0692f24a
132 branch: \xc3\xa9 (esc)
132 branch: \xc3\xa9 (esc)
133 tag: tip
133 tag: tip
134 user: test
134 user: test
135 date: Thu Jan 01 00:00:00 1970 +0000
135 date: Thu Jan 01 00:00:00 1970 +0000
136 summary: latin1 branch
136 summary: latin1 branch
137
137
138 changeset: 4:94db611b4196
138 changeset: 4:94db611b4196
139 user: test
139 user: test
140 date: Thu Jan 01 00:00:00 1970 +0000
140 date: Thu Jan 01 00:00:00 1970 +0000
141 summary: Added tag \xc3\xa9 for changeset ca661e7520de (esc)
141 summary: Added tag \xc3\xa9 for changeset ca661e7520de (esc)
142
142
143 changeset: 3:ca661e7520de
143 changeset: 3:ca661e7520de
144 tag: \xc3\xa9 (esc)
144 tag: \xc3\xa9 (esc)
145 user: test
145 user: test
146 date: Thu Jan 01 00:00:00 1970 +0000
146 date: Thu Jan 01 00:00:00 1970 +0000
147 summary: utf-8 e' encoded: \xc3\xa9 (esc)
147 summary: utf-8 e' encoded: \xc3\xa9 (esc)
148
148
149 changeset: 2:650c6f3d55dd
149 changeset: 2:650c6f3d55dd
150 user: test
150 user: test
151 date: Thu Jan 01 00:00:00 1970 +0000
151 date: Thu Jan 01 00:00:00 1970 +0000
152 summary: latin-1 e' encoded: \xc3\xa9 (esc)
152 summary: latin-1 e' encoded: \xc3\xa9 (esc)
153
153
154 changeset: 1:0e5b7e3f9c4a
154 changeset: 1:0e5b7e3f9c4a
155 user: test
155 user: test
156 date: Mon Jan 12 13:46:40 1970 +0000
156 date: Mon Jan 12 13:46:40 1970 +0000
157 summary: koi8-r: \xc3\x92\xc3\x94\xc3\x95\xc3\x94\xc3\x98 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
157 summary: koi8-r: \xc3\x92\xc3\x94\xc3\x95\xc3\x94\xc3\x98 = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
158
158
159 changeset: 0:1e78a93102a3
159 changeset: 0:1e78a93102a3
160 user: test
160 user: test
161 date: Mon Jan 12 13:46:40 1970 +0000
161 date: Mon Jan 12 13:46:40 1970 +0000
162 summary: latin-1 e': \xc3\xa9 = u'\\xe9' (esc)
162 summary: latin-1 e': \xc3\xa9 = u'\\xe9' (esc)
163
163
164
164
165 hg tags (ascii)
165 hg tags (ascii)
166
166
167 $ HGENCODING=ascii hg tags
167 $ HGENCODING=ascii hg tags
168 tip 5:a52c0692f24a
168 tip 5:a52c0692f24a
169 ? 3:ca661e7520de
169 ? 3:ca661e7520de
170
170
171 hg tags (latin-1)
171 hg tags (latin-1)
172
172
173 $ HGENCODING=latin-1 hg tags
173 $ HGENCODING=latin-1 hg tags
174 tip 5:a52c0692f24a
174 tip 5:a52c0692f24a
175 \xe9 3:ca661e7520de (esc)
175 \xe9 3:ca661e7520de (esc)
176
176
177 hg tags (utf-8)
177 hg tags (utf-8)
178
178
179 $ HGENCODING=utf-8 hg tags
179 $ HGENCODING=utf-8 hg tags
180 tip 5:a52c0692f24a
180 tip 5:a52c0692f24a
181 \xc3\xa9 3:ca661e7520de (esc)
181 \xc3\xa9 3:ca661e7520de (esc)
182
182
183 hg tags (JSON)
183 hg tags (JSON)
184
184
185 $ hg tags -Tjson
185 $ hg tags -Tjson
186 [
186 [
187 {
187 {
188 "node": "a52c0692f24ad921c0a31e1736e7635a8b23b670",
188 "node": "a52c0692f24ad921c0a31e1736e7635a8b23b670",
189 "rev": 5,
189 "rev": 5,
190 "tag": "tip",
190 "tag": "tip",
191 "type": ""
191 "type": ""
192 },
192 },
193 {
193 {
194 "node": "ca661e7520dec3f5438a63590c350bebadb04989",
194 "node": "ca661e7520dec3f5438a63590c350bebadb04989",
195 "rev": 3,
195 "rev": 3,
196 "tag": "\xc3\xa9", (esc)
196 "tag": "\xc3\xa9", (esc)
197 "type": ""
197 "type": ""
198 }
198 }
199 ]
199 ]
200
200
201 hg branches (ascii)
201 hg branches (ascii)
202
202
203 $ HGENCODING=ascii hg branches
203 $ HGENCODING=ascii hg branches
204 ? 5:a52c0692f24a
204 ? 5:a52c0692f24a
205 default 4:94db611b4196 (inactive)
205 default 4:94db611b4196 (inactive)
206
206
207 hg branches (latin-1)
207 hg branches (latin-1)
208
208
209 $ HGENCODING=latin-1 hg branches
209 $ HGENCODING=latin-1 hg branches
210 \xe9 5:a52c0692f24a (esc)
210 \xe9 5:a52c0692f24a (esc)
211 default 4:94db611b4196 (inactive)
211 default 4:94db611b4196 (inactive)
212
212
213 hg branches (utf-8)
213 hg branches (utf-8)
214
214
215 $ HGENCODING=utf-8 hg branches
215 $ HGENCODING=utf-8 hg branches
216 \xc3\xa9 5:a52c0692f24a (esc)
216 \xc3\xa9 5:a52c0692f24a (esc)
217 default 4:94db611b4196 (inactive)
217 default 4:94db611b4196 (inactive)
218 $ echo '[ui]' >> .hg/hgrc
218 $ echo '[ui]' >> .hg/hgrc
219 $ echo 'fallbackencoding = koi8-r' >> .hg/hgrc
219 $ echo 'fallbackencoding = koi8-r' >> .hg/hgrc
220
220
221 hg log (utf-8)
221 hg log (utf-8)
222
222
223 $ HGENCODING=utf-8 hg log
223 $ HGENCODING=utf-8 hg log
224 changeset: 5:a52c0692f24a
224 changeset: 5:a52c0692f24a
225 branch: \xc3\xa9 (esc)
225 branch: \xc3\xa9 (esc)
226 tag: tip
226 tag: tip
227 user: test
227 user: test
228 date: Thu Jan 01 00:00:00 1970 +0000
228 date: Thu Jan 01 00:00:00 1970 +0000
229 summary: latin1 branch
229 summary: latin1 branch
230
230
231 changeset: 4:94db611b4196
231 changeset: 4:94db611b4196
232 user: test
232 user: test
233 date: Thu Jan 01 00:00:00 1970 +0000
233 date: Thu Jan 01 00:00:00 1970 +0000
234 summary: Added tag \xc3\xa9 for changeset ca661e7520de (esc)
234 summary: Added tag \xc3\xa9 for changeset ca661e7520de (esc)
235
235
236 changeset: 3:ca661e7520de
236 changeset: 3:ca661e7520de
237 tag: \xc3\xa9 (esc)
237 tag: \xc3\xa9 (esc)
238 user: test
238 user: test
239 date: Thu Jan 01 00:00:00 1970 +0000
239 date: Thu Jan 01 00:00:00 1970 +0000
240 summary: utf-8 e' encoded: \xc3\xa9 (esc)
240 summary: utf-8 e' encoded: \xc3\xa9 (esc)
241
241
242 changeset: 2:650c6f3d55dd
242 changeset: 2:650c6f3d55dd
243 user: test
243 user: test
244 date: Thu Jan 01 00:00:00 1970 +0000
244 date: Thu Jan 01 00:00:00 1970 +0000
245 summary: latin-1 e' encoded: \xc3\xa9 (esc)
245 summary: latin-1 e' encoded: \xc3\xa9 (esc)
246
246
247 changeset: 1:0e5b7e3f9c4a
247 changeset: 1:0e5b7e3f9c4a
248 user: test
248 user: test
249 date: Mon Jan 12 13:46:40 1970 +0000
249 date: Mon Jan 12 13:46:40 1970 +0000
250 summary: koi8-r: \xd1\x80\xd1\x82\xd1\x83\xd1\x82\xd1\x8c = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
250 summary: koi8-r: \xd1\x80\xd1\x82\xd1\x83\xd1\x82\xd1\x8c = u'\\u0440\\u0442\\u0443\\u0442\\u044c' (esc)
251
251
252 changeset: 0:1e78a93102a3
252 changeset: 0:1e78a93102a3
253 user: test
253 user: test
254 date: Mon Jan 12 13:46:40 1970 +0000
254 date: Mon Jan 12 13:46:40 1970 +0000
255 summary: latin-1 e': \xd0\x98 = u'\\xe9' (esc)
255 summary: latin-1 e': \xd0\x98 = u'\\xe9' (esc)
256
256
257
257
258 hg log (dolphin)
258 hg log (dolphin)
259
259
260 $ HGENCODING=dolphin hg log
260 $ HGENCODING=dolphin hg log
261 abort: unknown encoding: dolphin
261 abort: unknown encoding: dolphin
262 (please check your locale settings)
262 (please check your locale settings)
263 [255]
263 [255]
264 $ HGENCODING=ascii hg branch `cat latin-1-tag`
264 $ HGENCODING=ascii hg branch `cat latin-1-tag`
265 abort: decoding near '\xe9': 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)! (esc)
265 abort: decoding near '\xe9': 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)! (esc)
266 [255]
266 [255]
267 $ cp latin-1-tag .hg/branch
267 $ cp latin-1-tag .hg/branch
268 $ HGENCODING=latin-1 hg ci -m 'auto-promote legacy name'
268 $ HGENCODING=latin-1 hg ci -m 'auto-promote legacy name'
269
269
270 Test roundtrip encoding of lookup tables when not using UTF-8 (issue2763)
270 Test roundtrip encoding of lookup tables when not using UTF-8 (issue2763)
271
271
272 $ HGENCODING=latin-1 hg up `cat latin-1-tag`
272 $ HGENCODING=latin-1 hg up `cat latin-1-tag`
273 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
273 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
274
274
275 $ cd ..
275 $ cd ..
276
276
277 Test roundtrip encoding/decoding of utf8b for generated data
277 Test roundtrip encoding/decoding of utf8b for generated data
278
278
279 #if hypothesis
279 #if hypothesis
280
280
281 >>> from hypothesishelpers import *
281 >>> from hypothesishelpers import *
282 >>> from mercurial import encoding
282 >>> from mercurial import encoding
283 >>> roundtrips(st.binary(), encoding.fromutf8b, encoding.toutf8b)
283 >>> roundtrips(st.binary(), encoding.fromutf8b, encoding.toutf8b)
284 Round trip OK
284 Round trip OK
285
285
286 #endif
286 #endif
General Comments 0
You need to be logged in to leave comments. Login now