@@ -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'
@@ -1545,7 +1544,7 @@ def mypeek(n=-1):
15451544 # then unbounded peek
15461545 p2 = resp .peek ()
15471546 self .assertGreaterEqual (len (p2 ), len (p ))
1548- self .assertTrue (p2 . startswith ( p ) )
1547+ self .assertStartsWith (p2 , p )
15491548 next = resp .read (len (p2 ))
15501549 self .assertEqual (next , p2 )
15511550 else :
@@ -1570,7 +1569,7 @@ def _verify_readline(self, readline, expected, limit=5):
15701569 line = readline (limit )
15711570 if line and line != b"foo" :
15721571 if len (line ) < 5 :
1573- self .assertTrue (line . endswith ( b"\n " ) )
1572+ self .assertEndsWith (line , b"\n " )
15741573 all .append (line )
15751574 if not line :
15761575 break
@@ -1765,7 +1764,7 @@ def test_client_constants(self):
17651764 ]
17661765 for const in expected :
17671766 with self .subTest (constant = const ):
1768- self .assertTrue ( hasattr ( client , const ) )
1767+ self .assertHasAttr ( client , const )
17691768
17701769
17711770class SourceAddressTest (TestCase ):
@@ -2407,8 +2406,7 @@ def test_tunnel_connect_single_send_connection_setup(self):
24072406 msg = f'unexpected number of send calls: { mock_send .mock_calls } ' )
24082407 proxy_setup_data_sent = mock_send .mock_calls [0 ][1 ][0 ]
24092408 self .assertIn (b'CONNECT destination.com' , proxy_setup_data_sent )
2410- self .assertTrue (
2411- proxy_setup_data_sent .endswith (b'\r \n \r \n ' ),
2409+ self .assertEndsWith (proxy_setup_data_sent , b'\r \n \r \n ' ,
24122410 msg = f'unexpected proxy data sent { proxy_setup_data_sent !r} ' )
24132411
24142412 def test_connect_put_request (self ):
0 commit comments