Fix test assertions that never compared against the expected value (#161774) Co-authored-by: Stan Ulbrych <stan@python.org>
diff --git a/Lib/test/test_capi/test_function.py b/Lib/test/test_capi/test_function.py index 9a07e31..5024c58 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 e3cb5db..4edf819 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 337801b..8f0a61b 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 447f847..4484749 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 a0a1196..2b41ef3 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 274c6aca..0c41858 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 10ecdd3..f393e67 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 aff66c8..788547c 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 b0e3cba..19a9f98 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 d4b4a13..a4ddc8b 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 e6525c4..7fecbb6 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 2f8fef2..5e09872 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)