1
1
import unittest
2
2
import urllib .parse
3
+ import warnings
3
4
4
5
RFC1808_BASE = "http://a/b/c/d;p?q#f"
5
6
RFC2396_BASE = "http://a/b/c/d;p?q"
@@ -993,15 +994,15 @@ class Utility_Tests(unittest.TestCase):
993
994
# In Python 2 this test class was in test_urllib.
994
995
995
996
def test_splittype (self ):
996
- splittype = urllib .parse .splittype
997
+ splittype = urllib .parse ._splittype
997
998
self .assertEqual (splittype ('type:opaquestring' ), ('type' , 'opaquestring' ))
998
999
self .assertEqual (splittype ('opaquestring' ), (None , 'opaquestring' ))
999
1000
self .assertEqual (splittype (':opaquestring' ), (None , ':opaquestring' ))
1000
1001
self .assertEqual (splittype ('type:' ), ('type' , '' ))
1001
1002
self .assertEqual (splittype ('type:opaque:string' ), ('type' , 'opaque:string' ))
1002
1003
1003
1004
def test_splithost (self ):
1004
- splithost = urllib .parse .splithost
1005
+ splithost = urllib .parse ._splithost
1005
1006
self .assertEqual (splithost ('//www.example.org:80/foo/bar/baz.html' ),
1006
1007
('www.example.org:80' , '/foo/bar/baz.html' ))
1007
1008
self .assertEqual (splithost ('//www.example.org:80' ),
@@ -1030,7 +1031,7 @@ def test_splithost(self):
1030
1031
('example.net' , '/file#' ))
1031
1032
1032
1033
def test_splituser (self ):
1033
- splituser = urllib .parse .splituser
1034
+ splituser = urllib .parse ._splituser
1034
1035
self .
assertEqual (
splituser (
'User:[email protected] :080' ),
1035
1036
('User:Pass' , 'www.python.org:080' ))
1036
1037
self .assertEqual (splituser ('@www.python.org:080' ),
@@ -1045,7 +1046,7 @@ def test_splituser(self):
1045
1046
def test_splitpasswd (self ):
1046
1047
# Some of the password examples are not sensible, but it is added to
1047
1048
# confirming to RFC2617 and addressing issue4675.
1048
- splitpasswd = urllib .parse .splitpasswd
1049
+ splitpasswd = urllib .parse ._splitpasswd
1049
1050
self .assertEqual (splitpasswd ('user:ab' ), ('user' , 'ab' ))
1050
1051
self .assertEqual (splitpasswd ('user:a\n b' ), ('user' , 'a\n b' ))
1051
1052
self .assertEqual (splitpasswd ('user:a\t b' ), ('user' , 'a\t b' ))
@@ -1061,7 +1062,7 @@ def test_splitpasswd(self):
1061
1062
self .assertEqual (splitpasswd (':ab' ), ('' , 'ab' ))
1062
1063
1063
1064
def test_splitport (self ):
1064
- splitport = urllib .parse .splitport
1065
+ splitport = urllib .parse ._splitport
1065
1066
self .assertEqual (splitport ('parrot:88' ), ('parrot' , '88' ))
1066
1067
self .assertEqual (splitport ('parrot' ), ('parrot' , None ))
1067
1068
self .assertEqual (splitport ('parrot:' ), ('parrot' , None ))
@@ -1072,7 +1073,7 @@ def test_splitport(self):
1072
1073
self .assertEqual (splitport (':88' ), ('' , '88' ))
1073
1074
1074
1075
def test_splitnport (self ):
1075
- splitnport = urllib .parse .splitnport
1076
+ splitnport = urllib .parse ._splitnport
1076
1077
self .assertEqual (splitnport ('parrot:88' ), ('parrot' , 88 ))
1077
1078
self .assertEqual (splitnport ('parrot' ), ('parrot' , - 1 ))
1078
1079
self .assertEqual (splitnport ('parrot' , 55 ), ('parrot' , 55 ))
@@ -1086,7 +1087,7 @@ def test_splitnport(self):
1086
1087
def test_splitquery (self ):
1087
1088
# Normal cases are exercised by other tests; ensure that we also
1088
1089
# catch cases with no port specified (testcase ensuring coverage)
1089
- splitquery = urllib .parse .splitquery
1090
+ splitquery = urllib .parse ._splitquery
1090
1091
self .assertEqual (splitquery ('http://python.org/fake?foo=bar' ),
1091
1092
('http://python.org/fake' , 'foo=bar' ))
1092
1093
self .assertEqual (splitquery ('http://python.org/fake?foo=bar?' ),
@@ -1096,7 +1097,7 @@ def test_splitquery(self):
1096
1097
self .assertEqual (splitquery ('?foo=bar' ), ('' , 'foo=bar' ))
1097
1098
1098
1099
def test_splittag (self ):
1099
- splittag = urllib .parse .splittag
1100
+ splittag = urllib .parse ._splittag
1100
1101
self .assertEqual (splittag ('http://example.com?foo=bar#baz' ),
1101
1102
('http://example.com?foo=bar' , 'baz' ))
1102
1103
self .assertEqual (splittag ('http://example.com?foo=bar#' ),
@@ -1108,7 +1109,7 @@ def test_splittag(self):
1108
1109
('http://example.com?foo=bar#baz' , 'boo' ))
1109
1110
1110
1111
def test_splitattr (self ):
1111
- splitattr = urllib .parse .splitattr
1112
+ splitattr = urllib .parse ._splitattr
1112
1113
self .assertEqual (splitattr ('/path;attr1=value1;attr2=value2' ),
1113
1114
('/path' , ['attr1=value1' , 'attr2=value2' ]))
1114
1115
self .assertEqual (splitattr ('/path;' ), ('/path' , ['' ]))
@@ -1119,23 +1120,108 @@ def test_splitattr(self):
1119
1120
def test_splitvalue (self ):
1120
1121
# Normal cases are exercised by other tests; test pathological cases
1121
1122
# with no key/value pairs. (testcase ensuring coverage)
1122
- splitvalue = urllib .parse .splitvalue
1123
+ splitvalue = urllib .parse ._splitvalue
1123
1124
self .assertEqual (splitvalue ('foo=bar' ), ('foo' , 'bar' ))
1124
1125
self .assertEqual (splitvalue ('foo=' ), ('foo' , '' ))
1125
1126
self .assertEqual (splitvalue ('=bar' ), ('' , 'bar' ))
1126
1127
self .assertEqual (splitvalue ('foobar' ), ('foobar' , None ))
1127
1128
self .assertEqual (splitvalue ('foo=bar=baz' ), ('foo' , 'bar=baz' ))
1128
1129
1129
1130
def test_to_bytes (self ):
1130
- result = urllib .parse .to_bytes ('http://www.python.org' )
1131
+ result = urllib .parse ._to_bytes ('http://www.python.org' )
1131
1132
self .assertEqual (result , 'http://www.python.org' )
1132
- self .assertRaises (UnicodeError , urllib .parse .to_bytes ,
1133
+ self .assertRaises (UnicodeError , urllib .parse ._to_bytes ,
1133
1134
'http://www.python.org/medi\u00e6 val' )
1134
1135
1135
1136
def test_unwrap (self ):
1136
- url = urllib .parse .unwrap ('<URL:type://host/path>' )
1137
+ url = urllib .parse ._unwrap ('<URL:type://host/path>' )
1137
1138
self .assertEqual (url , 'type://host/path' )
1138
1139
1139
1140
1141
+ class DeprecationTest (unittest .TestCase ):
1142
+
1143
+ def test_splittype_deprecation (self ):
1144
+ with self .assertWarns (DeprecationWarning ) as cm :
1145
+ urllib .parse .splittype ()
1146
+ self .assertEqual (str (cm .warning ),
1147
+ 'urllib.parse.splittype() is deprecated as of 3.7, '
1148
+ 'use urllib.parse.urlparse() instead' )
1149
+
1150
+ def test_splithost_deprecation (self ):
1151
+ with self .assertWarns (DeprecationWarning ) as cm :
1152
+ urllib .parse .splithost ()
1153
+ self .assertEqual (str (cm .warning ),
1154
+ 'urllib.parse.splithost() is deprecated as of 3.7, '
1155
+ 'use urllib.parse.urlparse() instead' )
1156
+
1157
+ def test_splituser_deprecation (self ):
1158
+ with self .assertWarns (DeprecationWarning ) as cm :
1159
+ urllib .parse .splituser ()
1160
+ self .assertEqual (str (cm .warning ),
1161
+ 'urllib.parse.splituser() is deprecated as of 3.7, '
1162
+ 'use urllib.parse.urlparse() instead' )
1163
+
1164
+ def test_splitpasswd_deprecation (self ):
1165
+ with self .assertWarns (DeprecationWarning ) as cm :
1166
+ urllib .parse .splitpasswd ()
1167
+ self .assertEqual (str (cm .warning ),
1168
+ 'urllib.parse.splitpasswd() is deprecated as of 3.7, '
1169
+ 'use urllib.parse.urlparse() instead' )
1170
+
1171
+ def test_splitport_deprecation (self ):
1172
+ with self .assertWarns (DeprecationWarning ) as cm :
1173
+ urllib .parse .splitport ()
1174
+ self .assertEqual (str (cm .warning ),
1175
+ 'urllib.parse.splitport() is deprecated as of 3.7, '
1176
+ 'use urllib.parse.urlparse() instead' )
1177
+
1178
+ def test_splitnport_deprecation (self ):
1179
+ with self .assertWarns (DeprecationWarning ) as cm :
1180
+ urllib .parse .splitnport ()
1181
+ self .assertEqual (str (cm .warning ),
1182
+ 'urllib.parse.splitnport() is deprecated as of 3.7, '
1183
+ 'use urllib.parse.urlparse() instead' )
1184
+
1185
+ def test_splitquery_deprecation (self ):
1186
+ with self .assertWarns (DeprecationWarning ) as cm :
1187
+ urllib .parse .splitquery ()
1188
+ self .assertEqual (str (cm .warning ),
1189
+ 'urllib.parse.splitquery() is deprecated as of 3.7, '
1190
+ 'use urllib.parse.urlparse() instead' )
1191
+
1192
+ def test_splittag_deprecation (self ):
1193
+ with self .assertWarns (DeprecationWarning ) as cm :
1194
+ urllib .parse .splittag ()
1195
+ self .assertEqual (str (cm .warning ),
1196
+ 'urllib.parse.splittag() is deprecated as of 3.7, '
1197
+ 'use urllib.parse.urlparse() instead' )
1198
+
1199
+ def test_splitattr_deprecation (self ):
1200
+ with self .assertWarns (DeprecationWarning ) as cm :
1201
+ urllib .parse .splitattr ()
1202
+ self .assertEqual (str (cm .warning ),
1203
+ 'urllib.parse.splitattr() is deprecated as of 3.7, '
1204
+ 'use urllib.parse.urlparse() instead' )
1205
+
1206
+ def test_splitvalue_deprecation (self ):
1207
+ with self .assertWarns (DeprecationWarning ) as cm :
1208
+ urllib .parse .splitvalue ()
1209
+ self .assertEqual (str (cm .warning ),
1210
+ 'urllib.parse.splitvalue() is deprecated as of 3.7, '
1211
+ 'use urllib.parse.urlparse() instead' )
1212
+
1213
+ def test_to_bytes_deprecation (self ):
1214
+ with self .assertWarns (DeprecationWarning ) as cm :
1215
+ urllib .parse .to_bytes ()
1216
+ self .assertEqual (str (cm .warning ),
1217
+ 'urllib.parse.to_bytes() is deprecated as of 3.7' )
1218
+
1219
+ def test_unwrap (self ):
1220
+ with self .assertWarns (DeprecationWarning ) as cm :
1221
+ urllib .parse .unwrap ()
1222
+ self .assertEqual (str (cm .warning ),
1223
+ 'urllib.parse.unwrap() is deprecated as of 3.7' )
1224
+
1225
+
1140
1226
if __name__ == "__main__" :
1141
1227
unittest .main ()
0 commit comments