From 3d1dd32a9feb548988f1ae17b029e5ab23250e46 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Mon, 9 Jul 2018 13:02:59 +0500 Subject: [PATCH 1/2] Fixed several assertTrue() that were intended to be assertEqual(). --- Lib/ctypes/test/test_as_parameter.py | 2 +- Lib/test/test_pkg.py | 2 +- Lib/test/test_socket.py | 2 +- Lib/test/test_support.py | 2 +- Lib/test/test_tokenize.py | 2 +- Lib/test/test_warnings/__init__.py | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/ctypes/test/test_as_parameter.py b/Lib/ctypes/test/test_as_parameter.py index a2640575a07452e..ed4159f79495959 100644 --- a/Lib/ctypes/test/test_as_parameter.py +++ b/Lib/ctypes/test/test_as_parameter.py @@ -24,7 +24,7 @@ def test_wchar_parm(self): f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double] result = f(self.wrap(1), self.wrap("x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0)) self.assertEqual(result, 139) - self.assertTrue(type(result), int) + self.assertEqual(type(result), int) def test_pointers(self): f = dll._testfunc_p_p diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index 532e8fe6d0d8860..8130eab50a934e0 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -138,7 +138,7 @@ def test_2(self): s = """ from t2 import * - self.assertTrue(dir(), ['self', 'sub']) + self.assertEqual(dir(), ['self', 'sub']) """ self.run_code(s) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index f377ebcb27b2bf2..4f3c4774e40ffc5 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -5843,7 +5843,7 @@ def test_aes_cbc(self): op=socket.ALG_OP_ENCRYPT, iv=iv) enc = op.recv(msglen * multiplier) self.assertEqual(len(enc), msglen * multiplier) - self.assertTrue(enc[:msglen], ciphertext) + self.assertEqual(enc[:msglen], ciphertext) op, _ = algo.accept() with op: diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 89f1fbfb6c2b529..7870e940a46e6ce 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -264,7 +264,7 @@ def test_temp_cwd(self): with support.temp_cwd(name=TESTFN): self.assertEqual(os.path.basename(os.getcwd()), TESTFN) self.assertFalse(os.path.exists(TESTFN)) - self.assertTrue(os.path.basename(os.getcwd()), here) + self.assertEqual(os.getcwd(), here) def test_temp_cwd__name_none(self): diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index f68580ccfb7c63c..ff1447954943d94 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -1360,7 +1360,7 @@ def mock_readline(): tokenize_module.detect_encoding = orig_detect_encoding tokenize_module._tokenize = orig__tokenize - self.assertTrue(encoding_used, encoding) + self.assertEqual(encoding_used, encoding) def test_oneline_defs(self): buf = [] diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 87f929f3147885c..3a8805df9e120d0 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -149,9 +149,9 @@ def test_always(self): self.module.filterwarnings("always", category=UserWarning) message = "FilterTests.test_always" self.module.warn(message, UserWarning) - self.assertTrue(message, w[-1].message) + self.assertEqual(message, w[-1].message.args[0]) self.module.warn(message, UserWarning) - self.assertTrue(w[-1].message, message) + self.assertEqual(w[-1].message.args[0], message) def test_always_after_default(self): with original_warnings.catch_warnings(record=True, From 5fa1f94a2a1553f815f61f234d961df3deafefc6 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Mon, 9 Jul 2018 17:59:14 +0500 Subject: [PATCH 2/2] Made requested changes. --- Lib/ctypes/test/test_as_parameter.py | 2 +- Lib/test/test_warnings/__init__.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/ctypes/test/test_as_parameter.py b/Lib/ctypes/test/test_as_parameter.py index ed4159f79495959..f9d27cb89d341b9 100644 --- a/Lib/ctypes/test/test_as_parameter.py +++ b/Lib/ctypes/test/test_as_parameter.py @@ -24,7 +24,7 @@ def test_wchar_parm(self): f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double] result = f(self.wrap(1), self.wrap("x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0)) self.assertEqual(result, 139) - self.assertEqual(type(result), int) + self.assertIs(type(result), int) def test_pointers(self): f = dll._testfunc_p_p diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 3a8805df9e120d0..a4775d03f556569 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -148,9 +148,13 @@ def test_always(self): self.module.resetwarnings() self.module.filterwarnings("always", category=UserWarning) message = "FilterTests.test_always" - self.module.warn(message, UserWarning) - self.assertEqual(message, w[-1].message.args[0]) - self.module.warn(message, UserWarning) + def f(): + self.module.warn(message, UserWarning) + f() + self.assertEqual(len(w), 1) + self.assertEqual(w[-1].message.args[0], message) + f() + self.assertEqual(len(w), 2) self.assertEqual(w[-1].message.args[0], message) def test_always_after_default(self):