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

Skip to content

Commit d4b75bf

Browse files
Issue #19601: Use specific asserts in sqlite3 tests.
2 parents 932c616 + 78ee078 commit d4b75bf

2 files changed

Lines changed: 20 additions & 30 deletions

File tree

Lib/sqlite3/test/factory.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def tearDown(self):
4747
self.con.close()
4848

4949
def CheckIsInstance(self):
50-
self.assertTrue(isinstance(self.con,
51-
MyConnection),
52-
"connection is not instance of MyConnection")
50+
self.assertIsInstance(self.con, MyConnection)
5351

5452
class CursorFactoryTests(unittest.TestCase):
5553
def setUp(self):
@@ -60,9 +58,7 @@ def tearDown(self):
6058

6159
def CheckIsInstance(self):
6260
cur = self.con.cursor(factory=MyCursor)
63-
self.assertTrue(isinstance(cur,
64-
MyCursor),
65-
"cursor is not instance of MyCursor")
61+
self.assertIsInstance(cur, MyCursor)
6662

6763
class RowFactoryTestsBackwardsCompat(unittest.TestCase):
6864
def setUp(self):
@@ -72,9 +68,7 @@ def CheckIsProducedByFactory(self):
7268
cur = self.con.cursor(factory=MyCursor)
7369
cur.execute("select 4+5 as foo")
7470
row = cur.fetchone()
75-
self.assertTrue(isinstance(row,
76-
dict),
77-
"row is not instance of dict")
71+
self.assertIsInstance(row, dict)
7872
cur.close()
7973

8074
def tearDown(self):
@@ -87,28 +81,24 @@ def setUp(self):
8781
def CheckCustomFactory(self):
8882
self.con.row_factory = lambda cur, row: list(row)
8983
row = self.con.execute("select 1, 2").fetchone()
90-
self.assertTrue(isinstance(row,
91-
list),
92-
"row is not instance of list")
84+
self.assertIsInstance(row, list)
9385

9486
def CheckSqliteRowIndex(self):
9587
self.con.row_factory = sqlite.Row
9688
row = self.con.execute("select 1 as a, 2 as b").fetchone()
97-
self.assertTrue(isinstance(row,
98-
sqlite.Row),
99-
"row is not instance of sqlite.Row")
89+
self.assertIsInstance(row, sqlite.Row)
10090

10191
col1, col2 = row["a"], row["b"]
102-
self.assertTrue(col1 == 1, "by name: wrong result for column 'a'")
103-
self.assertTrue(col2 == 2, "by name: wrong result for column 'a'")
92+
self.assertEqual(col1, 1, "by name: wrong result for column 'a'")
93+
self.assertEqual(col2, 2, "by name: wrong result for column 'a'")
10494

10595
col1, col2 = row["A"], row["B"]
106-
self.assertTrue(col1 == 1, "by name: wrong result for column 'A'")
107-
self.assertTrue(col2 == 2, "by name: wrong result for column 'B'")
96+
self.assertEqual(col1, 1, "by name: wrong result for column 'A'")
97+
self.assertEqual(col2, 2, "by name: wrong result for column 'B'")
10898

10999
col1, col2 = row[0], row[1]
110-
self.assertTrue(col1 == 1, "by index: wrong result for column 0")
111-
self.assertTrue(col2 == 2, "by index: wrong result for column 1")
100+
self.assertEqual(col1, 1, "by index: wrong result for column 0")
101+
self.assertEqual(col2, 2, "by index: wrong result for column 1")
112102

113103
def CheckSqliteRowIter(self):
114104
"""Checks if the row object is iterable"""
@@ -138,8 +128,8 @@ def CheckSqliteRowHashCmp(self):
138128
row_2 = self.con.execute("select 1 as a, 2 as b").fetchone()
139129
row_3 = self.con.execute("select 1 as a, 3 as b").fetchone()
140130

141-
self.assertTrue(row_1 == row_1)
142-
self.assertTrue(row_1 == row_2)
131+
self.assertEqual(row_1, row_1)
132+
self.assertEqual(row_1, row_2)
143133
self.assertTrue(row_2 != row_3)
144134

145135
self.assertFalse(row_1 != row_1)
@@ -161,20 +151,20 @@ def setUp(self):
161151
def CheckUnicode(self):
162152
austria = "Österreich"
163153
row = self.con.execute("select ?", (austria,)).fetchone()
164-
self.assertTrue(type(row[0]) == str, "type of row[0] must be unicode")
154+
self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
165155

166156
def CheckString(self):
167157
self.con.text_factory = bytes
168158
austria = "Österreich"
169159
row = self.con.execute("select ?", (austria,)).fetchone()
170-
self.assertTrue(type(row[0]) == bytes, "type of row[0] must be bytes")
171-
self.assertTrue(row[0] == austria.encode("utf-8"), "column must equal original data in UTF-8")
160+
self.assertEqual(type(row[0]), bytes, "type of row[0] must be bytes")
161+
self.assertEqual(row[0], austria.encode("utf-8"), "column must equal original data in UTF-8")
172162

173163
def CheckCustom(self):
174164
self.con.text_factory = lambda x: str(x, "utf-8", "ignore")
175165
austria = "Österreich"
176166
row = self.con.execute("select ?", (austria,)).fetchone()
177-
self.assertTrue(type(row[0]) == str, "type of row[0] must be unicode")
167+
self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
178168
self.assertTrue(row[0].endswith("reich"), "column must contain original data")
179169

180170
def CheckOptimizedUnicode(self):
@@ -185,8 +175,8 @@ def CheckOptimizedUnicode(self):
185175
germany = "Deutchland"
186176
a_row = self.con.execute("select ?", (austria,)).fetchone()
187177
d_row = self.con.execute("select ?", (germany,)).fetchone()
188-
self.assertTrue(type(a_row[0]) == str, "type of non-ASCII row must be str")
189-
self.assertTrue(type(d_row[0]) == str, "type of ASCII-only row must be str")
178+
self.assertEqual(type(a_row[0]), str, "type of non-ASCII row must be str")
179+
self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
190180

191181
def tearDown(self):
192182
self.con.close()

Lib/sqlite3/test/hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def progress():
162162
create table bar (a, b)
163163
""")
164164
second_count = len(progress_calls)
165-
self.assertTrue(first_count > second_count)
165+
self.assertGreater(first_count, second_count)
166166

167167
def CheckCancelOperation(self):
168168
"""

0 commit comments

Comments
 (0)