<commit_before>from test.lib.testing import eq_, assert_raises, assert_raises_message
from test.lib import testing, fixtures

try:
    from sqlalchemy.cprocessors import str_to_datetime as c_str_to_datetime, \
                                    str_to_date as c_str_to_date, \
                                    str_to_time as c_str_to_time
    from sqlalchemy.processors import py_fallback
    for key, value in py_fallback().items():
        globals()["py_%s" % key] = value
except:
    from sqlalchemy.processors import str_to_datetime as py_str_to_datetime, \
                                        str_to_date as py_str_to_date, \
                                        str_to_time as py_str_to_time

class DateProcessorTest(fixtures.TestBase):
    @testing.requires.cextensions
    def test_c_date_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse date string '2012' - value is not a string",
            c_str_to_date, 2012
        )

    def test_py_date_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse date string '2012' - value is not a string",
            py_str_to_date, 2012
        )

    @testing.requires.cextensions
    def test_c_datetime_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse datetime string '2012' - value is not a string",
            c_str_to_datetime, 2012
        )

    def test_py_datetime_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse datetime string '2012' - value is not a string",
            py_str_to_datetime, 2012
        )

    @testing.requires.cextensions
    def test_c_time_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse time string '2012' - value is not a string",
            c_str_to_time, 2012
        )

    def test_py_time_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse time string '2012' - value is not a string",
            py_str_to_time, 2012
        )

    @testing.requires.cextensions
    def test_c_date_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse date string: '5:a'",
            c_str_to_date, "5:a"
        )

    def test_py_date_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse date string: '5:a'",
            py_str_to_date, "5:a"
        )

    @testing.requires.cextensions
    def test_c_datetime_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse datetime string: '5:a'",
            c_str_to_datetime, "5:a"
        )

    def test_py_datetime_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse datetime string: '5:a'",
            py_str_to_datetime, "5:a"
        )

    @testing.requires.cextensions
    def test_c_time_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse time string: '5:a'",
            c_str_to_time, "5:a"
        )

    def test_py_time_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse time string: '5:a'",
            py_str_to_time, "5:a"
        )

<commit_msg>cleanup test_processors, modeling the PEP 399 style<commit_after>from test.lib import fixtures
from test.lib.testing import assert_raises_message

from sqlalchemy import processors
try:
    from sqlalchemy import cprocessors
except ImportError:
    cprocessors = None

class _DateProcessorTest(fixtures.TestBase):
    def test_date_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse date string '2012' - value is not a string",
            self.module.str_to_date, 2012
        )

    def test_datetime_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse datetime string '2012' - value is not a string",
            self.module.str_to_datetime, 2012
        )

    def test_time_no_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse time string '2012' - value is not a string",
            self.module.str_to_time, 2012
        )

    def test_date_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse date string: '5:a'",
            self.module.str_to_date, "5:a"
        )

    def test_datetime_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse datetime string: '5:a'",
            self.module.str_to_datetime, "5:a"
        )

    def test_time_invalid_string(self):
        assert_raises_message(
            ValueError,
            "Couldn't parse time string: '5:a'",
            self.module.str_to_time, "5:a"
        )


class PyDateProcessorTest(_DateProcessorTest):
    module = processors


class CDateProcessorTest(_DateProcessorTest):
    __requires__ = ('cextensions',)
    module = cprocessors
{'fraction_non_alphanumeric': 0.07493240633449208, 'fraction_numerical': 0.017960602549246814, 'mean_word_length': 2.0864123957091776, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805923', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1537, 'n_words': 339}