mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
parent
f68fa8b45d
commit
9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions
|
@ -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,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue