1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #33476 -- Reformatted code with Black.

This commit is contained in:
django-bot
2022-02-03 20:24:19 +01:00
committed by Mariusz Felisiak
parent f68fa8b45d
commit 9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions

View File

@@ -6,7 +6,6 @@ from .models import Post
class TestCharField(TestCase):
def test_max_length_passed_to_formfield(self):
"""
CharField passes its max_length attribute to form fields created using
@@ -21,22 +20,22 @@ class TestCharField(TestCase):
self.assertEqual(Post.objects.filter(title=9).count(), 0)
def test_emoji(self):
p = Post.objects.create(title='Smile 😀', body='Whatever.')
p = Post.objects.create(title="Smile 😀", body="Whatever.")
p.refresh_from_db()
self.assertEqual(p.title, 'Smile 😀')
self.assertEqual(p.title, "Smile 😀")
def test_assignment_from_choice_enum(self):
class Event(models.TextChoices):
C = 'Carnival!'
F = 'Festival!'
C = "Carnival!"
F = "Festival!"
p1 = Post.objects.create(title=Event.C, body=Event.F)
p1.refresh_from_db()
self.assertEqual(p1.title, 'Carnival!')
self.assertEqual(p1.body, 'Festival!')
self.assertEqual(p1.title, "Carnival!")
self.assertEqual(p1.body, "Festival!")
self.assertEqual(p1.title, Event.C)
self.assertEqual(p1.body, Event.F)
p2 = Post.objects.get(title='Carnival!')
p2 = Post.objects.get(title="Carnival!")
self.assertEqual(p1, p2)
self.assertEqual(p2.title, Event.C)
@@ -46,48 +45,47 @@ class TestMethods(SimpleTestCase):
field = models.CharField()
*_, kwargs = field.deconstruct()
self.assertEqual(kwargs, {})
field = models.CharField(db_collation='utf8_esperanto_ci')
field = models.CharField(db_collation="utf8_esperanto_ci")
*_, kwargs = field.deconstruct()
self.assertEqual(kwargs, {'db_collation': 'utf8_esperanto_ci'})
self.assertEqual(kwargs, {"db_collation": "utf8_esperanto_ci"})
class ValidationTests(SimpleTestCase):
class Choices(models.TextChoices):
C = 'c', 'C'
C = "c", "C"
def test_charfield_raises_error_on_empty_string(self):
f = models.CharField()
msg = 'This field cannot be blank.'
msg = "This field cannot be blank."
with self.assertRaisesMessage(ValidationError, msg):
f.clean('', None)
f.clean("", None)
def test_charfield_cleans_empty_string_when_blank_true(self):
f = models.CharField(blank=True)
self.assertEqual('', f.clean('', None))
self.assertEqual("", f.clean("", None))
def test_charfield_with_choices_cleans_valid_choice(self):
f = models.CharField(max_length=1, choices=[('a', 'A'), ('b', 'B')])
self.assertEqual('a', f.clean('a', None))
f = models.CharField(max_length=1, choices=[("a", "A"), ("b", "B")])
self.assertEqual("a", f.clean("a", None))
def test_charfield_with_choices_raises_error_on_invalid_choice(self):
f = models.CharField(choices=[('a', 'A'), ('b', 'B')])
f = models.CharField(choices=[("a", "A"), ("b", "B")])
msg = "Value 'not a' is not a valid choice."
with self.assertRaisesMessage(ValidationError, msg):
f.clean('not a', None)
f.clean("not a", None)
def test_enum_choices_cleans_valid_string(self):
f = models.CharField(choices=self.Choices.choices, max_length=1)
self.assertEqual(f.clean('c', None), 'c')
self.assertEqual(f.clean("c", None), "c")
def test_enum_choices_invalid_input(self):
f = models.CharField(choices=self.Choices.choices, max_length=1)
msg = "Value 'a' is not a valid choice."
with self.assertRaisesMessage(ValidationError, msg):
f.clean('a', None)
f.clean("a", None)
def test_charfield_raises_error_on_empty_input(self):
f = models.CharField(null=False)
msg = 'This field cannot be null.'
msg = "This field cannot be null."
with self.assertRaisesMessage(ValidationError, msg):
f.clean(None, None)