Skip to content

Commit

Permalink
Move some changes out to other PRs.
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Jan 20, 2025
1 parent b253501 commit b341ef3
Show file tree
Hide file tree
Showing 48 changed files with 180 additions and 162 deletions.
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def getaddrinfo_task(*args, **kwds):
with self.assertRaises(OSError) as cm:
self.loop.run_until_complete(coro)

self.assertStartsWith(str(cm.exception), 'Multiple exceptions: ')
self.assertTrue(str(cm.exception).startswith('Multiple exceptions: '))
self.assertTrue(m_socket.socket.return_value.close.called)

coro = self.loop.create_connection(
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ def test_subprocess_stderr(self):

transp.close()
self.assertEqual(b'OUT:test', proto.data[1])
self.assertStartsWith(proto.data[2], b'ERR:test')
self.assertTrue(proto.data[2].startswith(b'ERR:test'), proto.data[2])
self.assertEqual(0, proto.returncode)

@support.requires_subprocess()
Expand All @@ -2206,7 +2206,8 @@ def test_subprocess_stderr_redirect_to_stdout(self):

stdin.write(b'test')
self.loop.run_until_complete(proto.completed)
self.assertStartsWith(proto.data[1], b'OUT:testERR:test')
self.assertTrue(proto.data[1].startswith(b'OUT:testERR:test'),
proto.data[1])
self.assertEqual(b'', proto.data[2])

transp.close()
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_uninitialized(self):

def test_future_cancel_message_getter(self):
f = self._new_future(loop=self.loop)
self.assertHasAttr(f, '_cancel_message')
self.assertTrue(hasattr(f, '_cancel_message'))
self.assertEqual(f._cancel_message, None)

f.cancel('my message')
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_asyncio/test_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class LockTests(unittest.IsolatedAsyncioTestCase):

async def test_repr(self):
lock = asyncio.Lock()
self.assertEndsWith(repr(lock), '[unlocked]>')
self.assertTrue(repr(lock).endswith('[unlocked]>'))
self.assertTrue(RGX_REPR.match(repr(lock)))

await lock.acquire()
self.assertEndsWith(repr(lock), '[locked]>')
self.assertTrue(repr(lock).endswith('[locked]>'))
self.assertTrue(RGX_REPR.match(repr(lock)))

async def test_lock(self):
Expand Down Expand Up @@ -286,12 +286,12 @@ class EventTests(unittest.IsolatedAsyncioTestCase):

def test_repr(self):
ev = asyncio.Event()
self.assertEndsWith(repr(ev), '[unset]>')
self.assertTrue(repr(ev).endswith('[unset]>'))
match = RGX_REPR.match(repr(ev))
self.assertEqual(match.group('extras'), 'unset')

ev.set()
self.assertEndsWith(repr(ev), '[set]>')
self.assertTrue(repr(ev).endswith('[set]>'))
self.assertTrue(RGX_REPR.match(repr(ev)))

ev._waiters.append(mock.Mock())
Expand Down Expand Up @@ -916,11 +916,11 @@ def test_initial_value_zero(self):

async def test_repr(self):
sem = asyncio.Semaphore()
self.assertEndsWith(repr(sem), '[unlocked, value:1]>')
self.assertTrue(repr(sem).endswith('[unlocked, value:1]>'))
self.assertTrue(RGX_REPR.match(repr(sem)))

await sem.acquire()
self.assertEndsWith(repr(sem), '[locked]>')
self.assertTrue(repr(sem).endswith('[locked]>'))
self.assertTrue('waiters' not in repr(sem))
self.assertTrue(RGX_REPR.match(repr(sem)))

Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_asyncio/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_base_protocol(self):
self.assertIsNone(p.connection_lost(f))
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertNotHasAttr(p, '__dict__')
self.assertFalse(hasattr(p, '__dict__'))

def test_protocol(self):
f = mock.Mock()
Expand All @@ -30,7 +30,7 @@ def test_protocol(self):
self.assertIsNone(p.eof_received())
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertNotHasAttr(p, '__dict__')
self.assertFalse(hasattr(p, '__dict__'))

def test_buffered_protocol(self):
f = mock.Mock()
Expand All @@ -41,7 +41,7 @@ def test_buffered_protocol(self):
self.assertIsNone(p.buffer_updated(150))
self.assertIsNone(p.pause_writing())
self.assertIsNone(p.resume_writing())
self.assertNotHasAttr(p, '__dict__')
self.assertFalse(hasattr(p, '__dict__'))

def test_datagram_protocol(self):
f = mock.Mock()
Expand All @@ -50,7 +50,7 @@ def test_datagram_protocol(self):
self.assertIsNone(dp.connection_lost(f))
self.assertIsNone(dp.error_received(f))
self.assertIsNone(dp.datagram_received(f, f))
self.assertNotHasAttr(dp, '__dict__')
self.assertFalse(hasattr(dp, '__dict__'))

def test_subprocess_protocol(self):
f = mock.Mock()
Expand All @@ -60,7 +60,7 @@ def test_subprocess_protocol(self):
self.assertIsNone(sp.pipe_data_received(1, f))
self.assertIsNone(sp.pipe_connection_lost(1, f))
self.assertIsNone(sp.process_exited())
self.assertNotHasAttr(sp, '__dict__')
self.assertFalse(hasattr(sp, '__dict__'))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def _test_repr_or_str(self, fn, expect_id):
appear in fn(Queue()).
"""
q = asyncio.Queue()
self.assertStartsWith(fn(q), '<Queue')
self.assertTrue(fn(q).startswith('<Queue'), fn(q))
id_is_present = hex(id(q)) in fn(q)
self.assertEqual(expect_id, id_is_present)

Expand Down
14 changes: 7 additions & 7 deletions Lib/test/test_asyncio/test_sock_lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _basetest_sock_client_ops(self, httpd, sock):
self.loop.run_until_complete(
self.loop.sock_recv(sock, 1024))
sock.close()
self.assertStartsWith(data, b'HTTP/1.0 200 OK')
self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))

def _basetest_sock_recv_into(self, httpd, sock):
# same as _basetest_sock_client_ops, but using sock_recv_into
Expand All @@ -127,7 +127,7 @@ def _basetest_sock_recv_into(self, httpd, sock):
self.loop.run_until_complete(
self.loop.sock_recv_into(sock, buf[nbytes:]))
sock.close()
self.assertStartsWith(data, b'HTTP/1.0 200 OK')
self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))

def test_sock_client_ops(self):
with test_utils.run_test_server() as httpd:
Expand All @@ -150,7 +150,7 @@ async def _basetest_sock_recv_racing(self, httpd, sock):
# consume data
await self.loop.sock_recv(sock, 1024)

self.assertStartsWith(data, b'HTTP/1.0 200 OK')
self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))

async def _basetest_sock_recv_into_racing(self, httpd, sock):
sock.setblocking(False)
Expand All @@ -168,7 +168,7 @@ async def _basetest_sock_recv_into_racing(self, httpd, sock):
nbytes = await self.loop.sock_recv_into(sock, buf[:1024])
# consume data
await self.loop.sock_recv_into(sock, buf[nbytes:])
self.assertStartsWith(data, b'HTTP/1.0 200 OK')
self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))

await task

Expand Down Expand Up @@ -217,7 +217,7 @@ async def recv_all():
sock.shutdown(socket.SHUT_WR)
data = await task
# ProactorEventLoop could deliver hello, so endswith is necessary
self.assertEndsWith(data, b'world')
self.assertTrue(data.endswith(b'world'))

# After the first connect attempt before the listener is ready,
# the socket needs time to "recover" to make the next connect call.
Expand Down Expand Up @@ -298,7 +298,7 @@ async def _basetest_huge_content(self, address):
data = await self.loop.sock_recv(sock, DATA_SIZE)
# HTTP headers size is less than MTU,
# they are sent by the first packet always
self.assertStartsWith(data, b'HTTP/1.0 200 OK')
self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))
while data.find(b'\r\n\r\n') == -1:
data += await self.loop.sock_recv(sock, DATA_SIZE)
# Strip headers
Expand Down Expand Up @@ -351,7 +351,7 @@ async def _basetest_huge_content_recvinto(self, address):
data = bytes(buf[:nbytes])
# HTTP headers size is less than MTU,
# they are sent by the first packet always
self.assertStartsWith(data, b'HTTP/1.0 200 OK')
self.assertTrue(data.startswith(b'HTTP/1.0 200 OK'))
while data.find(b'\r\n\r\n') == -1:
nbytes = await self.loop.sock_recv_into(sock, buf)
data = bytes(buf[:nbytes])
Expand Down
18 changes: 9 additions & 9 deletions Lib/test/test_asyncio/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _basetest_open_connection(self, open_connection_fut):
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
f = reader.read()
data = self.loop.run_until_complete(f)
self.assertEndsWith(data, b'\r\n\r\nTest message')
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
writer.close()
self.assertEqual(messages, [])

Expand All @@ -75,7 +75,7 @@ def _basetest_open_connection_no_loop_ssl(self, open_connection_fut):
writer.write(b'GET / HTTP/1.0\r\n\r\n')
f = reader.read()
data = self.loop.run_until_complete(f)
self.assertEndsWith(data, b'\r\n\r\nTest message')
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))

writer.close()
self.assertEqual(messages, [])
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def test_wait_closed_on_close(self):
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
f = rd.read()
data = self.loop.run_until_complete(f)
self.assertEndsWith(data, b'\r\n\r\nTest message')
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
self.assertFalse(wr.is_closing())
wr.close()
self.assertTrue(wr.is_closing())
Expand All @@ -1028,7 +1028,7 @@ async def inner(httpd):
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
self.assertEndsWith(data, b'\r\n\r\nTest message')
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
wr.close()
await wr.wait_closed()

Expand All @@ -1048,7 +1048,7 @@ async def inner(httpd):
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
self.assertEndsWith(data, b'\r\n\r\nTest message')
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
wr.close()
with self.assertRaises(ConnectionResetError):
wr.write(b'data')
Expand Down Expand Up @@ -1089,12 +1089,12 @@ async def inner(httpd):
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
self.assertEndsWith(data, b'\r\n\r\nTest message')
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
with self.assertWarns(ResourceWarning) as cm:
del wr
gc.collect()
self.assertEqual(len(cm.warnings), 1)
self.assertStartsWith(str(cm.warnings[0].message), "unclosed <StreamWriter")
self.assertTrue(str(cm.warnings[0].message).startswith("unclosed <StreamWriter"))

messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
Expand All @@ -1112,7 +1112,7 @@ async def inner(httpd):
data = await rd.readline()
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
data = await rd.read()
self.assertEndsWith(data, b'\r\n\r\nTest message')
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))

# Make "loop is closed" occur first before "del wr" for this test.
self.loop.stop()
Expand Down Expand Up @@ -1144,7 +1144,7 @@ async def inner(rd, wr):
del wr
gc.collect()
self.assertEqual(len(cm.warnings), 1)
self.assertStartsWith(str(cm.warnings[0].message), "unclosed <StreamWriter")
self.assertTrue(str(cm.warnings[0].message).startswith("unclosed <StreamWriter"))

async def outer():
srv = await asyncio.start_server(inner, socket_helper.HOSTv4, 0)
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_task_cancel_message_getter(self):
async def coro():
pass
t = self.new_task(self.loop, coro())
self.assertHasAttr(t, '_cancel_message')
self.assertTrue(hasattr(t, '_cancel_message'))
self.assertEqual(t._cancel_message, None)

t.cancel('my message')
Expand Down Expand Up @@ -3131,7 +3131,7 @@ def new_task(self, coro):
class GenericTaskTests(test_utils.TestCase):

def test_future_subclass(self):
self.assertIsSubclass(asyncio.Task, asyncio.Future)
self.assertTrue(issubclass(asyncio.Task, asyncio.Future))

@support.cpython_only
def test_asyncio_module_compiled(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_asyncio/test_windows_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def test_popen(self):
self.assertGreater(len(out), 0)
self.assertGreater(len(err), 0)
# allow for partial reads...
self.assertStartsWith(msg.upper().rstrip(), out)
self.assertStartsWith(b"stderr", err)
self.assertTrue(msg.upper().rstrip().startswith(out))
self.assertTrue(b"stderr".startswith(err))

# The context manager calls wait() and closes resources
with p:
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_capi/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_object_setattr(self):

# PyObject_SetAttr(obj, attr_name, NULL) removes the attribute
xsetattr(obj, 'a', NULL)
self.assertNotHasAttr(obj, 'a')
self.assertFalse(hasattr(obj, 'a'))
self.assertRaises(AttributeError, xsetattr, obj, 'b', NULL)
self.assertRaises(RuntimeError, xsetattr, obj, 'evil', NULL)

Expand All @@ -294,7 +294,7 @@ def test_object_setattrstring(self):

# PyObject_SetAttrString(obj, attr_name, NULL) removes the attribute
setattrstring(obj, b'a', NULL)
self.assertNotHasAttr(obj, 'a')
self.assertFalse(hasattr(obj, 'a'))
self.assertRaises(AttributeError, setattrstring, obj, b'b', NULL)
self.assertRaises(RuntimeError, setattrstring, obj, b'evil', NULL)

Expand All @@ -311,10 +311,10 @@ def test_object_delattr(self):
obj.a = 1
setattr(obj, '\U0001f40d', 2)
xdelattr(obj, 'a')
self.assertNotHasAttr(obj, 'a')
self.assertFalse(hasattr(obj, 'a'))
self.assertRaises(AttributeError, xdelattr, obj, 'b')
xdelattr(obj, '\U0001f40d')
self.assertNotHasAttr(obj, '\U0001f40d')
self.assertFalse(hasattr(obj, '\U0001f40d'))

self.assertRaises(AttributeError, xdelattr, 42, 'numerator')
self.assertRaises(RuntimeError, xdelattr, obj, 'evil')
Expand All @@ -328,10 +328,10 @@ def test_object_delattrstring(self):
obj.a = 1
setattr(obj, '\U0001f40d', 2)
delattrstring(obj, b'a')
self.assertNotHasAttr(obj, 'a')
self.assertFalse(hasattr(obj, 'a'))
self.assertRaises(AttributeError, delattrstring, obj, b'b')
delattrstring(obj, '\U0001f40d'.encode())
self.assertNotHasAttr(obj, '\U0001f40d')
self.assertFalse(hasattr(obj, '\U0001f40d'))

self.assertRaises(AttributeError, delattrstring, 42, b'numerator')
self.assertRaises(RuntimeError, delattrstring, obj, b'evil')
Expand Down
Loading

0 comments on commit b341ef3

Please sign in to comment.