[Python-checkins] cpython (2.7): Issue #19601: Use specific asserts in sqlite3 tests.

serhiy.storchaka python-checkins at python.org
Sun Nov 17 11:58:23 CET 2013


http://hg.python.org/cpython/rev/d004ccdd6a57
changeset:   87179:d004ccdd6a57
branch:      2.7
parent:      87162:097389413dd3
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Nov 17 00:39:43 2013 +0200
summary:
  Issue #19601: Use specific asserts in sqlite3 tests.

files:
  Lib/sqlite3/test/factory.py |  48 +++++++++---------------
  Lib/sqlite3/test/hooks.py   |   2 +-
  2 files changed, 20 insertions(+), 30 deletions(-)


diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py
--- a/Lib/sqlite3/test/factory.py
+++ b/Lib/sqlite3/test/factory.py
@@ -47,9 +47,7 @@
         self.con.close()
 
     def CheckIsInstance(self):
-        self.assertTrue(isinstance(self.con,
-                                   MyConnection),
-                        "connection is not instance of MyConnection")
+        self.assertIsInstance(self.con, MyConnection)
 
 class CursorFactoryTests(unittest.TestCase):
     def setUp(self):
@@ -60,9 +58,7 @@
 
     def CheckIsInstance(self):
         cur = self.con.cursor(factory=MyCursor)
-        self.assertTrue(isinstance(cur,
-                                   MyCursor),
-                        "cursor is not instance of MyCursor")
+        self.assertIsInstance(cur, MyCursor)
 
 class RowFactoryTestsBackwardsCompat(unittest.TestCase):
     def setUp(self):
@@ -72,9 +68,7 @@
         cur = self.con.cursor(factory=MyCursor)
         cur.execute("select 4+5 as foo")
         row = cur.fetchone()
-        self.assertTrue(isinstance(row,
-                                   dict),
-                        "row is not instance of dict")
+        self.assertIsInstance(row, dict)
         cur.close()
 
     def tearDown(self):
@@ -87,28 +81,24 @@
     def CheckCustomFactory(self):
         self.con.row_factory = lambda cur, row: list(row)
         row = self.con.execute("select 1, 2").fetchone()
-        self.assertTrue(isinstance(row,
-                                   list),
-                        "row is not instance of list")
+        self.assertIsInstance(row, list)
 
     def CheckSqliteRowIndex(self):
         self.con.row_factory = sqlite.Row
         row = self.con.execute("select 1 as a, 2 as b").fetchone()
-        self.assertTrue(isinstance(row,
-                                   sqlite.Row),
-                        "row is not instance of sqlite.Row")
+        self.assertIsInstance(row, sqlite.Row)
 
         col1, col2 = row["a"], row["b"]
-        self.assertTrue(col1 == 1, "by name: wrong result for column 'a'")
-        self.assertTrue(col2 == 2, "by name: wrong result for column 'a'")
+        self.assertEqual(col1, 1, "by name: wrong result for column 'a'")
+        self.assertEqual(col2, 2, "by name: wrong result for column 'a'")
 
         col1, col2 = row["A"], row["B"]
-        self.assertTrue(col1 == 1, "by name: wrong result for column 'A'")
-        self.assertTrue(col2 == 2, "by name: wrong result for column 'B'")
+        self.assertEqual(col1, 1, "by name: wrong result for column 'A'")
+        self.assertEqual(col2, 2, "by name: wrong result for column 'B'")
 
         col1, col2 = row[0], row[1]
-        self.assertTrue(col1 == 1, "by index: wrong result for column 0")
-        self.assertTrue(col2 == 2, "by index: wrong result for column 1")
+        self.assertEqual(col1, 1, "by index: wrong result for column 0")
+        self.assertEqual(col2, 2, "by index: wrong result for column 1")
 
     def CheckSqliteRowIter(self):
         """Checks if the row object is iterable"""
@@ -138,8 +128,8 @@
         row_2 = self.con.execute("select 1 as a, 2 as b").fetchone()
         row_3 = self.con.execute("select 1 as a, 3 as b").fetchone()
 
-        self.assertTrue(row_1 == row_1)
-        self.assertTrue(row_1 == row_2)
+        self.assertEqual(row_1, row_1)
+        self.assertEqual(row_1, row_2)
         self.assertTrue(row_2 != row_3)
 
         self.assertFalse(row_1 != row_1)
@@ -161,20 +151,20 @@
     def CheckUnicode(self):
         austria = unicode("Österreich", "latin1")
         row = self.con.execute("select ?", (austria,)).fetchone()
-        self.assertTrue(type(row[0]) == unicode, "type of row[0] must be unicode")
+        self.assertEqual(type(row[0]), unicode, "type of row[0] must be unicode")
 
     def CheckString(self):
         self.con.text_factory = str
         austria = unicode("Österreich", "latin1")
         row = self.con.execute("select ?", (austria,)).fetchone()
-        self.assertTrue(type(row[0]) == str, "type of row[0] must be str")
-        self.assertTrue(row[0] == austria.encode("utf-8"), "column must equal original data in UTF-8")
+        self.assertEqual(type(row[0]), str, "type of row[0] must be str")
+        self.assertEqual(row[0], austria.encode("utf-8"), "column must equal original data in UTF-8")
 
     def CheckCustom(self):
         self.con.text_factory = lambda x: unicode(x, "utf-8", "ignore")
         austria = unicode("Österreich", "latin1")
         row = self.con.execute("select ?", (austria.encode("latin1"),)).fetchone()
-        self.assertTrue(type(row[0]) == unicode, "type of row[0] must be unicode")
+        self.assertEqual(type(row[0]), unicode, "type of row[0] must be unicode")
         self.assertTrue(row[0].endswith(u"reich"), "column must contain original data")
 
     def CheckOptimizedUnicode(self):
@@ -183,8 +173,8 @@
         germany = unicode("Deutchland")
         a_row = self.con.execute("select ?", (austria,)).fetchone()
         d_row = self.con.execute("select ?", (germany,)).fetchone()
-        self.assertTrue(type(a_row[0]) == unicode, "type of non-ASCII row must be unicode")
-        self.assertTrue(type(d_row[0]) == str, "type of ASCII-only row must be str")
+        self.assertEqual(type(a_row[0]), unicode, "type of non-ASCII row must be unicode")
+        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
 
     def tearDown(self):
         self.con.close()
diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py
--- a/Lib/sqlite3/test/hooks.py
+++ b/Lib/sqlite3/test/hooks.py
@@ -162,7 +162,7 @@
             create table bar (a, b)
             """)
         second_count = len(progress_calls)
-        self.assertTrue(first_count > second_count)
+        self.assertGreater(first_count, second_count)
 
     def CheckCancelOperation(self):
         """

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list