From b341ef319e551a1743f958d5627e5e3851adac2e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 20 Jan 2025 12:30:14 +0200 Subject: [PATCH] Move some changes out to other PRs. --- Lib/test/test_asyncio/test_base_events.py | 2 +- Lib/test/test_asyncio/test_events.py | 5 ++-- Lib/test/test_asyncio/test_futures.py | 2 +- Lib/test/test_asyncio/test_locks.py | 12 +++++----- Lib/test/test_asyncio/test_protocols.py | 10 ++++---- Lib/test/test_asyncio/test_queues.py | 2 +- Lib/test/test_asyncio/test_sock_lowlevel.py | 14 +++++------ Lib/test/test_asyncio/test_streams.py | 18 +++++++------- Lib/test/test_asyncio/test_tasks.py | 4 ++-- Lib/test/test_asyncio/test_windows_utils.py | 4 ++-- Lib/test/test_capi/test_abstract.py | 12 +++++----- Lib/test/test_capi/test_misc.py | 14 ++++++----- Lib/test/test_capi/test_sys.py | 4 ++-- .../test_ctypes/test_c_simple_type_meta.py | 16 ++++++------- Lib/test/test_ctypes/test_loading.py | 2 +- Lib/test/test_ctypes/test_repr.py | 6 ++--- Lib/test/test_email/test_contentmanager.py | 2 +- Lib/test/test_email/test_defect_handling.py | 4 ++-- Lib/test/test_email/test_email.py | 18 +++++++------- Lib/test/test_http_cookiejar.py | 2 +- Lib/test/test_http_cookies.py | 2 +- Lib/test/test_httplib.py | 24 ++++++++++--------- Lib/test/test_httpservers.py | 13 +++++----- Lib/test/test_import/__init__.py | 14 +++++------ .../extension/test_path_hook.py | 2 +- Lib/test/test_importlib/frozen/test_loader.py | 6 ++--- .../test_importlib/import_/test_caching.py | 4 ++-- .../test_importlib/import_/test_fromlist.py | 16 ++++++------- .../test_importlib/import_/test_meta_path.py | 2 +- Lib/test/test_importlib/import_/test_path.py | 2 +- .../import_/test_relative_imports.py | 6 ++--- .../test_importlib/resources/test_path.py | 2 +- Lib/test/test_importlib/source/test_finder.py | 8 +++---- .../test_importlib/source/test_path_hook.py | 6 ++--- Lib/test/test_importlib/test_abc.py | 12 ++++++---- Lib/test/test_importlib/test_api.py | 5 ++-- Lib/test/test_importlib/test_lazy.py | 4 ++-- .../test_importlib/test_namespace_pkgs.py | 4 ++-- Lib/test/test_importlib/test_pkg_import.py | 2 +- Lib/test/test_importlib/test_spec.py | 8 +++---- Lib/test/test_importlib/test_util.py | 2 +- Lib/test/test_mailbox.py | 6 ++--- Lib/test/test_poplib.py | 6 ++--- Lib/test/test_urllib.py | 8 +++++-- Lib/test/test_urllib2.py | 12 +++++----- Lib/test/test_urllib2_localnet.py | 3 ++- Lib/test/test_urllibnet.py | 3 ++- Lib/test/test_urlparse.py | 7 +++--- 48 files changed, 180 insertions(+), 162 deletions(-) diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index 102c9be0ecf031..1e063c1352ecb9 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -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( diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index ada049e9c7d387..ed75b909317357 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -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() @@ -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() diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py index 01d6230e6dd9a3..84b44011b9a844 100644 --- a/Lib/test/test_asyncio/test_futures.py +++ b/Lib/test/test_asyncio/test_futures.py @@ -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') diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py index 3bb3e5c4ca0658..aabfcd418829b2 100644 --- a/Lib/test/test_asyncio/test_locks.py +++ b/Lib/test/test_asyncio/test_locks.py @@ -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): @@ -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()) @@ -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))) diff --git a/Lib/test/test_asyncio/test_protocols.py b/Lib/test/test_asyncio/test_protocols.py index 4484a031988533..a8627b5b5b87f2 100644 --- a/Lib/test/test_asyncio/test_protocols.py +++ b/Lib/test/test_asyncio/test_protocols.py @@ -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() @@ -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() @@ -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() @@ -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() @@ -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__': diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py index 090b9774c2289f..1a8d604faea1fd 100644 --- a/Lib/test/test_asyncio/test_queues.py +++ b/Lib/test/test_asyncio/test_queues.py @@ -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), '') + self.assertTrue( + email.utils.make_msgid().endswith( + '@' + domain + '>')) def test_Generator_linend(self): # Issue 14645. @@ -4126,7 +4128,7 @@ def test_CRLFLF_at_end_of_part(self): "--BOUNDARY--\n" ) msg = email.message_from_string(m) - self.assertEndsWith(msg.get_payload(0).get_payload(), '\r\n') + self.assertTrue(msg.get_payload(0).get_payload().endswith('\r\n')) class Test8BitBytesHandling(TestEmailBase): diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py index 6a3fe41adb74a2..dbf9ce10f76f91 100644 --- a/Lib/test/test_http_cookiejar.py +++ b/Lib/test/test_http_cookiejar.py @@ -1515,7 +1515,7 @@ def test_netscape_example_1(self): h = req.get_header("Cookie") self.assertIn("PART_NUMBER=ROCKET_LAUNCHER_0001", h) self.assertIn("CUSTOMER=WILE_E_COYOTE", h) - self.assertStartsWith(h, "SHIPPING=FEDEX;") + self.assertTrue(h.startswith("SHIPPING=FEDEX;")) def test_netscape_example_2(self): # Second Example transaction sequence: diff --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py index 4ee33dba5d6309..7b3dc0fdaedc3b 100644 --- a/Lib/test/test_http_cookies.py +++ b/Lib/test/test_http_cookies.py @@ -180,7 +180,7 @@ def test_special_attrs(self): C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"') C['Customer']['expires'] = 0 # can't test exact output, it always depends on current date/time - self.assertEndsWith(C.output(), 'GMT') + self.assertTrue(C.output().endswith('GMT')) # loading 'expires' C = cookies.SimpleCookie() diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 90109b2b88f5d8..7a7ec555a2dbbb 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -273,7 +273,7 @@ def test_ipv6host_header(self): sock = FakeSocket('') conn.sock = sock conn.request('GET', '/foo') - self.assertStartsWith(sock.data, expected) + self.assertTrue(sock.data.startswith(expected)) expected = b'GET /foo HTTP/1.1\r\nHost: [2001:102A::]\r\n' \ b'Accept-Encoding: identity\r\n\r\n' @@ -281,7 +281,7 @@ def test_ipv6host_header(self): sock = FakeSocket('') conn.sock = sock conn.request('GET', '/foo') - self.assertStartsWith(sock.data, expected) + self.assertTrue(sock.data.startswith(expected)) expected = b'GET /foo HTTP/1.1\r\nHost: [fe80::]\r\n' \ b'Accept-Encoding: identity\r\n\r\n' @@ -289,7 +289,7 @@ def test_ipv6host_header(self): sock = FakeSocket('') conn.sock = sock conn.request('GET', '/foo') - self.assertStartsWith(sock.data, expected) + self.assertTrue(sock.data.startswith(expected)) expected = b'GET /foo HTTP/1.1\r\nHost: [fe80::]:81\r\n' \ b'Accept-Encoding: identity\r\n\r\n' @@ -297,7 +297,7 @@ def test_ipv6host_header(self): sock = FakeSocket('') conn.sock = sock conn.request('GET', '/foo') - self.assertStartsWith(sock.data, expected) + self.assertTrue(sock.data.startswith(expected)) def test_malformed_headers_coped_with(self): # Issue 19996 @@ -335,9 +335,9 @@ def test_parse_all_octets(self): self.assertIsNotNone(resp.getheader('obs-text')) self.assertIn('obs-text', resp.msg) for folded in (resp.getheader('obs-fold'), resp.msg['obs-fold']): - self.assertStartsWith(folded, 'text') + self.assertTrue(folded.startswith('text')) self.assertIn(' folded with space', folded) - self.assertEndsWith(folded, 'folded with tab') + self.assertTrue(folded.endswith('folded with tab')) def test_invalid_headers(self): conn = client.HTTPConnection('example.com') @@ -1000,7 +1000,8 @@ def test_send_file(self): sock = FakeSocket(body) conn.sock = sock conn.request('GET', '/foo', body) - self.assertStartsWith(sock.data, expected) + self.assertTrue(sock.data.startswith(expected), '%r != %r' % + (sock.data[:len(expected)], expected)) def test_send(self): expected = b'this is a test this is only a test' @@ -1544,7 +1545,7 @@ def mypeek(n=-1): # then unbounded peek p2 = resp.peek() self.assertGreaterEqual(len(p2), len(p)) - self.assertStartsWith(p2, p) + self.assertTrue(p2.startswith(p)) next = resp.read(len(p2)) self.assertEqual(next, p2) else: @@ -1569,7 +1570,7 @@ def _verify_readline(self, readline, expected, limit=5): line = readline(limit) if line and line != b"foo": if len(line) < 5: - self.assertEndsWith(line, b"\n") + self.assertTrue(line.endswith(b"\n")) all.append(line) if not line: break @@ -1764,7 +1765,7 @@ def test_client_constants(self): ] for const in expected: with self.subTest(constant=const): - self.assertHasAttr(client, const) + self.assertTrue(hasattr(client, const)) class SourceAddressTest(TestCase): @@ -2406,7 +2407,8 @@ def test_tunnel_connect_single_send_connection_setup(self): msg=f'unexpected number of send calls: {mock_send.mock_calls}') proxy_setup_data_sent = mock_send.mock_calls[0][1][0] self.assertIn(b'CONNECT destination.com', proxy_setup_data_sent) - self.assertEndsWith(proxy_setup_data_sent, b'\r\n\r\n', + self.assertTrue( + proxy_setup_data_sent.endswith(b'\r\n\r\n'), msg=f'unexpected proxy data sent {proxy_setup_data_sent!r}') def test_connect_put_request(self): diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index ccd60019d07764..1c370dcafa9fea 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -335,7 +335,8 @@ def test_get(self): self.con.request('GET', '/') self.con.getresponse() - self.assertEndsWith(err.getvalue(), '"GET / HTTP/1.1" 200 -\n') + self.assertTrue( + err.getvalue().endswith('"GET / HTTP/1.1" 200 -\n')) def test_err(self): self.con = http.client.HTTPConnection(self.HOST, self.PORT) @@ -346,8 +347,8 @@ def test_err(self): self.con.getresponse() lines = err.getvalue().split('\n') - self.assertEndsWith(lines[0], 'code 404, message File not found') - self.assertEndsWith(lines[1], '"ERROR / HTTP/1.1" 404 -') + self.assertTrue(lines[0].endswith('code 404, message File not found')) + self.assertTrue(lines[1].endswith('"ERROR / HTTP/1.1" 404 -')) class SimpleHTTPServerTestCase(BaseTestCase): @@ -471,7 +472,7 @@ def test_get_dir_redirect_location_domain_injection_bug(self): response = self.request(attack_url) self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) location = response.getheader('Location') - self.assertNotStartsWith(location, '//') + self.assertFalse(location.startswith('//'), msg=location) self.assertEqual(location, expected_location, msg='Expected Location header to start with a single / and ' 'end with a / as this is a directory redirect.') @@ -494,7 +495,7 @@ def test_get_dir_redirect_location_domain_injection_bug(self): # We're just ensuring that the scheme and domain make it through, if # there are or aren't multiple slashes at the start of the path that # follows that isn't important in this Location: header. - self.assertStartsWith(location, 'https://pypi.org/') + self.assertTrue(location.startswith('https://pypi.org/'), msg=location) def test_get(self): #constructs the path relative to the root directory of the HTTPServer @@ -1093,7 +1094,7 @@ def test_extra_space(self): b'Host: dummy\r\n' b'\r\n' ) - self.assertStartsWith(result[0], b'HTTP/1.1 400 ') + self.assertTrue(result[0].startswith(b'HTTP/1.1 400 ')) self.verify_expected_headers(result[1:result.index(b'\r\n')]) self.assertFalse(self.handler.get_called) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 654b9f5bd7ab50..1e706023c795b6 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -539,7 +539,7 @@ def test_import_name_binding(self): import test as x import test.support self.assertIs(x, test, x.__name__) - self.assertHasAttr(test.support, "__file__") + self.assertTrue(hasattr(test.support, "__file__")) # import x.y.z as w binds z as w import test.support as y @@ -610,7 +610,7 @@ def test_file_to_source(self): sys.path.insert(0, os.curdir) try: mod = __import__(TESTFN) - self.assertEndsWith(mod.__file__, '.py') + self.assertTrue(mod.__file__.endswith('.py')) os.remove(source) del sys.modules[TESTFN] make_legacy_pyc(source) @@ -1443,7 +1443,7 @@ def test_UNC_path(self): self.fail("could not import 'test_unc_path' from %r: %r" % (unc, e)) self.assertEqual(mod.testdata, 'test_unc_path') - self.assertStartsWith(mod.__file__, unc) + self.assertTrue(mod.__file__.startswith(unc), mod.__file__) unload("test_unc_path") @@ -1456,7 +1456,7 @@ def tearDown(self): def test_relimport_star(self): # This will import * from .test_import. from .. import relimport - self.assertHasAttr(relimport, "RelativeImportTests") + self.assertTrue(hasattr(relimport, "RelativeImportTests")) def test_issue3221(self): # Note for mergers: the 'absolute' tests from the 2.x branch @@ -1786,7 +1786,7 @@ def test_frozen_importlib_is_bootstrap(self): self.assertIs(mod, _bootstrap) self.assertEqual(mod.__name__, 'importlib._bootstrap') self.assertEqual(mod.__package__, 'importlib') - self.assertEndsWith(mod.__file__, '_bootstrap.py') + self.assertTrue(mod.__file__.endswith('_bootstrap.py'), mod.__file__) def test_frozen_importlib_external_is_bootstrap_external(self): from importlib import _bootstrap_external @@ -1794,7 +1794,7 @@ def test_frozen_importlib_external_is_bootstrap_external(self): self.assertIs(mod, _bootstrap_external) self.assertEqual(mod.__name__, 'importlib._bootstrap_external') self.assertEqual(mod.__package__, 'importlib') - self.assertEndsWith(mod.__file__, '_bootstrap_external.py') + self.assertTrue(mod.__file__.endswith('_bootstrap_external.py'), mod.__file__) def test_there_can_be_only_one(self): # Issue #15386 revealed a tricky loophole in the bootstrapping @@ -2800,7 +2800,7 @@ def check_common(self, loaded): self.assertEqual(mod.__file__, self.FILE) self.assertEqual(mod.__spec__.origin, self.ORIGIN) if not isolated: - self.assertIsSubclass(mod.error, Exception) + self.assertTrue(issubclass(mod.error, Exception)) self.assertEqual(mod.int_const, 1969) self.assertEqual(mod.str_const, 'something different') self.assertIsInstance(mod._module_initialized, float) diff --git a/Lib/test/test_importlib/extension/test_path_hook.py b/Lib/test/test_importlib/extension/test_path_hook.py index 941dcd5432ce46..314a635c77e082 100644 --- a/Lib/test/test_importlib/extension/test_path_hook.py +++ b/Lib/test/test_importlib/extension/test_path_hook.py @@ -21,7 +21,7 @@ def hook(self, entry): def test_success(self): # Path hook should handle a directory where a known extension module # exists. - self.assertHasAttr(self.hook(util.EXTENSIONS.path), 'find_spec') + self.assertTrue(hasattr(self.hook(util.EXTENSIONS.path), 'find_spec')) (Frozen_PathHooksTests, diff --git a/Lib/test/test_importlib/frozen/test_loader.py b/Lib/test/test_importlib/frozen/test_loader.py index c808bb73291a7c..1112c0664ad477 100644 --- a/Lib/test/test_importlib/frozen/test_loader.py +++ b/Lib/test/test_importlib/frozen/test_loader.py @@ -61,7 +61,7 @@ def exec_module(self, name, origname=None): module.main() self.assertTrue(module.initialized) - self.assertHasAttr(module, '__spec__') + self.assertTrue(hasattr(module, '__spec__')) self.assertEqual(module.__spec__.origin, 'frozen') return module, stdout.getvalue() @@ -72,7 +72,7 @@ def test_module(self): for attr, value in check.items(): self.assertEqual(getattr(module, attr), value) self.assertEqual(output, 'Hello world!\n') - self.assertHasAttr(module, '__spec__') + self.assertTrue(hasattr(module, '__spec__')) self.assertEqual(module.__spec__.loader_state.origname, name) def test_package(self): @@ -136,7 +136,7 @@ def test_get_code(self): exec(code, mod.__dict__) with captured_stdout() as stdout: mod.main() - self.assertHasAttr(mod, 'initialized') + self.assertTrue(hasattr(mod, 'initialized')) self.assertEqual(stdout.getvalue(), 'Hello world!\n') def test_get_source(self): diff --git a/Lib/test/test_importlib/import_/test_caching.py b/Lib/test/test_importlib/import_/test_caching.py index 718e7d041b0860..aedf0fd4f9db02 100644 --- a/Lib/test/test_importlib/import_/test_caching.py +++ b/Lib/test/test_importlib/import_/test_caching.py @@ -78,7 +78,7 @@ def test_using_cache_for_assigning_to_attribute(self): with self.create_mock('pkg.__init__', 'pkg.module') as importer: with util.import_state(meta_path=[importer]): module = self.__import__('pkg.module') - self.assertHasAttr(module, 'module') + self.assertTrue(hasattr(module, 'module')) self.assertEqual(id(module.module), id(sys.modules['pkg.module'])) @@ -88,7 +88,7 @@ def test_using_cache_for_fromlist(self): with self.create_mock('pkg.__init__', 'pkg.module') as importer: with util.import_state(meta_path=[importer]): module = self.__import__('pkg', fromlist=['module']) - self.assertHasAttr(module, 'module') + self.assertTrue(hasattr(module, 'module')) self.assertEqual(id(module.module), id(sys.modules['pkg.module'])) diff --git a/Lib/test/test_importlib/import_/test_fromlist.py b/Lib/test/test_importlib/import_/test_fromlist.py index feccc7be09a98c..4b4b9bc3f5e04a 100644 --- a/Lib/test/test_importlib/import_/test_fromlist.py +++ b/Lib/test/test_importlib/import_/test_fromlist.py @@ -63,7 +63,7 @@ def test_nonexistent_object(self): with util.import_state(meta_path=[importer]): module = self.__import__('module', fromlist=['non_existent']) self.assertEqual(module.__name__, 'module') - self.assertNotHasAttr(module, 'non_existent') + self.assertFalse(hasattr(module, 'non_existent')) def test_module_from_package(self): # [module] @@ -71,7 +71,7 @@ def test_module_from_package(self): with util.import_state(meta_path=[importer]): module = self.__import__('pkg', fromlist=['module']) self.assertEqual(module.__name__, 'pkg') - self.assertHasAttr(module, 'module') + self.assertTrue(hasattr(module, 'module')) self.assertEqual(module.module.__name__, 'pkg.module') def test_nonexistent_from_package(self): @@ -79,7 +79,7 @@ def test_nonexistent_from_package(self): with util.import_state(meta_path=[importer]): module = self.__import__('pkg', fromlist=['non_existent']) self.assertEqual(module.__name__, 'pkg') - self.assertNotHasAttr(module, 'non_existent') + self.assertFalse(hasattr(module, 'non_existent')) def test_module_from_package_triggers_ModuleNotFoundError(self): # If a submodule causes an ModuleNotFoundError because it tries @@ -107,7 +107,7 @@ def basic_star_test(self, fromlist=['*']): mock['pkg'].__all__ = ['module'] module = self.__import__('pkg', fromlist=fromlist) self.assertEqual(module.__name__, 'pkg') - self.assertHasAttr(module, 'module') + self.assertTrue(hasattr(module, 'module')) self.assertEqual(module.module.__name__, 'pkg.module') def test_using_star(self): @@ -125,8 +125,8 @@ def test_star_with_others(self): mock['pkg'].__all__ = ['module1'] module = self.__import__('pkg', fromlist=['module2', '*']) self.assertEqual(module.__name__, 'pkg') - self.assertHasAttr(module, 'module1') - self.assertHasAttr(module, 'module2') + self.assertTrue(hasattr(module, 'module1')) + self.assertTrue(hasattr(module, 'module2')) self.assertEqual(module.module1.__name__, 'pkg.module1') self.assertEqual(module.module2.__name__, 'pkg.module2') @@ -136,7 +136,7 @@ def test_nonexistent_in_all(self): importer['pkg'].__all__ = ['non_existent'] module = self.__import__('pkg', fromlist=['*']) self.assertEqual(module.__name__, 'pkg') - self.assertNotHasAttr(module, 'non_existent') + self.assertFalse(hasattr(module, 'non_existent')) def test_star_in_all(self): with util.mock_spec('pkg.__init__') as importer: @@ -144,7 +144,7 @@ def test_star_in_all(self): importer['pkg'].__all__ = ['*'] module = self.__import__('pkg', fromlist=['*']) self.assertEqual(module.__name__, 'pkg') - self.assertNotHasAttr(module, '*') + self.assertFalse(hasattr(module, '*')) def test_invalid_type(self): with util.mock_spec('pkg.__init__') as importer: diff --git a/Lib/test/test_importlib/import_/test_meta_path.py b/Lib/test/test_importlib/import_/test_meta_path.py index 4c00f60681acf1..8689017ba43112 100644 --- a/Lib/test/test_importlib/import_/test_meta_path.py +++ b/Lib/test/test_importlib/import_/test_meta_path.py @@ -43,7 +43,7 @@ def test_empty(self): self.assertIsNone(importlib._bootstrap._find_spec('nothing', None)) self.assertEqual(len(w), 1) - self.assertIsSubclass(w[-1].category, ImportWarning) + self.assertTrue(issubclass(w[-1].category, ImportWarning)) (Frozen_CallingOrder, diff --git a/Lib/test/test_importlib/import_/test_path.py b/Lib/test/test_importlib/import_/test_path.py index bcd5ad6e76005a..89b52fbd1e1aff 100644 --- a/Lib/test/test_importlib/import_/test_path.py +++ b/Lib/test/test_importlib/import_/test_path.py @@ -80,7 +80,7 @@ def test_empty_path_hooks(self): self.assertIsNone(self.find('os')) self.assertIsNone(sys.path_importer_cache[path_entry]) self.assertEqual(len(w), 1) - self.assertIsSubclass(w[-1].category, ImportWarning) + self.assertTrue(issubclass(w[-1].category, ImportWarning)) def test_path_importer_cache_empty_string(self): # The empty string should create a finder using the cwd. diff --git a/Lib/test/test_importlib/import_/test_relative_imports.py b/Lib/test/test_importlib/import_/test_relative_imports.py index e535d119763148..99c24f1fd9487c 100644 --- a/Lib/test/test_importlib/import_/test_relative_imports.py +++ b/Lib/test/test_importlib/import_/test_relative_imports.py @@ -81,7 +81,7 @@ def callback(global_): self.__import__('pkg') # For __import__(). module = self.__import__('', global_, fromlist=['mod2'], level=1) self.assertEqual(module.__name__, 'pkg') - self.assertHasAttr(module, 'mod2') + self.assertTrue(hasattr(module, 'mod2')) self.assertEqual(module.mod2.attr, 'pkg.mod2') self.relative_import_test(create, globals_, callback) @@ -107,7 +107,7 @@ def callback(global_): module = self.__import__('', global_, fromlist=['module'], level=1) self.assertEqual(module.__name__, 'pkg') - self.assertHasAttr(module, 'module') + self.assertTrue(hasattr(module, 'module')) self.assertEqual(module.module.attr, 'pkg.module') self.relative_import_test(create, globals_, callback) @@ -131,7 +131,7 @@ def callback(global_): module = self.__import__('', global_, fromlist=['subpkg2'], level=2) self.assertEqual(module.__name__, 'pkg') - self.assertHasAttr(module, 'subpkg2') + self.assertTrue(hasattr(module, 'subpkg2')) self.assertEqual(module.subpkg2.attr, 'pkg.subpkg2.__init__') self.relative_import_test(create, globals_, callback) diff --git a/Lib/test/test_importlib/resources/test_path.py b/Lib/test/test_importlib/resources/test_path.py index 903911f57b3306..378dc7a2baeb23 100644 --- a/Lib/test/test_importlib/resources/test_path.py +++ b/Lib/test/test_importlib/resources/test_path.py @@ -20,7 +20,7 @@ def test_reading(self): target = resources.files(self.data) / 'utf-8.file' with resources.as_file(target) as path: self.assertIsInstance(path, pathlib.Path) - self.assertEndsWith(path.name, "utf-8.file") + self.assertTrue(path.name.endswith("utf-8.file"), repr(path)) self.assertEqual('Hello, UTF-8 world!\n', path.read_text(encoding='utf-8')) diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py index 4de736a6bf3b2d..8c06c4da1f5cba 100644 --- a/Lib/test/test_importlib/source/test_finder.py +++ b/Lib/test/test_importlib/source/test_finder.py @@ -73,7 +73,7 @@ def run_test(self, test, create=None, *, compile_=None, unlink=None): if error.errno != errno.ENOENT: raise loader = self.import_(mapping['.root'], test) - self.assertHasAttr(loader, 'load_module') + self.assertTrue(hasattr(loader, 'load_module')) return loader def test_module(self): @@ -100,7 +100,7 @@ def test_module_in_package(self): with util.create_modules('pkg.__init__', 'pkg.sub') as mapping: pkg_dir = os.path.dirname(mapping['pkg.__init__']) loader = self.import_(pkg_dir, 'pkg.sub') - self.assertHasAttr(loader, 'load_module') + self.assertTrue(hasattr(loader, 'load_module')) # [sub package] def test_package_in_package(self): @@ -108,7 +108,7 @@ def test_package_in_package(self): with context as mapping: pkg_dir = os.path.dirname(mapping['pkg.__init__']) loader = self.import_(pkg_dir, 'pkg.sub') - self.assertHasAttr(loader, 'load_module') + self.assertTrue(hasattr(loader, 'load_module')) # [package over modules] def test_package_over_module(self): @@ -129,7 +129,7 @@ def test_empty_string_for_dir(self): file.write("# test file for importlib") try: loader = self._find(finder, 'mod', loader_only=True) - self.assertHasAttr(loader, 'load_module') + self.assertTrue(hasattr(loader, 'load_module')) finally: os.unlink('mod.py') diff --git a/Lib/test/test_importlib/source/test_path_hook.py b/Lib/test/test_importlib/source/test_path_hook.py index 6e1c23e6a9842b..f274330e0b333b 100644 --- a/Lib/test/test_importlib/source/test_path_hook.py +++ b/Lib/test/test_importlib/source/test_path_hook.py @@ -15,12 +15,12 @@ def path_hook(self): def test_success(self): with util.create_modules('dummy') as mapping: - self.assertHasAttr(self.path_hook()(mapping['.root']), - 'find_spec') + self.assertTrue(hasattr(self.path_hook()(mapping['.root']), + 'find_spec')) def test_empty_string(self): # The empty string represents the cwd. - self.assertHasAttr(self.path_hook()(''), 'find_spec') + self.assertTrue(hasattr(self.path_hook()(''), 'find_spec')) (Frozen_PathHookTest, diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py index b1ab52f966ffdb..92a77e079e57e7 100644 --- a/Lib/test/test_importlib/test_abc.py +++ b/Lib/test/test_importlib/test_abc.py @@ -43,12 +43,14 @@ def setUp(self): def test_subclasses(self): # Test that the expected subclasses inherit. for subclass in self.subclasses: - self.assertIsSubclass(subclass, self.__test) + self.assertTrue(issubclass(subclass, self.__test), + "{0} is not a subclass of {1}".format(subclass, self.__test)) def test_superclasses(self): # Test that the class inherits from the expected superclasses. for superclass in self.superclasses: - self.assertIsSubclass(self.__test, superclass) + self.assertTrue(issubclass(self.__test, superclass), + "{0} is not a superclass of {1}".format(superclass, self.__test)) class MetaPathFinder(InheritanceTests): @@ -422,14 +424,14 @@ def test_source_to_code_source(self): # Since compile() can handle strings, so should source_to_code(). source = 'attr = 42' module = self.source_to_module(source) - self.assertHasAttr(module, 'attr') + self.assertTrue(hasattr(module, 'attr')) self.assertEqual(module.attr, 42) def test_source_to_code_bytes(self): # Since compile() can handle bytes, so should source_to_code(). source = b'attr = 42' module = self.source_to_module(source) - self.assertHasAttr(module, 'attr') + self.assertTrue(hasattr(module, 'attr')) self.assertEqual(module.attr, 42) def test_source_to_code_path(self): @@ -763,7 +765,7 @@ def test_package_settings(self): warnings.simplefilter('ignore', DeprecationWarning) module = self.loader.load_module(self.name) self.verify_module(module) - self.assertNotHasAttr(module, '__path__') + self.assertFalse(hasattr(module, '__path__')) def test_get_source_encoding(self): # Source is considered encoded in UTF-8 by default unless otherwise diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index 1bc531a2fe34e7..6035b2ca72efb9 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -430,7 +430,8 @@ def test_everyone_has___loader__(self): for name, module in sys.modules.items(): if isinstance(module, types.ModuleType): with self.subTest(name=name): - self.assertHasAttr(module, '__loader__') + self.assertTrue(hasattr(module, '__loader__'), + '{!r} lacks a __loader__ attribute'.format(name)) if self.machinery.BuiltinImporter.find_spec(name): self.assertIsNot(module.__loader__, None) elif self.machinery.FrozenImporter.find_spec(name): @@ -440,7 +441,7 @@ def test_everyone_has___spec__(self): for name, module in sys.modules.items(): if isinstance(module, types.ModuleType): with self.subTest(name=name): - self.assertHasAttr(module, '__spec__') + self.assertTrue(hasattr(module, '__spec__')) if self.machinery.BuiltinImporter.find_spec(name): self.assertIsNot(module.__spec__, None) elif self.machinery.FrozenImporter.find_spec(name): diff --git a/Lib/test/test_importlib/test_lazy.py b/Lib/test/test_importlib/test_lazy.py index e48fad8898f0ef..5c6e0303528906 100644 --- a/Lib/test/test_importlib/test_lazy.py +++ b/Lib/test/test_importlib/test_lazy.py @@ -125,12 +125,12 @@ def test_delete_eventual_attr(self): # Deleting an attribute should stay deleted. module = self.new_module() del module.attr - self.assertNotHasAttr(module, 'attr') + self.assertFalse(hasattr(module, 'attr')) def test_delete_preexisting_attr(self): module = self.new_module() del module.__name__ - self.assertNotHasAttr(module, '__name__') + self.assertFalse(hasattr(module, '__name__')) def test_module_substitution_error(self): with test_util.uncache(TestingImporter.module_name): diff --git a/Lib/test/test_importlib/test_namespace_pkgs.py b/Lib/test/test_importlib/test_namespace_pkgs.py index 6ca0978f9bca69..cbbdada3b010a7 100644 --- a/Lib/test/test_importlib/test_namespace_pkgs.py +++ b/Lib/test/test_importlib/test_namespace_pkgs.py @@ -80,7 +80,7 @@ def test_cant_import_other(self): def test_simple_repr(self): import foo.one - self.assertStartsWith(repr(foo), "