summaryrefslogtreecommitdiff
path: root/tests/expressions
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2017-12-29 03:35:41 +0500
committerTim Graham <timograham@gmail.com>2017-12-28 17:35:41 -0500
commitae6fa914aa2f43d39ae491ac7d3140dda69702fa (patch)
tree8ecea479750200eed8f047381a167097404db8f9 /tests/expressions
parent46d1af2e82c2b2a6976397719afde33b5cff2498 (diff)
Fixed #28926 -- Fixed loss of precision of big DurationField values on SQLite and MySQL.
Diffstat (limited to 'tests/expressions')
-rw-r--r--tests/expressions/tests.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index 5d54e46c02..2a6714a65f 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -1250,6 +1250,16 @@ class FTimeDeltaTests(TestCase):
]
self.assertEqual(over_estimate, ['e4'])
+ @skipUnlessDBFeature('supports_temporal_subtraction')
+ def test_datetime_subtraction_microseconds(self):
+ delta = datetime.timedelta(microseconds=8999999999999999)
+ Experiment.objects.update(end=F('start') + delta)
+ qs = Experiment.objects.annotate(
+ delta=ExpressionWrapper(F('end') - F('start'), output_field=models.DurationField())
+ )
+ for e in qs:
+ self.assertEqual(e.delta, delta)
+
def test_duration_with_datetime(self):
# Exclude e1 which has very high precision so we can test this on all
# backends regardless of whether or not it supports
@@ -1259,6 +1269,15 @@ class FTimeDeltaTests(TestCase):
).order_by('name')
self.assertQuerysetEqual(over_estimate, ['e3', 'e4', 'e5'], lambda e: e.name)
+ def test_duration_with_datetime_microseconds(self):
+ delta = datetime.timedelta(microseconds=8999999999999999)
+ qs = Experiment.objects.annotate(dt=ExpressionWrapper(
+ F('start') + delta,
+ output_field=models.DateTimeField(),
+ ))
+ for e in qs:
+ self.assertEqual(e.dt, e.start + delta)
+
def test_date_minus_duration(self):
more_than_4_days = Experiment.objects.filter(
assigned__lt=F('completed') - Value(datetime.timedelta(days=4), output_field=models.DurationField())