@@ -207,6 +207,9 @@ def test_roundtrips(self):
207207 ('scheme://///path/to/file' ,
208208 ('scheme' ,'' ,'///path/to/file' ,'' ,'' ,'' ),
209209 ('scheme' ,'' ,'///path/to/file' ,'' ,'' )),
210+ ('file:tmp/junk.txt' ,
211+ ('file' ,'' ,'tmp/junk.txt' ,'' ,'' ,'' ),
212+ ('file' ,'' ,'tmp/junk.txt' ,'' ,'' )),
210213 ('file:///tmp/junk.txt' ,
211214 ('file' ,'' ,'/tmp/junk.txt' ,'' ,'' ,'' ),
212215 ('file' ,'' ,'/tmp/junk.txt' ,'' ,'' )),
@@ -216,6 +219,18 @@ def test_roundtrips(self):
216219 ('file://///tmp/junk.txt' ,
217220 ('file' ,'' ,'///tmp/junk.txt' ,'' ,'' ,'' ),
218221 ('file' ,'' ,'///tmp/junk.txt' ,'' ,'' )),
222+ ('http:tmp/junk.txt' ,
223+ ('http' ,'' ,'tmp/junk.txt' ,'' ,'' ,'' ),
224+ ('http' ,'' ,'tmp/junk.txt' ,'' ,'' )),
225+ ('http://example.com/tmp/junk.txt' ,
226+ ('http' ,'example.com' ,'/tmp/junk.txt' ,'' ,'' ,'' ),
227+ ('http' ,'example.com' ,'/tmp/junk.txt' ,'' ,'' )),
228+ ('http:///example.com/tmp/junk.txt' ,
229+ ('http' ,'' ,'/example.com/tmp/junk.txt' ,'' ,'' ,'' ),
230+ ('http' ,'' ,'/example.com/tmp/junk.txt' ,'' ,'' )),
231+ ('http:////example.com/tmp/junk.txt' ,
232+ ('http' ,'' ,'//example.com/tmp/junk.txt' ,'' ,'' ,'' ),
233+ ('http' ,'' ,'//example.com/tmp/junk.txt' ,'' ,'' )),
219234 ('imap://mail.python.org/mbox1' ,
220235 ('imap' ,'mail.python.org' ,'/mbox1' ,'' ,'' ,'' ),
221236 ('imap' ,'mail.python.org' ,'/mbox1' ,'' ,'' )),
@@ -260,7 +275,8 @@ def _encode(t):
260275 ('' ,'' ,'schème:path/to/file' ,'' ,'' )),
261276 ]
262277for url ,parsed ,split in str_cases + bytes_cases :
263- self .checkRoundtrips (url ,parsed ,split )
278+ with self .subTest (url ):
279+ self .checkRoundtrips (url ,parsed ,split )
264280
265281def test_roundtrips_normalization (self ):
266282str_cases = [
@@ -292,7 +308,8 @@ def _encode(t):
292308tuple (x .encode ('ascii' )for x in t [3 ]))
293309bytes_cases = [_encode (x )for x in str_cases ]
294310for url ,url2 ,parsed ,split in str_cases + bytes_cases :
295- self .checkRoundtrips (url ,parsed ,split ,url2 )
311+ with self .subTest (url ):
312+ self .checkRoundtrips (url ,parsed ,split ,url2 )
296313
297314def test_http_roundtrips (self ):
298315# urllib.parse.urlsplit treats 'http:' as an optimized special case,
@@ -333,11 +350,17 @@ def _encode(t):
333350self .checkRoundtrips (url ,parsed ,split )
334351
335352def checkJoin (self ,base ,relurl ,expected ):
336- str_components = (base ,relurl ,expected )
337- self .assertEqual (urllib .parse .urljoin (base ,relurl ),expected )
338- bytes_components = baseb ,relurlb ,expectedb = [
339- x .encode ('ascii' )for x in str_components ]
340- self .assertEqual (urllib .parse .urljoin (baseb ,relurlb ),expectedb )
353+ with self .subTest (base = base ,relurl = relurl ):
354+ self .assertEqual (urllib .parse .urljoin (base ,relurl ),expected )
355+ baseb = base .encode ('ascii' )
356+ relurlb = relurl .encode ('ascii' )
357+ expectedb = expected .encode ('ascii' )
358+ self .assertEqual (urllib .parse .urljoin (baseb ,relurlb ),expectedb )
359+
360+ relurl = urllib .parse .urlunsplit (urllib .parse .urlsplit (relurl ))
361+ self .assertEqual (urllib .parse .urljoin (base ,relurl ),expected )
362+ relurlb = urllib .parse .urlunsplit (urllib .parse .urlsplit (relurlb ))
363+ self .assertEqual (urllib .parse .urljoin (baseb ,relurlb ),expectedb )
341364
342365def test_unparse_parse (self ):
343366str_cases = ['Python' ,'./Python' ,'x-newscheme://foo.com/stuff' ,'x://y' ,'x:/y' ,'x:/' ,'/' ,]