bpo-40823: Use loadTestsFromTestCase() iso. makeSuite() in sqlite3 tests (GH-20538)

This commit is contained in:
Erlend Egeberg Aasland 2021-01-07 01:05:07 +01:00 committed by GitHub
parent 1ab045933b
commit 849e339a92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 345 additions and 320 deletions

View file

@ -28,23 +28,23 @@ from test.support.os_helper import TESTFN, unlink
class CollationTests(unittest.TestCase):
def CheckCreateCollationNotString(self):
def test_create_collation_not_string(self):
con = sqlite.connect(":memory:")
with self.assertRaises(TypeError):
con.create_collation(None, lambda x, y: (x > y) - (x < y))
def CheckCreateCollationNotCallable(self):
def test_create_collation_not_callable(self):
con = sqlite.connect(":memory:")
with self.assertRaises(TypeError) as cm:
con.create_collation("X", 42)
self.assertEqual(str(cm.exception), 'parameter must be callable')
def CheckCreateCollationNotAscii(self):
def test_create_collation_not_ascii(self):
con = sqlite.connect(":memory:")
with self.assertRaises(sqlite.ProgrammingError):
con.create_collation("collä", lambda x, y: (x > y) - (x < y))
def CheckCreateCollationBadUpper(self):
def test_create_collation_bad_upper(self):
class BadUpperStr(str):
def upper(self):
return None
@ -61,7 +61,7 @@ class CollationTests(unittest.TestCase):
self.assertEqual(result[0][0], 'b')
self.assertEqual(result[1][0], 'a')
def CheckCollationIsUsed(self):
def test_collation_is_used(self):
def mycoll(x, y):
# reverse order
return -((x > y) - (x < y))
@ -86,7 +86,7 @@ class CollationTests(unittest.TestCase):
result = con.execute(sql).fetchall()
self.assertEqual(str(cm.exception), 'no such collation sequence: mycoll')
def CheckCollationReturnsLargeInteger(self):
def test_collation_returns_large_integer(self):
def mycoll(x, y):
# reverse order
return -((x > y) - (x < y)) * 2**32
@ -105,7 +105,7 @@ class CollationTests(unittest.TestCase):
self.assertEqual(result, [('c',), ('b',), ('a',)],
msg="the expected order was not returned")
def CheckCollationRegisterTwice(self):
def test_collation_register_twice(self):
"""
Register two different collation functions under the same name.
Verify that the last one is actually used.
@ -119,7 +119,7 @@ class CollationTests(unittest.TestCase):
self.assertEqual(result[0][0], 'b')
self.assertEqual(result[1][0], 'a')
def CheckDeregisterCollation(self):
def test_deregister_collation(self):
"""
Register a collation, then deregister it. Make sure an error is raised if we try
to use it.
@ -132,7 +132,7 @@ class CollationTests(unittest.TestCase):
self.assertEqual(str(cm.exception), 'no such collation sequence: mycoll')
class ProgressTests(unittest.TestCase):
def CheckProgressHandlerUsed(self):
def test_progress_handler_used(self):
"""
Test that the progress handler is invoked once it is set.
"""
@ -148,7 +148,7 @@ class ProgressTests(unittest.TestCase):
self.assertTrue(progress_calls)
def CheckOpcodeCount(self):
def test_opcode_count(self):
"""
Test that the opcode argument is respected.
"""
@ -171,7 +171,7 @@ class ProgressTests(unittest.TestCase):
second_count = len(progress_calls)
self.assertGreaterEqual(first_count, second_count)
def CheckCancelOperation(self):
def test_cancel_operation(self):
"""
Test that returning a non-zero value stops the operation in progress.
"""
@ -185,7 +185,7 @@ class ProgressTests(unittest.TestCase):
curs.execute,
"create table bar (a, b)")
def CheckClearHandler(self):
def test_clear_handler(self):
"""
Test that setting the progress handler to None clears the previously set handler.
"""
@ -201,7 +201,7 @@ class ProgressTests(unittest.TestCase):
self.assertEqual(action, 0, "progress handler was not cleared")
class TraceCallbackTests(unittest.TestCase):
def CheckTraceCallbackUsed(self):
def test_trace_callback_used(self):
"""
Test that the trace callback is invoked once it is set.
"""
@ -214,7 +214,7 @@ class TraceCallbackTests(unittest.TestCase):
self.assertTrue(traced_statements)
self.assertTrue(any("create table foo" in stmt for stmt in traced_statements))
def CheckClearTraceCallback(self):
def test_clear_trace_callback(self):
"""
Test that setting the trace callback to None clears the previously set callback.
"""
@ -227,7 +227,7 @@ class TraceCallbackTests(unittest.TestCase):
con.execute("create table foo(a, b)")
self.assertFalse(traced_statements, "trace callback was not cleared")
def CheckUnicodeContent(self):
def test_unicode_content(self):
"""
Test that the statement can contain unicode literals.
"""
@ -244,7 +244,7 @@ class TraceCallbackTests(unittest.TestCase):
"Unicode data %s garbled in trace callback: %s"
% (ascii(unicode_value), ', '.join(map(ascii, traced_statements))))
def CheckTraceCallbackContent(self):
def test_trace_callback_content(self):
# set_trace_callback() shouldn't produce duplicate content (bpo-26187)
traced_statements = []
def trace(statement):
@ -264,10 +264,14 @@ class TraceCallbackTests(unittest.TestCase):
def suite():
collation_suite = unittest.makeSuite(CollationTests, "Check")
progress_suite = unittest.makeSuite(ProgressTests, "Check")
trace_suite = unittest.makeSuite(TraceCallbackTests, "Check")
return unittest.TestSuite((collation_suite, progress_suite, trace_suite))
tests = [
CollationTests,
ProgressTests,
TraceCallbackTests,
]
return unittest.TestSuite(
[unittest.TestLoader().loadTestsFromTestCase(t) for t in tests]
)
def test():
runner = unittest.TextTestRunner()