@@ -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' )
@@ -1000,8 +1000,7 @@ def test_send_file(self):
1000
1000
sock = FakeSocket (body )
1001
1001
conn .sock = sock
1002
1002
conn .request ('GET' , '/foo' , body )
1003
- self .assertTrue (sock .data .startswith (expected ), '%r != %r' %
1004
- (sock .data [:len (expected )], expected ))
1003
+ self .assertStartsWith (sock .data , expected )
1005
1004
1006
1005
def test_send (self ):
1007
1006
expected = b'this is a test this is only a test'
@@ -1564,7 +1563,7 @@ def mypeek(n=-1):
1564
1563
# then unbounded peek
1565
1564
p2 = resp .peek ()
1566
1565
self .assertGreaterEqual (len (p2 ), len (p ))
1567
- self .assertTrue (p2 . startswith ( p ) )
1566
+ self .assertStartsWith (p2 , p )
1568
1567
next = resp .read (len (p2 ))
1569
1568
self .assertEqual (next , p2 )
1570
1569
else :
@@ -1589,7 +1588,7 @@ def _verify_readline(self, readline, expected, limit=5):
1589
1588
line = readline (limit )
1590
1589
if line and line != b"foo" :
1591
1590
if len (line ) < 5 :
1592
- self .assertTrue (line . endswith ( b"\n " ) )
1591
+ self .assertEndsWith (line , b"\n " )
1593
1592
all .append (line )
1594
1593
if not line :
1595
1594
break
@@ -1784,7 +1783,7 @@ def test_client_constants(self):
1784
1783
]
1785
1784
for const in expected :
1786
1785
with self .subTest (constant = const ):
1787
- self .assertTrue ( hasattr ( client , const ) )
1786
+ self .assertHasAttr ( client , const )
1788
1787
1789
1788
1790
1789
class SourceAddressTest (TestCase ):
@@ -2426,8 +2425,7 @@ def test_tunnel_connect_single_send_connection_setup(self):
2426
2425
msg = f'unexpected number of send calls: { mock_send .mock_calls } ' )
2427
2426
proxy_setup_data_sent = mock_send .mock_calls [0 ][1 ][0 ]
2428
2427
self .assertIn (b'CONNECT destination.com' , proxy_setup_data_sent )
2429
- self .assertTrue (
2430
- proxy_setup_data_sent .endswith (b'\r \n \r \n ' ),
2428
+ self .assertEndsWith (proxy_setup_data_sent , b'\r \n \r \n ' ,
2431
2429
msg = f'unexpected proxy data sent { proxy_setup_data_sent !r} ' )
2432
2430
2433
2431
def test_connect_put_request (self ):
0 commit comments