Ejemplo n.º 1
0
 def test_empty_result_set(self):
     StatTestModel.objects.all().delete()
     tests = [
         (Corr(y="int2", x="int1"), None),
         (CovarPop(y="int2", x="int1"), None),
         (CovarPop(y="int2", x="int1", sample=True), None),
         (RegrAvgX(y="int2", x="int1"), None),
         (RegrAvgY(y="int2", x="int1"), None),
         (RegrCount(y="int2", x="int1"), 0),
         (RegrIntercept(y="int2", x="int1"), None),
         (RegrR2(y="int2", x="int1"), None),
         (RegrSlope(y="int2", x="int1"), None),
         (RegrSXX(y="int2", x="int1"), None),
         (RegrSXY(y="int2", x="int1"), None),
         (RegrSYY(y="int2", x="int1"), None),
     ]
     for aggregation, expected_result in tests:
         with self.subTest(aggregation=aggregation):
             # Empty result with non-execution optimization.
             with self.assertNumQueries(0):
                 values = StatTestModel.objects.none().aggregate(
                     aggregation=aggregation,
                 )
                 self.assertEqual(values, {"aggregation": expected_result})
             # Empty result when query must be executed.
             with self.assertNumQueries(1):
                 values = StatTestModel.objects.aggregate(
                     aggregation=aggregation,
                 )
                 self.assertEqual(values, {"aggregation": expected_result})
Ejemplo n.º 2
0
 def test_regr_count_empty_result(self):
     StatTestModel.objects.all().delete()
     values = StatTestModel.objects.aggregate(
         regrcount=RegrCount(y='int2', x='int1'))
     self.assertEqual(values, {'regrcount': 0})
Ejemplo n.º 3
0
 def test_regr_count_general(self):
     values = StatTestModel.objects.aggregate(
         regrcount=RegrCount(y='int2', x='int1'))
     self.assertEqual(values, {'regrcount': 3})
Ejemplo n.º 4
0
 def test_regr_count_default(self):
     msg = "RegrCount does not allow default."
     with self.assertRaisesMessage(TypeError, msg):
         RegrCount(y="int2", x="int1", default=0)
Ejemplo n.º 5
0
 def test_regr_count_general(self):
     values = StatTestModel.objects.aggregate(
         regrcount=RegrCount(y="int2", x="int1")
     )
     self.assertEqual(values, {"regrcount": 3})
Ejemplo n.º 6
0
 def test_regr_count_default(self):
     msg = 'RegrCount does not allow default.'
     with self.assertRaisesMessage(TypeError, msg):
         RegrCount(y='int2', x='int1', default=0)