@@ -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' )
@@ -1000,8 +1000,7 @@ def test_send_file(self):
10001000 sock = FakeSocket (body )
10011001 conn .sock = sock
10021002 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 )
10051004
10061005 def test_send (self ):
10071006 expected = b'this is a test this is only a test'
@@ -1564,7 +1563,7 @@ def mypeek(n=-1):
15641563 # then unbounded peek
15651564 p2 = resp .peek ()
15661565 self .assertGreaterEqual (len (p2 ), len (p ))
1567- self .assertTrue (p2 . startswith ( p ) )
1566+ self .assertStartsWith (p2 , p )
15681567 next = resp .read (len (p2 ))
15691568 self .assertEqual (next , p2 )
15701569 else :
@@ -1589,7 +1588,7 @@ def _verify_readline(self, readline, expected, limit=5):
15891588 line = readline (limit )
15901589 if line and line != b"foo" :
15911590 if len (line ) < 5 :
1592- self .assertTrue (line . endswith ( b"\n " ) )
1591+ self .assertEndsWith (line , b"\n " )
15931592 all .append (line )
15941593 if not line :
15951594 break
@@ -1784,7 +1783,7 @@ def test_client_constants(self):
17841783 ]
17851784 for const in expected :
17861785 with self .subTest (constant = const ):
1787- self .assertTrue ( hasattr ( client , const ) )
1786+ self .assertHasAttr ( client , const )
17881787
17891788
17901789class SourceAddressTest (TestCase ):
@@ -2426,8 +2425,7 @@ def test_tunnel_connect_single_send_connection_setup(self):
24262425 msg = f'unexpected number of send calls: { mock_send .mock_calls } ' )
24272426 proxy_setup_data_sent = mock_send .mock_calls [0 ][1 ][0 ]
24282427 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 ' ,
24312429 msg = f'unexpected proxy data sent { proxy_setup_data_sent !r} ' )
24322430
24332431 def test_connect_put_request (self ):
0 commit comments