@@ -1255,7 +1255,14 @@ def test_mixed_types_rejected(self):
12551255 with self .assertRaisesRegex (TypeError , "Cannot mix str" ):
12561256 urllib .parse .urljoin (b"http://python.org" , "http://python.org" )
12571257
1258+ def test_non_string_true_values_rejected (self ):
1259+ # True values raise informative TypeErrors
1260+ msg = "Expected a string or bytes object: got <class "
1261+ with self .assertRaisesRegex (TypeError , msg ):
1262+ urllib .parse .urlsplit (1 , b'http' )
1263+
12581264 def _check_result_type (self , str_type , str_args ):
1265+ num_args = len (str_type ._fields )
12591266 bytes_type = str_type ._encoded_counterpart
12601267 self .assertIs (bytes_type ._decoded_counterpart , str_type )
12611268 bytes_args = tuple_encode (str_args )
@@ -1987,6 +1994,27 @@ def test_to_bytes_deprecation(self):
19871994 self .assertEqual (str (cm .warning ),
19881995 'urllib.parse.to_bytes() is deprecated as of 3.8' )
19891996
1997+ def test_falsey_deprecation (self ):
1998+ pattern = (
1999+ "Providing false values other than strings or bytes to urllib.parse "
2000+ "is deprecated: got <class "
2001+ )
2002+ cases = [
2003+ (urllib .parse .urljoin , ['http://www.python.org' , []]),
2004+ (urllib .parse .urljoin , [[], b'docs' ]),
2005+ (urllib .parse .urlparse , [b'www.python.org' , None ]),
2006+ (urllib .parse .urlparse , [{}, '' ]),
2007+ (urllib .parse .urlsplit , [0 , b'http' ]),
2008+ (urllib .parse .urlsplit , [b'http://www.python.org' , None ]),
2009+ (urllib .parse .urldefrag , [{}]),
2010+ (urllib .parse .urlunparse , [[None , b'www.python.org' , None , None , None , None ]]),
2011+ (urllib .parse .urlunsplit , [['http' , 0 , '' , '' , '' ]]),
2012+ ]
2013+ for callable , args in cases :
2014+ with self .subTest (callable = callable ):
2015+ with self .assertWarnsRegex (DeprecationWarning , pattern ):
2016+ callable (* args )
2017+
19902018
19912019def str_encode (s ):
19922020 if s is None :
0 commit comments