<commit_before>from __future__ import absolute_import

import datetime
from decimal import Decimal

from django.db.models import Q, F, Avg, Max, Min
from django.test import TestCase, Approximate

from aggregate_if import Sum, Count

from .models import Author, Publisher, Book, Store


class BaseAggregateTestCase(TestCase):
    fixtures = ["aggregation.json"]

    def test_empty_aggregate(self):
        self.assertEqual(Author.objects.all().aggregate(), {})

    def test_single_aggregate(self):
        vals = Author.objects.aggregate(Avg("age"))<commit_msg>Use conditional Avg on tests<commit_after>from __future__ import absolute_import

import datetime
from decimal import Decimal

from django.db.models import Q, F, Max, Min
from django.test import TestCase, Approximate

from aggregate_if import Sum, Count, Avg

from .models import Author, Publisher, Book, Store


class BaseAggregateTestCase(TestCase):
    fixtures = ["aggregation.json"]

    def test_empty_aggregate(self):
        self.assertEqual(Author.objects.all().aggregate(), {})

    def test_single_aggregate(self):
        vals = Author.objects.aggregate(Avg("age"))
{'fraction_non_alphanumeric': 0.09306409130816505, 'fraction_numerical': 0.0, 'mean_word_length': 4.846153846153846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5419242', 'n_tokens_mistral': 339, 'n_tokens_neox': 323, 'n_words': 95}