aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2025-01-14 15:18:25 +0200
committerGitHub <noreply@github.com>2025-01-14 15:18:25 +0200
commit75bd42c73718ca54ed70d5bf90cbc76c2c1d5ddc (patch)
tree76cce0da06f84fd5f06d91832b3cbf1726e37ace
parentff3e145b2770ffe86c905b1092747ce3d8381319 (diff)
downloadcpython-75bd42c73718ca54ed70d5bf90cbc76c2c1d5ddc.tar.gz
cpython-75bd42c73718ca54ed70d5bf90cbc76c2c1d5ddc.zip
gh-71339: Use new assertion methods in test_sqlite3 (GH-128830)
-rw-r--r--Lib/test/test_sqlite3/test_cli.py16
-rw-r--r--Lib/test/test_sqlite3/test_dbapi.py37
-rw-r--r--Lib/test/test_sqlite3/test_factory.py2
3 files changed, 22 insertions, 33 deletions
diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py
index d014a9ce841..dcd90d11d46 100644
--- a/Lib/test/test_sqlite3/test_cli.py
+++ b/Lib/test/test_sqlite3/test_cli.py
@@ -90,14 +90,14 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli()
self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn(self.MEMORY_DB_MSG, err)
- self.assertTrue(out.endswith(self.PS1))
+ self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 1)
self.assertEqual(out.count(self.PS2), 0)
def test_interact_quit(self):
out, err = self.run_cli(commands=(".quit",))
self.assertIn(self.MEMORY_DB_MSG, err)
- self.assertTrue(out.endswith(self.PS1))
+ self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 1)
self.assertEqual(out.count(self.PS2), 0)
@@ -105,7 +105,7 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli(commands=(".version",))
self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn(sqlite3.sqlite_version + "\n", out)
- self.assertTrue(out.endswith(self.PS1))
+ self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 2)
self.assertEqual(out.count(self.PS2), 0)
self.assertIn(sqlite3.sqlite_version, out)
@@ -114,14 +114,14 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli(commands=("SELECT 1;",))
self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn("(1,)\n", out)
- self.assertTrue(out.endswith(self.PS1))
+ self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 2)
self.assertEqual(out.count(self.PS2), 0)
def test_interact_incomplete_multiline_sql(self):
out, err = self.run_cli(commands=("SELECT 1",))
self.assertIn(self.MEMORY_DB_MSG, err)
- self.assertTrue(out.endswith(self.PS2))
+ self.assertEndsWith(out, self.PS2)
self.assertEqual(out.count(self.PS1), 1)
self.assertEqual(out.count(self.PS2), 1)
@@ -130,7 +130,7 @@ class InteractiveSession(unittest.TestCase):
self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn(self.PS2, out)
self.assertIn("(1,)\n", out)
- self.assertTrue(out.endswith(self.PS1))
+ self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 2)
self.assertEqual(out.count(self.PS2), 1)
@@ -138,7 +138,7 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli(commands=("sel;",))
self.assertIn(self.MEMORY_DB_MSG, err)
self.assertIn("OperationalError (SQLITE_ERROR)", err)
- self.assertTrue(out.endswith(self.PS1))
+ self.assertEndsWith(out, self.PS1)
self.assertEqual(out.count(self.PS1), 2)
self.assertEqual(out.count(self.PS2), 0)
@@ -147,7 +147,7 @@ class InteractiveSession(unittest.TestCase):
out, err = self.run_cli(TESTFN, commands=("CREATE TABLE t(t);",))
self.assertIn(TESTFN, err)
- self.assertTrue(out.endswith(self.PS1))
+ self.assertEndsWith(out, self.PS1)
out, _ = self.run_cli(TESTFN, commands=("SELECT count(t) FROM t;",))
self.assertIn("(0,)\n", out)
diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py
index 488b401fb00..f5ffe242743 100644
--- a/Lib/test/test_sqlite3/test_dbapi.py
+++ b/Lib/test/test_sqlite3/test_dbapi.py
@@ -59,45 +59,34 @@ class ModuleTests(unittest.TestCase):
sqlite.paramstyle)
def test_warning(self):
- self.assertTrue(issubclass(sqlite.Warning, Exception),
- "Warning is not a subclass of Exception")
+ self.assertIsSubclass(sqlite.Warning, Exception)
def test_error(self):
- self.assertTrue(issubclass(sqlite.Error, Exception),
- "Error is not a subclass of Exception")
+ self.assertIsSubclass(sqlite.Error, Exception)
def test_interface_error(self):
- self.assertTrue(issubclass(sqlite.InterfaceError, sqlite.Error),
- "InterfaceError is not a subclass of Error")
+ self.assertIsSubclass(sqlite.InterfaceError, sqlite.Error)
def test_database_error(self):
- self.assertTrue(issubclass(sqlite.DatabaseError, sqlite.Error),
- "DatabaseError is not a subclass of Error")
+ self.assertIsSubclass(sqlite.DatabaseError, sqlite.Error)
def test_data_error(self):
- self.assertTrue(issubclass(sqlite.DataError, sqlite.DatabaseError),
- "DataError is not a subclass of DatabaseError")
+ self.assertIsSubclass(sqlite.DataError, sqlite.DatabaseError)
def test_operational_error(self):
- self.assertTrue(issubclass(sqlite.OperationalError, sqlite.DatabaseError),
- "OperationalError is not a subclass of DatabaseError")
+ self.assertIsSubclass(sqlite.OperationalError, sqlite.DatabaseError)
def test_integrity_error(self):
- self.assertTrue(issubclass(sqlite.IntegrityError, sqlite.DatabaseError),
- "IntegrityError is not a subclass of DatabaseError")
+ self.assertIsSubclass(sqlite.IntegrityError, sqlite.DatabaseError)
def test_internal_error(self):
- self.assertTrue(issubclass(sqlite.InternalError, sqlite.DatabaseError),
- "InternalError is not a subclass of DatabaseError")
+ self.assertIsSubclass(sqlite.InternalError, sqlite.DatabaseError)
def test_programming_error(self):
- self.assertTrue(issubclass(sqlite.ProgrammingError, sqlite.DatabaseError),
- "ProgrammingError is not a subclass of DatabaseError")
+ self.assertIsSubclass(sqlite.ProgrammingError, sqlite.DatabaseError)
def test_not_supported_error(self):
- self.assertTrue(issubclass(sqlite.NotSupportedError,
- sqlite.DatabaseError),
- "NotSupportedError is not a subclass of DatabaseError")
+ self.assertIsSubclass(sqlite.NotSupportedError, sqlite.DatabaseError)
def test_module_constants(self):
consts = [
@@ -274,7 +263,7 @@ class ModuleTests(unittest.TestCase):
consts.append("SQLITE_IOERR_CORRUPTFS")
for const in consts:
with self.subTest(const=const):
- self.assertTrue(hasattr(sqlite, const))
+ self.assertHasAttr(sqlite, const)
def test_error_code_on_exception(self):
err_msg = "unable to open database file"
@@ -288,7 +277,7 @@ class ModuleTests(unittest.TestCase):
sqlite.connect(db)
e = cm.exception
self.assertEqual(e.sqlite_errorcode, err_code)
- self.assertTrue(e.sqlite_errorname.startswith("SQLITE_CANTOPEN"))
+ self.assertStartsWith(e.sqlite_errorname, "SQLITE_CANTOPEN")
def test_extended_error_code_on_exception(self):
with memory_database() as con:
@@ -425,7 +414,7 @@ class ConnectionTests(unittest.TestCase):
]
for exc in exceptions:
with self.subTest(exc=exc):
- self.assertTrue(hasattr(self.cx, exc))
+ self.assertHasAttr(self.cx, exc)
self.assertIs(getattr(sqlite, exc), getattr(self.cx, exc))
def test_interrupt_on_closed_db(self):
diff --git a/Lib/test/test_sqlite3/test_factory.py b/Lib/test/test_sqlite3/test_factory.py
index 48d35b54a2e..cc9f1ec5c4b 100644
--- a/Lib/test/test_sqlite3/test_factory.py
+++ b/Lib/test/test_sqlite3/test_factory.py
@@ -280,7 +280,7 @@ class TextFactoryTests(MemoryDatabaseMixin, unittest.TestCase):
austria = "Österreich"
row = self.con.execute("select ?", (austria,)).fetchone()
self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
- self.assertTrue(row[0].endswith("reich"), "column must contain original data")
+ self.assertEndsWith(row[0], "reich", "column must contain original data")
class TextFactoryTestsWithEmbeddedZeroBytes(unittest.TestCase):