[Python-checkins] Fixed several assertTrue() that were intended to be assertEqual(). (GH-8191)

Serhiy Storchaka webhook-mailer at python.org
Mon Jul 9 11:25:59 EDT 2018


https://github.com/python/cpython/commit/b796e7dcdc24ff7ec53044af041254c83a8ace21
commit: b796e7dcdc24ff7ec53044af041254c83a8ace21
branch: master
author: Sergey Fedoseev <fedoseev.sergey at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2018-07-09T18:25:55+03:00
summary:

Fixed several assertTrue() that were intended to be assertEqual(). (GH-8191)

Fixed also testing the "always" warning filter.

files:
M Lib/ctypes/test/test_as_parameter.py
M Lib/test/test_pkg.py
M Lib/test/test_socket.py
M Lib/test/test_support.py
M Lib/test/test_tokenize.py
M Lib/test/test_warnings/__init__.py

diff --git a/Lib/ctypes/test/test_as_parameter.py b/Lib/ctypes/test/test_as_parameter.py
index a2640575a074..f9d27cb89d34 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.assertIs(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 532e8fe6d0d8..8130eab50a93 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 f377ebcb27b2..4f3c4774e40f 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 89f1fbfb6c2b..7870e940a46e 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 f68580ccfb7c..ff1447954943 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 87f929f31478..a4775d03f556 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -148,10 +148,14 @@ def test_always(self):
             self.module.resetwarnings()
             self.module.filterwarnings("always", category=UserWarning)
             message = "FilterTests.test_always"
-            self.module.warn(message, UserWarning)
-            self.assertTrue(message, w[-1].message)
-            self.module.warn(message, UserWarning)
-            self.assertTrue(w[-1].message, message)
+            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):
         with original_warnings.catch_warnings(record=True,



More information about the Python-checkins mailing list