Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48b5c98

Browse files
committed
Replace more boilerplate code with modern unittest features in sqlite3 tests
1 parent f5b1af6 commit 48b5c98

3 files changed

Lines changed: 6 additions & 13 deletions

File tree

Lib/sqlite3/test/dbapi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ def CheckRowcountExecutemany(self):
335335
def CheckTotalChanges(self):
336336
self.cu.execute("insert into test(name) values ('foo')")
337337
self.cu.execute("insert into test(name) values ('foo')")
338-
if self.cx.total_changes < 2:
339-
self.fail("total changes reported wrong value")
338+
self.assertLess(2, self.cx.total_changes, msg='total changes reported wrong value')
340339

341340
# Checks for executemany:
342341
# Sequences are required by the DB-API, iterators

Lib/sqlite3/test/hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def mycoll(x, y):
6161
) order by x collate mycoll
6262
"""
6363
result = con.execute(sql).fetchall()
64-
if result[0][0] != "c" or result[1][0] != "b" or result[2][0] != "a":
65-
self.fail("the expected order was not returned")
64+
self.assertEqual(result, [('c',), ('b',), ('a',)],
65+
msg='the expected order was not returned')
6666

6767
con.create_collation("mycoll", None)
6868
with self.assertRaises(sqlite.OperationalError) as cm:

Lib/sqlite3/test/regression.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,11 @@ def CheckTypeMapUsage(self):
134134
def CheckErrorMsgDecodeError(self):
135135
# When porting the module to Python 3.0, the error message about
136136
# decoding errors disappeared. This verifies they're back again.
137-
failure = None
138-
try:
137+
with self.assertRaises(sqlite.OperationalError) as cm:
139138
self.con.execute("select 'xxx' || ? || 'yyy' colname",
140139
(bytes(bytearray([250])),)).fetchone()
141-
failure = "should have raised an OperationalError with detailed description"
142-
except sqlite.OperationalError as e:
143-
msg = e.args[0]
144-
if not msg.startswith("Could not decode to UTF-8 column 'colname' with text 'xxx"):
145-
failure = "OperationalError did not have expected description text"
146-
if failure:
147-
self.fail(failure)
140+
msg = "Could not decode to UTF-8 column 'colname' with text 'xxx"
141+
self.assertIn(msg, str(cm.exception))
148142

149143
def CheckRegisterAdapter(self):
150144
"""

0 commit comments

Comments
 (0)