mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -15,7 +15,7 @@ class Person(models.Model):
|
||||
return "%s %s" % (self.first_name, self.last_name)
|
||||
|
||||
def _set_full_name(self, combined_name):
|
||||
self.first_name, self.last_name = combined_name.split(' ', 1)
|
||||
self.first_name, self.last_name = combined_name.split(" ", 1)
|
||||
|
||||
full_name = property(_get_full_name)
|
||||
|
||||
|
||||
@@ -4,24 +4,23 @@ from .models import Person
|
||||
|
||||
|
||||
class PropertyTests(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.a = Person.objects.create(first_name='John', last_name='Lennon')
|
||||
cls.a = Person.objects.create(first_name="John", last_name="Lennon")
|
||||
|
||||
def test_getter(self):
|
||||
self.assertEqual(self.a.full_name, 'John Lennon')
|
||||
self.assertEqual(self.a.full_name, "John Lennon")
|
||||
|
||||
def test_setter(self):
|
||||
# The "full_name" property hasn't provided a "set" method.
|
||||
with self.assertRaises(AttributeError):
|
||||
setattr(self.a, 'full_name', 'Paul McCartney')
|
||||
setattr(self.a, "full_name", "Paul McCartney")
|
||||
|
||||
# And cannot be used to initialize the class.
|
||||
with self.assertRaises(AttributeError):
|
||||
Person(full_name='Paul McCartney')
|
||||
Person(full_name="Paul McCartney")
|
||||
|
||||
# But "full_name_2" has, and it can be used to initialize the class.
|
||||
a2 = Person(full_name_2='Paul McCartney')
|
||||
a2 = Person(full_name_2="Paul McCartney")
|
||||
a2.save()
|
||||
self.assertEqual(a2.first_name, 'Paul')
|
||||
self.assertEqual(a2.first_name, "Paul")
|
||||
|
||||
Reference in New Issue
Block a user