@@ -123,14 +123,12 @@ def test_200_error(self):
123
123
content_type = self ._content_type ("country" ),
124
124
)
125
125
126
- with self .assertRaisesRegex (
127
- GeoIP2Error , "could not decode the response as JSON"
128
- ):
126
+ with pytest .raises (GeoIP2Error , match = "could not decode the response as JSON" ):
129
127
self .run_client (self .client .country ("1.1.1.1" ))
130
128
131
129
def test_bad_ip_address (self ):
132
- with self . assertRaisesRegex (
133
- ValueError , "'1.2.3' does not appear to be an IPv4 " " or IPv6 address"
130
+ with pytest . raises (
131
+ ValueError , match = "'1.2.3' does not appear to be an IPv4 or IPv6 address"
134
132
):
135
133
self .run_client (self .client .country ("1.2.3" ))
136
134
@@ -142,9 +140,7 @@ def test_no_body_error(self):
142
140
status = 400 ,
143
141
content_type = self ._content_type ("country" ),
144
142
)
145
- with self .assertRaisesRegex (
146
- HTTPError , "Received a 400 error for .* with no body"
147
- ):
143
+ with pytest .raises (HTTPError , match = "Received a 400 error for .* with no body" ):
148
144
self .run_client (self .client .country ("1.2.3.7" ))
149
145
150
146
def test_weird_body_error (self ):
@@ -157,9 +153,10 @@ def test_weird_body_error(self):
157
153
content_type = self ._content_type ("country" ),
158
154
)
159
155
160
- with self . assertRaisesRegex (
156
+ with pytest . raises (
161
157
HTTPError ,
162
- "Response contains JSON but it does not " "specify code or error keys" ,
158
+ match = "Response contains JSON but it does not "
159
+ "specify code or error keys" ,
163
160
):
164
161
self .run_client (self .client .country ("1.2.3.8" ))
165
162
@@ -172,8 +169,8 @@ def test_bad_body_error(self):
172
169
status = 400 ,
173
170
content_type = self ._content_type ("country" ),
174
171
)
175
- with self . assertRaisesRegex (
176
- HTTPError , "it did not include the expected JSON body"
172
+ with pytest . raises (
173
+ HTTPError , match = "it did not include the expected JSON body"
177
174
):
178
175
self .run_client (self .client .country ("1.2.3.9" ))
179
176
@@ -185,7 +182,7 @@ def test_500_error(self):
185
182
status = 500 ,
186
183
content_type = self ._content_type ("country" ),
187
184
)
188
- with self . assertRaisesRegex (HTTPError , r"Received a server error \(500\) for" ):
185
+ with pytest . raises (HTTPError , match = r"Received a server error \(500\) for" ):
189
186
self .run_client (self .client .country ("1.2.3.10" ))
190
187
191
188
def test_300_error (self ):
@@ -197,8 +194,8 @@ def test_300_error(self):
197
194
status = 300 ,
198
195
content_type = self ._content_type ("country" ),
199
196
)
200
- with self . assertRaisesRegex (
201
- HTTPError , r"Received a very surprising HTTP status \(300\) for"
197
+ with pytest . raises (
198
+ HTTPError , match = r"Received a very surprising HTTP status \(300\) for"
202
199
):
203
200
self .run_client (self .client .country ("1.2.3.11" ))
204
201
@@ -245,7 +242,7 @@ def _test_error(self, status, error_code, error_class):
245
242
status = status ,
246
243
content_type = self ._content_type ("country" ),
247
244
)
248
- with self . assertRaisesRegex (error_class , msg ):
245
+ with pytest . raises (error_class , match = msg ):
249
246
self .run_client (self .client .country ("1.2.3.18" ))
250
247
251
248
def test_unknown_error (self ):
@@ -259,7 +256,7 @@ def test_unknown_error(self):
259
256
status = 400 ,
260
257
content_type = self ._content_type ("country" ),
261
258
)
262
- with self . assertRaisesRegex (InvalidRequestError , msg ):
259
+ with pytest . raises (InvalidRequestError , match = msg ):
263
260
self .run_client (self .client .country (ip ))
264
261
265
262
def test_request (self ):
0 commit comments