Skip to content

Commit c08cbc8

Browse files
Use ExtraAssertions instead of rewriting the assertions
assertStartsWith() and assertEndsWith() are provided by test.support.testcase.ExtraAssertions in 3.13, so the new tests can be kept identical to the 3.14+ version. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 5740185 commit c08cbc8

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

Lib/test/test_wsgiref.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest import mock
22
from test import support
33
from test.support import socket_helper, control_characters_c0
4+
from test.support.testcase import ExtraAssertions
45
from test.test_httpservers import NoLogRequestHandler
56
from unittest import TestCase
67
from wsgiref.util import setup_testing_defaults
@@ -122,7 +123,7 @@ def compare_generic_iter(make_it, match):
122123
raise AssertionError("Too many items from .__next__()", it)
123124

124125

125-
class IntegrationTests(TestCase):
126+
class IntegrationTests(TestCase, ExtraAssertions):
126127

127128
def check_hello(self, out, has_length=True):
128129
pyver = (python_implementation() + "/" +
@@ -217,51 +218,51 @@ def test_wsgi_input_read(self):
217218
good_app = input_app("read", 5)
218219

219220
out, err = run_amock(validator(bad_app))
220-
self.assertTrue(out.endswith(
221+
self.assertEndsWith(out,
221222
b"A server error occurred. Please contact the administrator."
222-
))
223+
)
223224

224225
self.assertEqual(
225226
err.splitlines()[-2], "AssertionError"
226227
)
227228

228229
out, err = run_amock(validator(good_app), b"GET / HTTP/1.0\n\nTest 1\nTest 2\n")
229-
self.assertTrue(out.endswith(b"Test "))
230+
self.assertEndsWith(out, b"Test ")
230231

231232
def test_wsgi_input_readlines(self):
232233
bad_app = input_app("readlines", 3, 5)
233234
good_app = input_app("readlines", 1)
234235

235236
out, err = run_amock(validator(bad_app))
236-
self.assertTrue(out.endswith(
237+
self.assertEndsWith(out,
237238
b"A server error occurred. Please contact the administrator."
238-
))
239+
)
239240
self.assertEqual(
240241
err.splitlines()[-2], "AssertionError"
241242
)
242243
out, err = run_amock(validator(good_app), b"GET / HTTP/1.0\n\nTest Line 1\nTest Line 2\n")
243-
self.assertTrue(out.endswith(b"Test Line 1\n"))
244+
self.assertEndsWith(out, b"Test Line 1\n")
244245

245246
def test_wsgi_input_readline(self):
246247
bad_app = input_app("readline", 3, 4)
247248
good_app = input_app("readline", 2)
248249

249250
out, err = run_amock(validator(bad_app))
250-
self.assertTrue(out.endswith(
251+
self.assertEndsWith(out,
251252
b"A server error occurred. Please contact the administrator."
252-
))
253+
)
253254
self.assertEqual(
254255
err.splitlines()[-2], "AssertionError"
255256
)
256257

257258
out, err = run_amock(validator(good_app), b"GET / HTTP/1.0\n\nTest 1\nTest 2\n")
258-
self.assertTrue(out.endswith(b"Te"))
259+
self.assertEndsWith(out, b"Te")
259260

260261
def test_wsgi_input_close(self):
261262
app = input_app("close")
262263
out, err = run_amock(validator(app), b"GET / HTTP/1.0\n\nTest 1\nTest 2\n")
263264
self.assertEqual(err.splitlines()[-2], 'AssertionError: input.close() must not be called')
264-
self.assertTrue(out.endswith(b"A server error occurred. Please contact the administrator."))
265+
self.assertEndsWith(out, b"A server error occurred. Please contact the administrator.")
265266

266267
def test_wsgi_input_iter(self):
267268
def app(e,s):
@@ -272,7 +273,7 @@ def app(e,s):
272273
return [b';'.join(req)]
273274

274275
out, err = run_amock(validator(app), b"GET / HTTP/1.0\n\nTest 1\nTest 2\n")
275-
self.assertTrue(out.endswith(b"Test 1\n;Test 2\n"))
276+
self.assertEndsWith(out, b"Test 1\n;Test 2\n")
276277

277278
def test_wsgi_errors_write(self):
278279
bad_app = errors_app("write", b"Test")
@@ -282,7 +283,7 @@ def test_wsgi_errors_write(self):
282283
self.assertEqual(err.splitlines()[-2], 'AssertionError')
283284

284285
out, err = run_amock(validator(good_app), b"GET / HTTP/1.0\n\n")
285-
self.assertTrue(err.startswith("Test"))
286+
self.assertStartsWith(err, "Test")
286287

287288
def test_wsgi_errors_writelines(self):
288289
bad_app = errors_app("writelines", [1, "Test"])
@@ -292,7 +293,7 @@ def test_wsgi_errors_writelines(self):
292293
self.assertEqual(err.splitlines()[-2], 'AssertionError')
293294

294295
out, err = run_amock(validator(good_app), b"GET / HTTP/1.0\n\n")
295-
self.assertTrue(err.startswith("TestTest"))
296+
self.assertStartsWith(err, "TestTest")
296297

297298
def test_wsgi_errors_close(self):
298299
app = errors_app("close")

0 commit comments

Comments
 (0)