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:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -10,7 +10,6 @@ from .models import DurationModel, NullDurationModel
|
||||
|
||||
|
||||
class TestSaveLoad(TestCase):
|
||||
|
||||
def test_simple_roundtrip(self):
|
||||
duration = datetime.timedelta(microseconds=8999999999999999)
|
||||
DurationModel.objects.create(field=duration)
|
||||
@@ -30,7 +29,6 @@ class TestSaveLoad(TestCase):
|
||||
|
||||
|
||||
class TestQuerying(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.objs = [
|
||||
@@ -42,13 +40,13 @@ class TestQuerying(TestCase):
|
||||
def test_exact(self):
|
||||
self.assertSequenceEqual(
|
||||
DurationModel.objects.filter(field=datetime.timedelta(days=1)),
|
||||
[self.objs[0]]
|
||||
[self.objs[0]],
|
||||
)
|
||||
|
||||
def test_gt(self):
|
||||
self.assertSequenceEqual(
|
||||
DurationModel.objects.filter(field__gt=datetime.timedelta(days=0)),
|
||||
[self.objs[0], self.objs[1]]
|
||||
[self.objs[0], self.objs[1]],
|
||||
)
|
||||
|
||||
|
||||
@@ -57,25 +55,24 @@ class TestSerialization(SimpleTestCase):
|
||||
|
||||
def test_dumping(self):
|
||||
instance = DurationModel(field=datetime.timedelta(days=1, hours=1))
|
||||
data = serializers.serialize('json', [instance])
|
||||
data = serializers.serialize("json", [instance])
|
||||
self.assertEqual(json.loads(data), json.loads(self.test_data))
|
||||
|
||||
def test_loading(self):
|
||||
instance = list(serializers.deserialize('json', self.test_data))[0].object
|
||||
instance = list(serializers.deserialize("json", self.test_data))[0].object
|
||||
self.assertEqual(instance.field, datetime.timedelta(days=1, hours=1))
|
||||
|
||||
|
||||
class TestValidation(SimpleTestCase):
|
||||
|
||||
def test_invalid_string(self):
|
||||
field = models.DurationField()
|
||||
with self.assertRaises(exceptions.ValidationError) as cm:
|
||||
field.clean('not a datetime', None)
|
||||
self.assertEqual(cm.exception.code, 'invalid')
|
||||
field.clean("not a datetime", None)
|
||||
self.assertEqual(cm.exception.code, "invalid")
|
||||
self.assertEqual(
|
||||
cm.exception.message % cm.exception.params,
|
||||
'“not a datetime” value has an invalid format. '
|
||||
'It must be in [DD] [[HH:]MM:]ss[.uuuuuu] format.'
|
||||
"“not a datetime” value has an invalid format. "
|
||||
"It must be in [DD] [[HH:]MM:]ss[.uuuuuu] format.",
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user