<commit_before># -*- coding: utf-8 -*-


from fields import *
from validators import *



def basefield_test():
    f = BaseField(validators=All(Number(min=3), Length(max=10)))
    value = f('7')
    assert isinstance(value, unicode)
    assert value == u'7'

    f = BaseField(default=12334, validators=Any(Equal('x'), Int()))
    value = f(1)
    assert isinstance(value, unicode)
    assert value == u'1'
    value = f(None)
    assert value == u'12334'



if __name__ == '__main__':
    import nose
    nose.main()

<commit_msg>add tests<commit_after># -*- coding: utf-8 -*-


from fields import *
from validators import *
from converters import *



def basefield_test():
    f = BaseField(validators=All(Number(min=3), Length(max=10)))
    value = f('7')
    assert isinstance(value, unicode)
    assert value == u'7'

    f = BaseField(default=12334, validators=Any(Equal('x'), Int()))
    value = f(1)
    assert isinstance(value, unicode)
    assert value == u'1'
    value = f(None)
    assert value == u'12334'

    f3 = BaseField(validators=Equal('m'), empty_value='')
    value = f3('')
    assert value is None
    try:
        f3('x')
    except ValidationError:
        pass
    else:
        raise AssertionError

    freq = BaseField(required=True, validators=Equal('zx'))
    try:
        freq(None)
    except RequiredError:
        pass
    else:
        raise AssertionError

    rconv = BaseField(validators=Equal('mmm'))
    from functools import partial
    rconv.converter = partial(int_converter, rconv) # DO NOT normally use!
    try:
        rconv('mmm')
    except ConversionError:
        pass
    else:
        raise AssertionError



if __name__ == '__main__':
    import nose
    nose.main()


{'fraction_non_alphanumeric': 0.13086276780544295, 'fraction_numerical': 0.0225825130283729, 'mean_word_length': 2.8831460674157303, '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': '3774241', 'n_tokens_mistral': 590, 'n_tokens_neox': 552, 'n_words': 143}