<commit_before>"""
    tests.test_validation
    ~~~~~~~~~~~~~~~~~~~~~

    Provides unit tests for SQLAlchemy models which have some validation
    functionality and therefore raise validation errors when requests are made
    to write to the database.

    Validation is not provided by Flask-Restless itself, but it must capture
    validation errors and return them to the client.

    :copyright: 2012 <NAME> <<EMAIL>>
    :license: GNU AGPLv3+ or BSD

"""
import re

from unittest2 import TestSuite
from unittest2 import skipUnless

from flask import json

# for SAValidation package on pypi.python.org
try:
    import savalidation as _sav
    import savalidation.validators as sav
    sav_version = tuple(int(n) for n in _sav.VERSION.split('.'))
    has_savalidation = True
except:
    has_savalidation = False

from .helpers import setUpModule
from .helpers import tearDownModule
from .helpers import TestSupport

__all__ = ['SAVTest', 'SimpleValidationTest']

#: A regular expression for email addresses.
EMAIL_REGEX = re.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^"
                         "_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a"
                         "-z0-9](?:[a-z0-9-]*[a-z0-9])")

dumps = json.dumps
loads = json.loads


class SimpleValidationTest(TestSupport):
    """Tests for validation errors raised by the SQLAlchemy's simple built-in
    validation.

    For more information about this functionality, see the documentation for
    :func:`sqlalchemy.orm.validates`.

    """

    def setUp(self):
        """Create APIs for the validated models."""
        super(SimpleValidationTest, self).setUp()
        # for the sake of brevity...
        db = self.db<commit_msg>Use try/except/else syntax to separate code which may raise exceptions from code which does not.<commit_after>"""
    tests.test_validation
    ~~~~~~~~~~~~~~~~~~~~~

    Provides unit tests for SQLAlchemy models which have some validation
    functionality and therefore raise validation errors when requests are made
    to write to the database.

    Validation is not provided by Flask-Restless itself, but it must capture
    validation errors and return them to the client.

    :copyright: 2012 <NAME> <<EMAIL>>
    :license: GNU AGPLv3+ or BSD

"""
import re

from unittest2 import TestSuite
from unittest2 import skipUnless

from flask import json

# for SAValidation package on pypi.python.org
try:
    import savalidation as _sav
    import savalidation.validators as sav
except:
    has_savalidation = False
else:
    sav_version = tuple(int(n) for n in _sav.VERSION.split('.'))
    has_savalidation = True

from .helpers import setUpModule
from .helpers import tearDownModule
from .helpers import TestSupport

__all__ = ['SAVTest', 'SimpleValidationTest']

#: A regular expression for email addresses.
EMAIL_REGEX = re.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^"
                         "_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a"
                         "-z0-9](?:[a-z0-9-]*[a-z0-9])")

dumps = json.dumps
loads = json.loads


class SimpleValidationTest(TestSupport):
    """Tests for validation errors raised by the SQLAlchemy's simple built-in
    validation.

    For more information about this functionality, see the documentation for
    :func:`sqlalchemy.orm.validates`.

    """

    def setUp(self):
        """Create APIs for the validated models."""
        super(SimpleValidationTest, self).setUp()
        # for the sake of brevity...
        db = self.db
{'fraction_non_alphanumeric': 0.13337100875953659, 'fraction_numerical': 0.012998022040124329, 'mean_word_length': 3.229390681003584, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5415913', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1083, 'n_words': 342}