Replace more boilerplate code with modern unittest features in sqlite3 tests
authorBerker Peksag <berker.peksag@gmail.com>
Mon, 13 Jun 2016 21:42:50 +0000 (00:42 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Mon, 13 Jun 2016 21:42:50 +0000 (00:42 +0300)
Lib/sqlite3/test/dbapi.py
Lib/sqlite3/test/hooks.py
Lib/sqlite3/test/regression.py

index 6057805f65c0c8844dfaa12393006312aab4b88a..903e5990316d7a3c1c2dd3e8e72a17a088d0a739 100644 (file)
@@ -335,8 +335,7 @@ class CursorTests(unittest.TestCase):
     def CheckTotalChanges(self):
         self.cu.execute("insert into test(name) values ('foo')")
         self.cu.execute("insert into test(name) values ('foo')")
-        if self.cx.total_changes < 2:
-            self.fail("total changes reported wrong value")
+        self.assertLess(2, self.cx.total_changes, msg='total changes reported wrong value')
 
     # Checks for executemany:
     # Sequences are required by the DB-API, iterators
index 67653aeeb9f9897f92543acd8e410da0844dbd36..de69569d1c0d6cc37198a912882241820cbf3660 100644 (file)
@@ -61,8 +61,8 @@ class CollationTests(unittest.TestCase):
             ) order by x collate mycoll
             """
         result = con.execute(sql).fetchall()
-        if result[0][0] != "c" or result[1][0] != "b" or result[2][0] != "a":
-            self.fail("the expected order was not returned")
+        self.assertEqual(result, [('c',), ('b',), ('a',)],
+                         msg='the expected order was not returned')
 
         con.create_collation("mycoll", None)
         with self.assertRaises(sqlite.OperationalError) as cm:
index 85ace84d754adeff7a40eea5b19854ef78c3ceb4..0cf9002d8c04d36b06967096da378e9544323dd8 100644 (file)
@@ -134,17 +134,11 @@ class RegressionTests(unittest.TestCase):
     def CheckErrorMsgDecodeError(self):
         # When porting the module to Python 3.0, the error message about
         # decoding errors disappeared. This verifies they're back again.
-        failure = None
-        try:
+        with self.assertRaises(sqlite.OperationalError) as cm:
             self.con.execute("select 'xxx' || ? || 'yyy' colname",
                              (bytes(bytearray([250])),)).fetchone()
-            failure = "should have raised an OperationalError with detailed description"
-        except sqlite.OperationalError as e:
-            msg = e.args[0]
-            if not msg.startswith("Could not decode to UTF-8 column 'colname' with text 'xxx"):
-                failure = "OperationalError did not have expected description text"
-        if failure:
-            self.fail(failure)
+        msg = "Could not decode to UTF-8 column 'colname' with text 'xxx"
+        self.assertIn(msg, str(cm.exception))
 
     def CheckRegisterAdapter(self):
         """