@@ -273,31 +273,31 @@ def test_ipv6host_header(self):
273
273
sock = FakeSocket ('' )
274
274
conn .sock = sock
275
275
conn .request ('GET' , '/foo' )
276
- self .assertTrue (sock .data . startswith ( expected ) )
276
+ self .assertStartsWith (sock .data , expected )
277
277
278
278
expected = b'GET /foo HTTP/1.1\r \n Host: [2001:102A::]\r \n ' \
279
279
b'Accept-Encoding: identity\r \n \r \n '
280
280
conn = client .HTTPConnection ('[2001:102A::]' )
281
281
sock = FakeSocket ('' )
282
282
conn .sock = sock
283
283
conn .request ('GET' , '/foo' )
284
- self .assertTrue (sock .data . startswith ( expected ) )
284
+ self .assertStartsWith (sock .data , expected )
285
285
286
286
expected = b'GET /foo HTTP/1.1\r \n Host: [fe80::]\r \n ' \
287
287
b'Accept-Encoding: identity\r \n \r \n '
288
288
conn = client .HTTPConnection ('[fe80::%2]' )
289
289
sock = FakeSocket ('' )
290
290
conn .sock = sock
291
291
conn .request ('GET' , '/foo' )
292
- self .assertTrue (sock .data . startswith ( expected ) )
292
+ self .assertStartsWith (sock .data , expected )
293
293
294
294
expected = b'GET /foo HTTP/1.1\r \n Host: [fe80::]:81\r \n ' \
295
295
b'Accept-Encoding: identity\r \n \r \n '
296
296
conn = client .HTTPConnection ('[fe80::%2]:81' )
297
297
sock = FakeSocket ('' )
298
298
conn .sock = sock
299
299
conn .request ('GET' , '/foo' )
300
- self .assertTrue (sock .data . startswith ( expected ) )
300
+ self .assertStartsWith (sock .data , expected )
301
301
302
302
def test_malformed_headers_coped_with (self ):
303
303
# Issue 19996
@@ -335,9 +335,9 @@ def test_parse_all_octets(self):
335
335
self .assertIsNotNone (resp .getheader ('obs-text' ))
336
336
self .assertIn ('obs-text' , resp .msg )
337
337
for folded in (resp .getheader ('obs-fold' ), resp .msg ['obs-fold' ]):
338
- self .assertTrue (folded . startswith ( 'text' ) )
338
+ self .assertStartsWith (folded , 'text' )
339
339
self .assertIn (' folded with space' , folded )
340
- self .assertTrue (folded . endswith ( 'folded with tab' ) )
340
+ self .assertEndsWith (folded , 'folded with tab' )
341
341
342
342
def test_invalid_headers (self ):
343
343
conn = client .HTTPConnection ('example.com' )
@@ -989,8 +989,7 @@ def test_send_file(self):
989
989
sock = FakeSocket (body )
990
990
conn .sock = sock
991
991
conn .request ('GET' , '/foo' , body )
992
- self .assertTrue (sock .data .startswith (expected ), '%r != %r' %
993
- (sock .data [:len (expected )], expected ))
992
+ self .assertStartsWith (sock .data , expected )
994
993
995
994
def test_send (self ):
996
995
expected = b'this is a test this is only a test'
@@ -1553,7 +1552,7 @@ def mypeek(n=-1):
1553
1552
# then unbounded peek
1554
1553
p2 = resp .peek ()
1555
1554
self .assertGreaterEqual (len (p2 ), len (p ))
1556
- self .assertTrue (p2 . startswith ( p ) )
1555
+ self .assertStartsWith (p2 , p )
1557
1556
next = resp .read (len (p2 ))
1558
1557
self .assertEqual (next , p2 )
1559
1558
else :
@@ -1578,7 +1577,7 @@ def _verify_readline(self, readline, expected, limit=5):
1578
1577
line = readline (limit )
1579
1578
if line and line != b"foo" :
1580
1579
if len (line ) < 5 :
1581
- self .assertTrue (line . endswith ( b"\n " ) )
1580
+ self .assertEndsWith (line , b"\n " )
1582
1581
all .append (line )
1583
1582
if not line :
1584
1583
break
@@ -1773,7 +1772,7 @@ def test_client_constants(self):
1773
1772
]
1774
1773
for const in expected :
1775
1774
with self .subTest (constant = const ):
1776
- self .assertTrue ( hasattr ( client , const ) )
1775
+ self .assertHasAttr ( client , const )
1777
1776
1778
1777
1779
1778
class SourceAddressTest (TestCase ):
@@ -2415,8 +2414,7 @@ def test_tunnel_connect_single_send_connection_setup(self):
2415
2414
msg = f'unexpected number of send calls: { mock_send .mock_calls } ' )
2416
2415
proxy_setup_data_sent = mock_send .mock_calls [0 ][1 ][0 ]
2417
2416
self .assertIn (b'CONNECT destination.com' , proxy_setup_data_sent )
2418
- self .assertTrue (
2419
- proxy_setup_data_sent .endswith (b'\r \n \r \n ' ),
2417
+ self .assertEndsWith (proxy_setup_data_sent , b'\r \n \r \n ' ,
2420
2418
msg = f'unexpected proxy data sent { proxy_setup_data_sent !r} ' )
2421
2419
2422
2420
def test_connect_put_request (self ):
0 commit comments