@@ -273,31 +273,31 @@ def test_ipv6host_header(self):
273273 sock = FakeSocket ('' )
274274 conn .sock = sock
275275 conn .request ('GET' , '/foo' )
276- self .assertTrue (sock .data . startswith ( expected ) )
276+ self .assertStartsWith (sock .data , expected )
277277
278278 expected = b'GET /foo HTTP/1.1\r \n Host: [2001:102A::]\r \n ' \
279279 b'Accept-Encoding: identity\r \n \r \n '
280280 conn = client .HTTPConnection ('[2001:102A::]' )
281281 sock = FakeSocket ('' )
282282 conn .sock = sock
283283 conn .request ('GET' , '/foo' )
284- self .assertTrue (sock .data . startswith ( expected ) )
284+ self .assertStartsWith (sock .data , expected )
285285
286286 expected = b'GET /foo HTTP/1.1\r \n Host: [fe80::]\r \n ' \
287287 b'Accept-Encoding: identity\r \n \r \n '
288288 conn = client .HTTPConnection ('[fe80::%2]' )
289289 sock = FakeSocket ('' )
290290 conn .sock = sock
291291 conn .request ('GET' , '/foo' )
292- self .assertTrue (sock .data . startswith ( expected ) )
292+ self .assertStartsWith (sock .data , expected )
293293
294294 expected = b'GET /foo HTTP/1.1\r \n Host: [fe80::]:81\r \n ' \
295295 b'Accept-Encoding: identity\r \n \r \n '
296296 conn = client .HTTPConnection ('[fe80::%2]:81' )
297297 sock = FakeSocket ('' )
298298 conn .sock = sock
299299 conn .request ('GET' , '/foo' )
300- self .assertTrue (sock .data . startswith ( expected ) )
300+ self .assertStartsWith (sock .data , expected )
301301
302302 def test_malformed_headers_coped_with (self ):
303303 # Issue 19996
@@ -335,9 +335,9 @@ def test_parse_all_octets(self):
335335 self .assertIsNotNone (resp .getheader ('obs-text' ))
336336 self .assertIn ('obs-text' , resp .msg )
337337 for folded in (resp .getheader ('obs-fold' ), resp .msg ['obs-fold' ]):
338- self .assertTrue (folded . startswith ( 'text' ) )
338+ self .assertStartsWith (folded , 'text' )
339339 self .assertIn (' folded with space' , folded )
340- self .assertTrue (folded . endswith ( 'folded with tab' ) )
340+ self .assertEndsWith (folded , 'folded with tab' )
341341
342342 def test_invalid_headers (self ):
343343 conn = client .HTTPConnection ('example.com' )
@@ -989,8 +989,7 @@ def test_send_file(self):
989989 sock = FakeSocket (body )
990990 conn .sock = sock
991991 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 )
994993
995994 def test_send (self ):
996995 expected = b'this is a test this is only a test'
@@ -1553,7 +1552,7 @@ def mypeek(n=-1):
15531552 # then unbounded peek
15541553 p2 = resp .peek ()
15551554 self .assertGreaterEqual (len (p2 ), len (p ))
1556- self .assertTrue (p2 . startswith ( p ) )
1555+ self .assertStartsWith (p2 , p )
15571556 next = resp .read (len (p2 ))
15581557 self .assertEqual (next , p2 )
15591558 else :
@@ -1578,7 +1577,7 @@ def _verify_readline(self, readline, expected, limit=5):
15781577 line = readline (limit )
15791578 if line and line != b"foo" :
15801579 if len (line ) < 5 :
1581- self .assertTrue (line . endswith ( b"\n " ) )
1580+ self .assertEndsWith (line , b"\n " )
15821581 all .append (line )
15831582 if not line :
15841583 break
@@ -1773,7 +1772,7 @@ def test_client_constants(self):
17731772 ]
17741773 for const in expected :
17751774 with self .subTest (constant = const ):
1776- self .assertTrue ( hasattr ( client , const ) )
1775+ self .assertHasAttr ( client , const )
17771776
17781777
17791778class SourceAddressTest (TestCase ):
@@ -2415,8 +2414,7 @@ def test_tunnel_connect_single_send_connection_setup(self):
24152414 msg = f'unexpected number of send calls: { mock_send .mock_calls } ' )
24162415 proxy_setup_data_sent = mock_send .mock_calls [0 ][1 ][0 ]
24172416 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 ' ,
24202418 msg = f'unexpected proxy data sent { proxy_setup_data_sent !r} ' )
24212419
24222420 def test_connect_put_request (self ):
0 commit comments