https://github.com/python/cpython/commit/aecef70048dc56c7ac270c7d9e3c112347ea347e commit: aecef70048dc56c7ac270c7d9e3c112347ea347e branch: main author: Andrés Delfino <[email protected]> committer: StanFromIreland <[email protected]> date: 2026-11-11T18:54:18Z summary:
Fix test assertions that never compared against the expected value (#161774) Co-authored-by: Stan Ulbrych <[email protected]> files: M Lib/test/test_capi/test_function.py M Lib/test/test_ctypes/test_memfunctions.py M Lib/test/test_ctypes/test_returnfuncptrs.py M Lib/test/test_enum.py M Lib/test/test_frame.py M Lib/test/test_minidom.py M Lib/test/test_optparse.py M Lib/test/test_pathlib/test_pathlib.py M Lib/test/test_ssl.py M Lib/test/test_stringprep.py M Lib/test/test_ttk_textonly.py M Lib/test/test_zipfile/test_core.py diff --git a/Lib/test/test_capi/test_function.py b/Lib/test/test_capi/test_function.py index 9a07e3106f3a22a..5024c58679bb2b9 100644 --- a/Lib/test/test_capi/test_function.py +++ b/Lib/test/test_capi/test_function.py @@ -235,7 +235,7 @@ def inner(arg5, arg6): self.assertEqual(len(closure), len(func.__code__.co_freevars)) for cell in closure: self.assertIsInstance(cell, CellType) - self.assertTrue(closure[0].cell_contents, 5) + self.assertEqual(closure[0].cell_contents, 5) func = with_two_levels(1, 2)(3, 4) closure = _testcapi.function_get_closure(func) diff --git a/Lib/test/test_ctypes/test_memfunctions.py b/Lib/test/test_ctypes/test_memfunctions.py index e3cb5db775ef622..4edf819ca98ebaa 100644 --- a/Lib/test/test_ctypes/test_memfunctions.py +++ b/Lib/test/test_ctypes/test_memfunctions.py @@ -60,7 +60,7 @@ def test_cast(self): @support.refcount_test def test_string_at(self): s = string_at(b"foo bar") - self.assertTrue(s, "foo bar") + self.assertEqual(s, b"foo bar") self.assertEqual(string_at(b"foo bar", 7), b"foo bar") self.assertEqual(string_at(b"foo bar", 3), b"foo") diff --git a/Lib/test/test_ctypes/test_returnfuncptrs.py b/Lib/test/test_ctypes/test_returnfuncptrs.py index 337801b226ab06b..8f0a61be4c5a80b 100644 --- a/Lib/test/test_ctypes/test_returnfuncptrs.py +++ b/Lib/test/test_ctypes/test_returnfuncptrs.py @@ -28,7 +28,7 @@ def test_without_prototype(self): # _CFuncPtr instances are now callable with an integer argument # which denotes a function address: strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(addr) - self.assertTrue(strchr(b"abcdef", b"b"), "bcdef") + self.assertEqual(strchr(b"abcdef", b"b"), b"bcdef") self.assertEqual(strchr(b"abcdef", b"x"), None) self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) self.assertRaises(TypeError, strchr, b"abcdef") @@ -38,7 +38,7 @@ def test_from_dll(self): # _CFuncPtr instances are now callable with a tuple argument # which denotes a function name and a dll: strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(("my_strchr", dll)) - self.assertTrue(strchr(b"abcdef", b"b"), "bcdef") + self.assertEqual(strchr(b"abcdef", b"b"), b"bcdef") self.assertEqual(strchr(b"abcdef", b"x"), None) self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) self.assertRaises(TypeError, strchr, b"abcdef") @@ -57,7 +57,7 @@ def __getitem__(self, key): # which denotes a function name and a dll: strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)( BadSequence(("my_strchr", CDLL(_ctypes_test.__file__)))) - self.assertTrue(strchr(b"abcdef", b"b"), "bcdef") + self.assertEqual(strchr(b"abcdef", b"b"), b"bcdef") self.assertEqual(strchr(b"abcdef", b"x"), None) self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) self.assertRaises(TypeError, strchr, b"abcdef") diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 447f847f33da938..4484749eac449e3 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -1032,7 +1032,7 @@ class OpenXYZ(self.enum_type): self.assertIs(~(Y|Z), OpenXYZ(28)) self.assertIs(~(X|Y|Z), OpenXYZ(24)) self.assertIs(~XYZ_MASK, OpenXYZ(0)) - self.assertTrue(~OpenXYZ(0), XYZ_MASK) + self.assertIs(~OpenXYZ(0), XYZ_MASK) else: self.assertIs(~X, Y|Z) self.assertIs(~Y, X|Z) @@ -1045,7 +1045,7 @@ class OpenXYZ(self.enum_type): self.assertIs(~(Y|Z), X) self.assertIs(~(X|Y|Z), OpenXYZ(0)) self.assertIs(~XYZ_MASK, OpenXYZ(0)) - self.assertTrue(~OpenXYZ(0), (X|Y|Z)) + self.assertIs(~OpenXYZ(0), (X|Y|Z)) def test_assigned_negative_value(self): class X(self.enum_type): @@ -1895,7 +1895,7 @@ class Season(Enum): @reraise_if_not_enum(Name) def test_subclassing(self): self.assertEqual(Name.BDFL, 'Guido van Rossum') - self.assertTrue(Name.BDFL, Name('Guido van Rossum')) + self.assertIs(Name.BDFL, Name('Guido van Rossum')) self.assertIs(Name.BDFL, getattr(Name, 'BDFL')) test_pickle_dump_load(self.assertIs, Name.BDFL) diff --git a/Lib/test/test_frame.py b/Lib/test/test_frame.py index a0a11966ebf3c17..2b41ef33a30b446 100644 --- a/Lib/test/test_frame.py +++ b/Lib/test/test_frame.py @@ -867,13 +867,13 @@ def PyFrame_GetLocals(frame: ctypes.py_object) -> ctypes.py_object: pass frame_locals = PyEval_GetFrameLocals() - self.assertTrue(type(frame_locals), dict) + self.assertIs(type(frame_locals), dict) self.assertEqual(frame_locals['x'], 1) frame_locals['x'] = 2 self.assertEqual(x, 1) frame_globals = PyEval_GetFrameGlobals() - self.assertTrue(type(frame_globals), dict) + self.assertIs(type(frame_globals), dict) self.assertIs(frame_globals, globals()) frame_builtins = PyEval_GetFrameBuiltins() @@ -881,7 +881,7 @@ def PyFrame_GetLocals(frame: ctypes.py_object) -> ctypes.py_object: frame = sys._getframe() f_locals = PyFrame_GetLocals(frame) - self.assertTrue(f_locals['x'], 1) + self.assertEqual(f_locals['x'], 1) f_locals['x'] = 2 self.assertEqual(x, 2) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 274c6acab4a6512..0c418587afe8ed2 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -1274,7 +1274,7 @@ def testCloneElementDeep(self): self.assertEqual(len(clone.childNodes), 1) self.assertEqual(clone.childNodes.length, 1) self.assertIsNone(clone.parentNode) - self.assertTrue(clone.toxml(), '<doc attr="value"><foo/></doc>') + self.assertEqual(clone.toxml(), '<doc attr="value"><foo/></doc>') dom.unlink() def testCloneDocumentShallow(self): diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py index 10ecdd3bccc23f7..f393e67ecbff594 100644 --- a/Lib/test/test_optparse.py +++ b/Lib/test/test_optparse.py @@ -1018,7 +1018,7 @@ def test_group_manipulate(self): description="Some more options") group.set_title("Bacon") group.add_option("--bacon", type="int") - self.assertTrue(self.parser.get_option_group("--bacon"), group) + self.assertIs(self.parser.get_option_group("--bacon"), group) # -- Test extending and parser.parse_args() ---------------------------- diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index aff66c8efedbbc0..788547c49e43e33 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -1697,8 +1697,8 @@ def test_move_dir(self): self.assertEqual(target.joinpath('dirD', 'fileD').read_text(), "this is file D\n") self.assertTrue(target.joinpath('fileC').is_file()) - self.assertTrue(target.joinpath('fileC').read_text(), - "this is file C\n") + self.assertEqual(target.joinpath('fileC').read_text(), + "this is file C\n") @patch_replace def test_move_dir_other_fs(self): diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index b0e3cbaa548e8d5..19a9f98c316ab3a 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -4217,8 +4217,6 @@ def test_ecc_cert(self): s.connect((HOST, server.port)) cert = s.getpeercert() self.assertTrue(cert, "Can't get peer certificate.") - cipher = s.cipher()[0].split('-') - self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA')) @unittest.skipUnless(IS_OPENSSL_3_0_0, "test requires RFC 5280 check added in OpenSSL 3.0+") @@ -4276,7 +4274,7 @@ def test_dual_rsa_ecc(self): cert = s.getpeercert() self.assertTrue(cert, "Can't get peer certificate.") cipher = s.cipher()[0].split('-') - self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA')) + self.assertEqual(cipher[:2], ['ECDHE', 'ECDSA']) def test_check_hostname_idn(self, warnings_filters=True): if support.verbose: diff --git a/Lib/test/test_stringprep.py b/Lib/test/test_stringprep.py index d4b4a13d0de2645..a4ddc8b33e2570b 100644 --- a/Lib/test/test_stringprep.py +++ b/Lib/test/test_stringprep.py @@ -13,11 +13,11 @@ def test(self): self.assertTrue(in_table_b1("\u00ad")) self.assertFalse(in_table_b1("\u00ae")) - self.assertTrue(map_table_b2("\u0041"), "\u0061") - self.assertTrue(map_table_b2("\u0061"), "\u0061") + self.assertEqual(map_table_b2("\u0041"), "\u0061") + self.assertEqual(map_table_b2("\u0061"), "\u0061") - self.assertTrue(map_table_b3("\u0041"), "\u0061") - self.assertTrue(map_table_b3("\u0061"), "\u0061") + self.assertEqual(map_table_b3("\u0041"), "\u0061") + self.assertEqual(map_table_b3("\u0061"), "\u0061") self.assertTrue(in_table_c11("\u0020")) self.assertFalse(in_table_c11("\u0021")) diff --git a/Lib/test/test_ttk_textonly.py b/Lib/test/test_ttk_textonly.py index e6525c4d6c69822..7fecbb6305442be 100644 --- a/Lib/test/test_ttk_textonly.py +++ b/Lib/test/test_ttk_textonly.py @@ -169,7 +169,7 @@ def test_format_mapdict(self): def test_format_elemcreate(self): - self.assertTrue(ttk._format_elemcreate(None), (None, ())) + self.assertEqual(ttk._format_elemcreate(None), ((),)) ## Testing type = image # image type expects at least an image name, so this should raise diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index 2f8fef2a006c381..5e098720df77010 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -5607,14 +5607,14 @@ def test_write_dir(self): self.assertEqual(zinfo.external_attr, (mode << 16) | 0x10) zipf.write(dirpath, "y") zinfo = zipf.filelist[1] - self.assertTrue(zinfo.filename, "y/") + self.assertEqual(zinfo.filename, "y/") self.assertEqual(zinfo.external_attr, (mode << 16) | 0x10) with zipfile.ZipFile(TESTFN, "r") as zipf: zinfo = zipf.filelist[0] self.assertEndsWith(zinfo.filename, "/x/") self.assertEqual(zinfo.external_attr, (mode << 16) | 0x10) zinfo = zipf.filelist[1] - self.assertTrue(zinfo.filename, "y/") + self.assertEqual(zinfo.filename, "y/") self.assertEqual(zinfo.external_attr, (mode << 16) | 0x10) target = os.path.join(TESTFN2, "target") os.mkdir(target) _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
