<commit_before>import os
import mock

from django.test import TestCase
from requests import RequestException

from django.test import RequestFactory

from djlotrek.utils import group_objects_by_attribute, order_dict_from_list
from djlotrek.aes import decode


class UtilsTestCase(TestCase):

    def setUp(self):
        pass

    def test_group_objects_by_attribute(self):
        """Our beloved get_host_url utility"""
        class Human():
            name = ''
            age = 0

            def __init__(self, name, age):
                self.name = name
                self.age = age

        humans = []
        humans.append(Human('Andrea', 30))
        humans.append(Human('Marco', 30))
        humans.append(Human('Salvatore', 22))
        humans.append(Human('Giulio', 22))
        humans.append(Human('Ale', 26))

        grouped_objects = group_objects_by_attribute(humans, 'age')

        self.assertEqual (len(grouped_objects[30]), 2)
        self.assertEqual (len(grouped_objects[26]), 1)
        self.assertEqual (len(grouped_objects[22]), 2)

    def test_order_dict_from_list(self):
        """Our beloved get_host_url utility"""
        my_dict = {
            'italian' : 'ciao',
            'english' : 'hello',
            'spanish' : 'hola',
        }

        ordered_dict = order_dict_from_list(my_dict, ['english', 'spanish', 'italian', 'german'])
        self.assertEqual(list(ordered_dict.keys()), ['english', 'spanish', 'italian'])<commit_msg>Add doctest for utils test :rocket:<commit_after>import os
import mock

from django.test import TestCase
from requests import RequestException

from django.test import RequestFactory

from djlotrek.utils import group_objects_by_attribute, order_dict_from_list
from djlotrek.aes import decode


class UtilsTestCase(TestCase):

    def test_group_objects_by_attribute(self):
        """
        group_objects_by_attribute utils use for group objects and attribute
        together in a dictionary object
        """
        class Human():
            name = ''
            age = 0

            def __init__(self, name, age):
                self.name = name
                self.age = age

        humans = []
        humans.append(Human('Andrea', 30))
        humans.append(Human('Marco', 30))
        humans.append(Human('Salvatore', 22))
        humans.append(Human('Giulio', 22))
        humans.append(Human('Ale', 26))

        grouped_objects = group_objects_by_attribute(humans, 'age')

        self.assertEqual (len(grouped_objects[30]), 2)
        self.assertEqual (len(grouped_objects[26]), 1)
        self.assertEqual (len(grouped_objects[22]), 2)

    def test_order_dict_from_list(self):
        """
        order_dict_from_list utils pass dictionary and ordered key list
        then return ordered dictionary
        """
        my_dict = {
            'italian' : 'ciao',
            'english' : 'hello',
            'spanish' : 'hola',
        }

        ordered_dict = order_dict_from_list(my_dict, ['english', 'spanish', 'italian', 'german'])
        self.assertEqual(list(ordered_dict.keys()), ['english', 'spanish', 'italian'])
{'fraction_non_alphanumeric': 0.11367275056035862, 'fraction_numerical': 0.012808197246237591, 'mean_word_length': 2.6538011695906434, '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': '3368607', 'n_tokens_mistral': 968, 'n_tokens_neox': 910, 'n_words': 208}