mirror of
https://github.com/django/django.git
synced 2025-08-30 15:27:40 +00:00
Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.core.
This commit is contained in:
parent
37044817f9
commit
474cc420bf
8 changed files with 76 additions and 11 deletions
|
@ -4,6 +4,7 @@ from io import StringIO
|
|||
from django.apps import apps
|
||||
from django.core import checks
|
||||
from django.core.checks import Error, Warning
|
||||
from django.core.checks.messages import CheckMessage
|
||||
from django.core.checks.registry import CheckRegistry
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
|
@ -74,6 +75,20 @@ class SystemCheckFrameworkTests(SimpleTestCase):
|
|||
def no_kwargs(app_configs, databases):
|
||||
pass
|
||||
|
||||
def test_register_run_checks_non_iterable(self):
|
||||
registry = CheckRegistry()
|
||||
|
||||
@registry.register
|
||||
def return_non_iterable(**kwargs):
|
||||
return Error('Message')
|
||||
|
||||
msg = (
|
||||
'The function %r did not return a list. All functions registered '
|
||||
'with the checks registry must return a list.' % return_non_iterable
|
||||
)
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
registry.run_checks()
|
||||
|
||||
|
||||
class MessageTests(SimpleTestCase):
|
||||
|
||||
|
@ -132,6 +147,11 @@ class MessageTests(SimpleTestCase):
|
|||
e = Error("Error", obj=DummyObj())
|
||||
self.assertNotEqual(e, 'a string')
|
||||
|
||||
def test_invalid_level(self):
|
||||
msg = 'The first argument should be level.'
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
CheckMessage('ERROR', 'Message')
|
||||
|
||||
|
||||
def simple_system_check(**kwargs):
|
||||
simple_system_check.kwargs = kwargs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue