summaryrefslogtreecommitdiff
path: root/tests/test_runner/test_debug_sql.py
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /tests/test_runner/test_debug_sql.py
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/test_runner/test_debug_sql.py')
-rw-r--r--tests/test_runner/test_debug_sql.py79
1 files changed, 46 insertions, 33 deletions
diff --git a/tests/test_runner/test_debug_sql.py b/tests/test_runner/test_debug_sql.py
index 0e8e4207d6..9957295f01 100644
--- a/tests/test_runner/test_debug_sql.py
+++ b/tests/test_runner/test_debug_sql.py
@@ -8,21 +8,22 @@ from django.test.runner import DiscoverRunner
from .models import Person
-@unittest.skipUnless(connection.vendor == 'sqlite', 'Only run on sqlite so we can check output SQL.')
+@unittest.skipUnless(
+ connection.vendor == "sqlite", "Only run on sqlite so we can check output SQL."
+)
class TestDebugSQL(unittest.TestCase):
-
class PassingTest(TestCase):
def runTest(self):
- Person.objects.filter(first_name='pass').count()
+ Person.objects.filter(first_name="pass").count()
class FailingTest(TestCase):
def runTest(self):
- Person.objects.filter(first_name='fail').count()
+ Person.objects.filter(first_name="fail").count()
self.fail()
class ErrorTest(TestCase):
def runTest(self):
- Person.objects.filter(first_name='error').count()
+ Person.objects.filter(first_name="error").count()
raise Exception
class ErrorSetUpTestDataTest(TestCase):
@@ -36,18 +37,18 @@ class TestDebugSQL(unittest.TestCase):
class PassingSubTest(TestCase):
def runTest(self):
with self.subTest():
- Person.objects.filter(first_name='subtest-pass').count()
+ Person.objects.filter(first_name="subtest-pass").count()
class FailingSubTest(TestCase):
def runTest(self):
with self.subTest():
- Person.objects.filter(first_name='subtest-fail').count()
+ Person.objects.filter(first_name="subtest-fail").count()
self.fail()
class ErrorSubTest(TestCase):
def runTest(self):
with self.subTest():
- Person.objects.filter(first_name='subtest-error').count()
+ Person.objects.filter(first_name="subtest-error").count()
raise Exception
def _test_output(self, verbosity):
@@ -86,34 +87,46 @@ class TestDebugSQL(unittest.TestCase):
self.assertIn(output, full_output)
expected_outputs = [
- ('''SELECT COUNT(*) AS "__count" '''
- '''FROM "test_runner_person" WHERE '''
- '''"test_runner_person"."first_name" = 'error';'''),
- ('''SELECT COUNT(*) AS "__count" '''
- '''FROM "test_runner_person" WHERE '''
- '''"test_runner_person"."first_name" = 'fail';'''),
- ('''SELECT COUNT(*) AS "__count" '''
- '''FROM "test_runner_person" WHERE '''
- '''"test_runner_person"."first_name" = 'subtest-error';'''),
- ('''SELECT COUNT(*) AS "__count" '''
- '''FROM "test_runner_person" WHERE '''
- '''"test_runner_person"."first_name" = 'subtest-fail';'''),
+ (
+ """SELECT COUNT(*) AS "__count" """
+ """FROM "test_runner_person" WHERE """
+ """"test_runner_person"."first_name" = 'error';"""
+ ),
+ (
+ """SELECT COUNT(*) AS "__count" """
+ """FROM "test_runner_person" WHERE """
+ """"test_runner_person"."first_name" = 'fail';"""
+ ),
+ (
+ """SELECT COUNT(*) AS "__count" """
+ """FROM "test_runner_person" WHERE """
+ """"test_runner_person"."first_name" = 'subtest-error';"""
+ ),
+ (
+ """SELECT COUNT(*) AS "__count" """
+ """FROM "test_runner_person" WHERE """
+ """"test_runner_person"."first_name" = 'subtest-fail';"""
+ ),
]
verbose_expected_outputs = [
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.FailingTest) ... FAIL',
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.ErrorTest) ... ERROR',
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.PassingTest) ... ok',
+ "runTest (test_runner.test_debug_sql.TestDebugSQL.FailingTest) ... FAIL",
+ "runTest (test_runner.test_debug_sql.TestDebugSQL.ErrorTest) ... ERROR",
+ "runTest (test_runner.test_debug_sql.TestDebugSQL.PassingTest) ... ok",
# If there are errors/failures in subtests but not in test itself,
# the status is not written. That behavior comes from Python.
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.FailingSubTest) ...',
- 'runTest (test_runner.test_debug_sql.TestDebugSQL.ErrorSubTest) ...',
- ('''SELECT COUNT(*) AS "__count" '''
- '''FROM "test_runner_person" WHERE '''
- '''"test_runner_person"."first_name" = 'pass';'''),
- ('''SELECT COUNT(*) AS "__count" '''
- '''FROM "test_runner_person" WHERE '''
- '''"test_runner_person"."first_name" = 'subtest-pass';'''),
+ "runTest (test_runner.test_debug_sql.TestDebugSQL.FailingSubTest) ...",
+ "runTest (test_runner.test_debug_sql.TestDebugSQL.ErrorSubTest) ...",
+ (
+ """SELECT COUNT(*) AS "__count" """
+ """FROM "test_runner_person" WHERE """
+ """"test_runner_person"."first_name" = 'pass';"""
+ ),
+ (
+ """SELECT COUNT(*) AS "__count" """
+ """FROM "test_runner_person" WHERE """
+ """"test_runner_person"."first_name" = 'subtest-pass';"""
+ ),
]
def test_setupclass_exception(self):
@@ -130,7 +143,7 @@ class TestDebugSQL(unittest.TestCase):
runner.teardown_databases(old_config)
output = stream.getvalue()
self.assertIn(
- 'ERROR: setUpClass '
- '(test_runner.test_debug_sql.TestDebugSQL.ErrorSetUpTestDataTest)',
+ "ERROR: setUpClass "
+ "(test_runner.test_debug_sql.TestDebugSQL.ErrorSetUpTestDataTest)",
output,
)