MCPcopy
hub / github.com/django/django / test_datetime_subtraction

Method test_datetime_subtraction

tests/expressions/tests.py:2333–2357  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2331
2332 @skipUnlessDBFeature("supports_temporal_subtraction")
2333 def test_datetime_subtraction(self):
2334 under_estimate = [
2335 e.name
2336 for e in Experiment.objects.filter(estimated_time__gt=F("end") - F("start"))
2337 ]
2338 self.assertEqual(under_estimate, ["e2"])
2339
2340 over_estimate = [
2341 e.name
2342 for e in Experiment.objects.filter(estimated_time__lt=F("end") - F("start"))
2343 ]
2344 self.assertEqual(over_estimate, ["e4"])
2345
2346 queryset = Experiment.objects.annotate(
2347 difference=F("start") - Value(None, output_field=DateTimeField()),
2348 )
2349 self.assertIsNone(queryset.first().difference)
2350
2351 queryset = Experiment.objects.annotate(
2352 shifted=ExpressionWrapper(
2353 F("start") - Value(None, output_field=DurationField()),
2354 output_field=DateTimeField(),
2355 )
2356 )
2357 self.assertIsNone(queryset.first().shifted)
2358
2359 @skipUnlessDBFeature("supports_temporal_subtraction")
2360 def test_datetime_subquery_subtraction(self):

Callers

nothing calls this directly

Calls 8

FClass · 0.90
ValueClass · 0.90
DateTimeFieldClass · 0.90
ExpressionWrapperClass · 0.90
DurationFieldClass · 0.90
annotateMethod · 0.80
firstMethod · 0.80
filterMethod · 0.45

Tested by

no test coverage detected