<commit_before>
from django.test import TestCase

from nap import fields

class SourceObj(object):
    def __init__(self):
        self.bool = True
        self.int = 1
        self.str = 'test'

class FieldTestCase(TestCase):
    '''
    Field cycles:
    deflate: digattr -> reduce -> data[name]
    inflate: data[name] -> restore -> dest[name]
    '''

    def setUp(self):
        self.src = SourceObj()
        self.dest = {}

    def test_001_boolean(self):
        field = fields.BooleanField()
        field.deflate('bool', self.src, self.dest)
        self.assertEqual(self.dest['bool'], self.src.bool)

        data = {}
        field.inflate('bool', self.dest, data)
        self.assertEqual(data['bool'], True)<commit_msg>Add more fields tests<commit_after>
from django.test import TestCase

from nap import fields

class Mock(object):
    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)

class FieldTestCase(TestCase):
    '''
    Field cycles:
    deflate: digattr -> reduce -> data[name]
    inflate: data[name] -> restore -> dest[name]
    '''

    def test_000_field(self):
        data = {}
        field = fields.Field()

        field.deflate('value', Mock(value='str'), data)
        self.assertEqual('str', data['value'])

        field.deflate('value', Mock(value=None), data)
        self.assertTrue(data['value'] is None)

        dest = {}

        field.inflate('value', data, dest)
        self.assertEqual(dest['value'], data['value'])

    def test_000_field_default(self):
        data = {}
        field = fields.Field()

        field.deflate('value', Mock(), data)
        self.assertNotIn('value', data)

    def test_001_boolean(self):
        data = {}
        field = fields.BooleanField()

        field.deflate('value', Mock(value=True), data)
        self.assertTrue(data['value'] is True)

        dest = {}

        field.inflate('value', data, dest)
        self.assertTrue(dest['value'] is True)

    def test_002_integer(self):
        data = {}
        field = fields.IntegerField()

        field.deflate('value', Mock(value=7), data)
        self.assertEqual(data['value'], 7)

        dest = {}

        field.inflate('value', data, dest)
        self.assertEqual(dest['value'], data['value'])

    def test_003_decimal(self):
        from decimal import Decimal
        data = {}
        field = fields.DecimalField()

        field.deflate('value', Mock(value=Decimal('1.05')), data)
        self.assertEqual(data['value'], 1.05)

        dest = {}

        field.inflate('value', data, dest)
        self.assertEqual(dest['value'], data['value'])

    def test_004_datetime(self):
        from datetime import datetime
        data = {}
        field = fields.DateTimeField()

        when = datetime(2010, 11, 5, 12, 7, 19)
        field.deflate('value', Mock(value=when), data)
        self.assertEqual(data['value'], '2010-11-05 12:07:19')

        dest = {}

        field.inflate('value', data, dest)
        self.assertEqual(dest['value'], when)

{'fraction_non_alphanumeric': 0.14893617021276595, 'fraction_numerical': 0.018330605564648116, 'mean_word_length': 2.4531073446327682, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5291016', 'n_tokens_mistral': 967, 'n_tokens_neox': 906, 'n_words': 201}