Merge lp:~jelmer/brz/some-more into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/some-more
Merge into: lp:brz
Diff against target: 282 lines (+83/-44)
6 files modified
breezy/cache_utf8.py (+3/-2)
breezy/commands.py (+1/-1)
breezy/tests/blackbox/test_exceptions.py (+6/-3)
breezy/tests/test_urlutils.py (+6/-5)
breezy/urlutils.py (+48/-33)
python3.passing (+19/-0)
To merge this branch: bzr merge lp:~jelmer/brz/some-more
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+353541@code.launchpad.net

Commit message

Fix a couple more tests on Python 3.

Description of the change

Fix a couple more UI-y tests on Python 3.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

I think I'd looked at some of these changes before, all seems reasonable to me. There's messiness but it's not new messiness.

review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/cache_utf8.py'
2--- breezy/cache_utf8.py 2018-08-13 01:38:21 +0000
3+++ breezy/cache_utf8.py 2018-09-11 03:12:36 +0000
4@@ -108,8 +108,9 @@
5 # real Unicode string. Unicode and plain strings of this type will have the
6 # same hash, so we can just use it as the key in _uni_to_utf8, but we need
7 # the return value to be different in _utf8_to_uni
8- ascii_str = _uni_to_utf8.setdefault(ascii_str, ascii_str)
9- _utf8_to_uni.setdefault(ascii_str, ascii_str.decode('ascii'))
10+ uni_str = ascii_str.decode('ascii')
11+ ascii_str = _uni_to_utf8.setdefault(uni_str, ascii_str)
12+ _utf8_to_uni.setdefault(ascii_str, uni_str)
13 return ascii_str
14
15
16
17=== modified file 'breezy/commands.py'
18--- breezy/commands.py 2018-07-26 01:01:49 +0000
19+++ breezy/commands.py 2018-09-11 03:12:36 +0000
20@@ -901,7 +901,7 @@
21 else:
22 args = argv
23
24- # for python 2.5 and later, optparse raises this exception if a non-ascii
25+ # python 2's optparse raises this exception if a non-ascii
26 # option name is given. See http://bugs.python.org/issue2931
27 try:
28 options, args = parser.parse_args(args)
29
30=== modified file 'breezy/tests/blackbox/test_exceptions.py'
31--- breezy/tests/blackbox/test_exceptions.py 2018-08-26 11:21:16 +0000
32+++ breezy/tests/blackbox/test_exceptions.py 2018-09-11 03:12:36 +0000
33@@ -54,7 +54,7 @@
34 raise tests.TestNotApplicable("Needs system beholden to C locales")
35 if PY3:
36 raise tests.TestNotApplicable("Unable to pass argv to subprocess as bytes")
37- out, err = self.run_bzr_subprocess(["\xa0"],
38+ out, err = self.run_bzr_subprocess([b"\xa0"],
39 env_changes={"LANG": "C", "LC_ALL": "C"},
40 universal_newlines=True,
41 retcode=errors.EXIT_ERROR)
42@@ -75,8 +75,11 @@
43 "Test that we handle http://bugs.python.org/issue2931"
44
45 def test_nonascii_optparse(self):
46- """Reasonable error raised when non-ascii in option name"""
47- error_re = 'Only ASCII permitted in option names'
48+ """Reasonable error raised when non-ascii in option name on Python 2"""
49+ if PY3:
50+ error_re = u'no such option: -\xe4'
51+ else:
52+ error_re = 'Only ASCII permitted in option names'
53 out = self.run_bzr_error([error_re], ['st', u'-\xe4'])
54
55
56
57=== modified file 'breezy/tests/test_urlutils.py'
58--- breezy/tests/test_urlutils.py 2018-08-05 22:33:53 +0000
59+++ breezy/tests/test_urlutils.py 2018-09-11 03:12:36 +0000
60@@ -126,11 +126,12 @@
61 eq('http://host/~bob%2525-._',
62 normalize_url(u'http://host/%7Ebob%2525%2D%2E%5F'))
63
64- # Normalize verifies URLs when they are not unicode
65- # (indicating they did not come from the user)
66- self.assertRaises(urlutils.InvalidURL, normalize_url,
67- 'http://host/\xb5')
68- self.assertRaises(urlutils.InvalidURL, normalize_url, 'http://host/ ')
69+ if not PY3:
70+ # On Python 2, normalize verifies URLs when they are not unicode
71+ # (indicating they did not come from the user)
72+ self.assertRaises(urlutils.InvalidURL, normalize_url,
73+ b'http://host/\xb5')
74+ self.assertRaises(urlutils.InvalidURL, normalize_url, b'http://host/ ')
75
76 def test_url_scheme_re(self):
77 # Test paths that may be URLs
78
79=== modified file 'breezy/urlutils.py'
80--- breezy/urlutils.py 2018-08-19 12:24:17 +0000
81+++ breezy/urlutils.py 2018-09-11 03:12:36 +0000
82@@ -38,6 +38,7 @@
83 """)
84
85 from .sixish import (
86+ int2byte,
87 PY3,
88 text_type,
89 )
90@@ -700,10 +701,10 @@
91 _no_decode_ords = [ord(c) for c in _no_decode_chars]
92 _no_decode_hex = (['%02x' % o for o in _no_decode_ords]
93 + ['%02X' % o for o in _no_decode_ords])
94-_hex_display_map = dict(([('%02x' % o, chr(o)) for o in range(256)]
95- + [('%02X' % o, chr(o)) for o in range(256)]))
96+_hex_display_map = dict(([('%02x' % o, int2byte(o)) for o in range(256)]
97+ + [('%02X' % o, int2byte(o)) for o in range(256)]))
98 #These entries get mapped to themselves
99-_hex_display_map.update((hex, '%'+hex) for hex in _no_decode_hex)
100+_hex_display_map.update((hex, b'%'+hex.encode('ascii')) for hex in _no_decode_hex)
101
102 # These characters shouldn't be percent-encoded, and it's always safe to
103 # unencode them if they are.
104@@ -724,6 +725,49 @@
105 "%#" # Extra reserved characters
106 )
107
108+
109+def _unescape_segment_for_display(segment, encoding):
110+ """Unescape a segment for display.
111+
112+ Helper for unescape_for_display
113+
114+ :param url: A 7-bit ASCII URL
115+ :param encoding: The final output encoding
116+
117+ :return: A unicode string which can be safely encoded into the
118+ specified encoding.
119+ """
120+ escaped_chunks = segment.split('%')
121+ escaped_chunks[0] = escaped_chunks[0].encode('utf-8')
122+ for j in range(1, len(escaped_chunks)):
123+ item = escaped_chunks[j]
124+ try:
125+ escaped_chunks[j] = _hex_display_map[item[:2]]
126+ except KeyError:
127+ # Put back the percent symbol
128+ escaped_chunks[j] = b'%' + (item[:2].encode('utf-8') if PY3 else item[:2])
129+ except UnicodeDecodeError:
130+ escaped_chunks[j] = unichr(int(item[:2], 16)).encode('utf-8')
131+ escaped_chunks[j] += (item[2:].encode('utf-8') if PY3 else item[2:])
132+ unescaped = b''.join(escaped_chunks)
133+ try:
134+ decoded = unescaped.decode('utf-8')
135+ except UnicodeDecodeError:
136+ # If this path segment cannot be properly utf-8 decoded
137+ # after doing unescaping we will just leave it alone
138+ return segment
139+ else:
140+ try:
141+ decoded.encode(encoding)
142+ except UnicodeEncodeError:
143+ # If this chunk cannot be encoded in the local
144+ # encoding, then we should leave it alone
145+ return segment
146+ else:
147+ # Otherwise take the url decoded one
148+ return decoded
149+
150+
151 def unescape_for_display(url, encoding):
152 """Decode what you can for a URL, so that we get a nice looking path.
153
154@@ -752,36 +796,7 @@
155 # Split into sections to try to decode utf-8
156 res = url.split('/')
157 for i in range(1, len(res)):
158- escaped_chunks = res[i].split('%')
159- for j in range(1, len(escaped_chunks)):
160- item = escaped_chunks[j]
161- try:
162- escaped_chunks[j] = _hex_display_map[item[:2]] + item[2:]
163- except KeyError:
164- # Put back the percent symbol
165- escaped_chunks[j] = '%' + item
166- except UnicodeDecodeError:
167- escaped_chunks[j] = unichr(int(item[:2], 16)) + item[2:]
168- unescaped = ''.join(escaped_chunks)
169- if sys.version_info[0] == 2:
170- try:
171- decoded = unescaped.decode('utf-8')
172- except UnicodeDecodeError:
173- # If this path segment cannot be properly utf-8 decoded
174- # after doing unescaping we will just leave it alone
175- pass
176- else:
177- try:
178- decoded.encode(encoding)
179- except UnicodeEncodeError:
180- # If this chunk cannot be encoded in the local
181- # encoding, then we should leave it alone
182- pass
183- else:
184- # Otherwise take the url decoded one
185- res[i] = decoded
186- else:
187- res[i] = unescaped
188+ res[i] = _unescape_segment_for_display(res[i], encoding)
189 return u'/'.join(res)
190
191
192
193=== modified file 'python3.passing'
194--- python3.passing 2018-09-11 02:50:43 +0000
195+++ python3.passing 2018-09-11 03:12:36 +0000
196@@ -2013,6 +2013,7 @@
197 breezy.tests.blackbox.test_exceptions.TestExceptionReporting.test_exception_exitcode
198 breezy.tests.blackbox.test_exceptions.TestExceptionReporting.test_undecodable_argv
199 breezy.tests.blackbox.test_exceptions.TestExceptionReporting.test_utf8_default_fs_enc
200+breezy.tests.blackbox.test_exceptions.TestOptParseBugHandling.test_nonascii_optparse
201 breezy.tests.blackbox.test_export_pot.TestExportPot.test_export_pot
202 breezy.tests.blackbox.test_export_pot.TestExportPot.test_export_pot_plugin
203 breezy.tests.blackbox.test_export_pot.TestExportPot.test_export_pot_plugin_unknown
204@@ -8485,7 +8486,9 @@
205 breezy.tests.per_intertree.test_compare.TestCompare.test_content_modification(InterTree(PreviewTree))
206 breezy.tests.per_intertree.test_compare.TestCompare.test_dangling(InterDirStateTree(C))
207 breezy.tests.per_intertree.test_compare.TestCompare.test_dangling(InterDirStateTree(PY))
208+breezy.tests.per_intertree.test_compare.TestCompare.test_dangling(InterTree)
209 breezy.tests.per_intertree.test_compare.TestCompare.test_dangling(InterTree(CHKInventory))
210+breezy.tests.per_intertree.test_compare.TestCompare.test_dangling(InterTree(PreviewTree))
211 breezy.tests.per_intertree.test_compare.TestCompare.test_default_ignores_unversioned_files(InterDirStateTree(C))
212 breezy.tests.per_intertree.test_compare.TestCompare.test_default_ignores_unversioned_files(InterDirStateTree(PY))
213 breezy.tests.per_intertree.test_compare.TestCompare.test_default_ignores_unversioned_files(InterTree)
214@@ -8597,7 +8600,10 @@
215 breezy.tests.per_intertree.test_compare.TestIterChanges.test_default_ignores_unversioned_files(InterTree(CHKInventory))
216 breezy.tests.per_intertree.test_compare.TestIterChanges.test_default_ignores_unversioned_files(InterTree(PreviewTree))
217 breezy.tests.per_intertree.test_compare.TestIterChanges.test_deleted_and_unknown(InterDirStateTree(C))
218+breezy.tests.per_intertree.test_compare.TestIterChanges.test_deleted_and_unknown(InterDirStateTree(PY))
219+breezy.tests.per_intertree.test_compare.TestIterChanges.test_deleted_and_unknown(InterTree)
220 breezy.tests.per_intertree.test_compare.TestIterChanges.test_deleted_and_unknown(InterTree(CHKInventory))
221+breezy.tests.per_intertree.test_compare.TestIterChanges.test_deleted_and_unknown(InterTree(PreviewTree))
222 breezy.tests.per_intertree.test_compare.TestIterChanges.test_deleted_unicode(InterDirStateTree(C))
223 breezy.tests.per_intertree.test_compare.TestIterChanges.test_deleted_unicode(InterDirStateTree(PY))
224 breezy.tests.per_intertree.test_compare.TestIterChanges.test_deleted_unicode(InterTree)
225@@ -8699,7 +8705,10 @@
226 breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_and_added(InterTree(CHKInventory))
227 breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_and_added(InterTree(PreviewTree))
228 breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_and_unknown(InterDirStateTree(C))
229+breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_and_unknown(InterDirStateTree(PY))
230+breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_and_unknown(InterTree)
231 breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_and_unknown(InterTree(CHKInventory))
232+breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_and_unknown(InterTree(PreviewTree))
233 breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_unicode(InterDirStateTree(C))
234 breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_unicode(InterDirStateTree(PY))
235 breezy.tests.per_intertree.test_compare.TestIterChanges.test_renamed_unicode(InterTree)
236@@ -8796,7 +8805,10 @@
237 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unknown_unicode(InterTree(CHKInventory))
238 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unknown_unicode(InterTree(PreviewTree))
239 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_paths_in_target_matching_source_old_names(InterDirStateTree(C))
240+breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_paths_in_target_matching_source_old_names(InterDirStateTree(PY))
241+breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_paths_in_target_matching_source_old_names(InterTree)
242 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_paths_in_target_matching_source_old_names(InterTree(CHKInventory))
243+breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_paths_in_target_matching_source_old_names(InterTree(PreviewTree))
244 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_paths_in_tree(InterDirStateTree(C))
245 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_paths_in_tree(InterDirStateTree(PY))
246 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_paths_in_tree(InterTree)
247@@ -8813,7 +8825,10 @@
248 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_subtree_only_emits_root(InterTree(CHKInventory))
249 breezy.tests.per_intertree.test_compare.TestIterChanges.test_unversioned_subtree_only_emits_root(InterTree(PreviewTree))
250 breezy.tests.per_intertree.test_compare.TestIterChanges.test_versioned_symlinks(InterDirStateTree(C))
251+breezy.tests.per_intertree.test_compare.TestIterChanges.test_versioned_symlinks(InterDirStateTree(PY))
252+breezy.tests.per_intertree.test_compare.TestIterChanges.test_versioned_symlinks(InterTree)
253 breezy.tests.per_intertree.test_compare.TestIterChanges.test_versioned_symlinks(InterTree(CHKInventory))
254+breezy.tests.per_intertree.test_compare.TestIterChanges.test_versioned_symlinks(InterTree(PreviewTree))
255 breezy.tests.per_intertree.test_compare.TestIterChanges.test_versioned_symlinks_specific_files(InterDirStateTree(C))
256 breezy.tests.per_intertree.test_compare.TestIterChanges.test_versioned_symlinks_specific_files(InterDirStateTree(PY))
257 breezy.tests.per_intertree.test_compare.TestIterChanges.test_versioned_symlinks_specific_files(InterTree)
258@@ -16291,6 +16306,8 @@
259 breezy.tests.per_transport.TransportTests.test_connection_error(ChrootTransport,TestingChrootServer)
260 breezy.tests.per_transport.TransportTests.test_connection_error(FakeNFSTransportDecorator,FakeNFSServer)
261 breezy.tests.per_transport.TransportTests.test_connection_error(FakeVFATTransportDecorator,FakeVFATServer)
262+breezy.tests.per_transport.TransportTests.test_connection_error(HTTPS_transport,HTTPSServer)
263+breezy.tests.per_transport.TransportTests.test_connection_error(HttpTransport,HttpServer)
264 breezy.tests.per_transport.TransportTests.test_connection_error(LocalTransport,LocalURLServer)
265 breezy.tests.per_transport.TransportTests.test_connection_error(MemoryTransport,MemoryServer)
266 breezy.tests.per_transport.TransportTests.test_connection_error(NoSmartTransportDecorator,NoSmartTransportServer)
267@@ -30677,6 +30694,7 @@
268 breezy.tests.test_urlutils.TestUrlToPath.test_join_segment_parameters
269 breezy.tests.test_urlutils.TestUrlToPath.test_join_segment_parameters_raw
270 breezy.tests.test_urlutils.TestUrlToPath.test_normalize_url_files
271+breezy.tests.test_urlutils.TestUrlToPath.test_normalize_url_hybrid
272 breezy.tests.test_urlutils.TestUrlToPath.test_posix_local_path_from_url
273 breezy.tests.test_urlutils.TestUrlToPath.test_posix_local_path_to_url
274 breezy.tests.test_urlutils.TestUrlToPath.test_relative_url
275@@ -30685,6 +30703,7 @@
276 breezy.tests.test_urlutils.TestUrlToPath.test_split_segment_parameters_raw
277 breezy.tests.test_urlutils.TestUrlToPath.test_strip_trailing_slash
278 breezy.tests.test_urlutils.TestUrlToPath.test_unescape
279+breezy.tests.test_urlutils.TestUrlToPath.test_unescape_for_display_utf8
280 breezy.tests.test_urlutils.TestUrlToPath.test_url_scheme_re
281 breezy.tests.test_urlutils.TestUrlToPath.test_win32_extract_drive_letter
282 breezy.tests.test_urlutils.TestUrlToPath.test_win32_local_path_from_url

Subscribers

People subscribed via source and target branches