<commit_before>import unittest
from flask_restful import types
import datetime
#noinspection PyUnresolvedReferences
from nose.tools import assert_equals, assert_raises # you need it for tests in form of continuations

# http://docs.python.org/library/datetime.html?highlight=datetime#datetime.tzinfo.fromutc
ZERO = datetime.timedelta(0)
HOUR = datetime.timedelta(hours=1)


class UTC(datetime.tzinfo):
    """UTC"""

    def utcoffset(self, dt):
        return ZERO

    def tzname(self, dt):
        return "UTC"

    def dst(self, dt):
        return ZERO

def test_datetime_formatters():
    dates = [
        (datetime.datetime(2011, 1, 1), "Sat, 01 Jan 2011 00:00:00 -0000"),
        (datetime.datetime(2011, 1, 1, 23, 59, 59),
         "Sat, 01 Jan 2011 23:59:59 -0000"),
        (datetime.datetime(2011, 1, 1, 23, 59, 59, tzinfo=UTC()),
                  "Sat, 01 Jan 2011 23:59:59 -0000"),
        ]
    for date_obj, expected in dates:
        yield assert_equals, types.rfc822(date_obj), expected

def test_urls():
    urls = [
        'http://www.djangoproject.com/',
        'http://localhost/',
        'http://example.com/',
        'http://www.example.com/',
        'http://www.example.com:8000/test',
        'http://valid-with-hyphens.com/',
        'http://subdomain.example.com/',
        'http://192.168.3.11/',
        'http://192.168.3.11:8000/test',
        'http://valid-----hyphens.com/',
        'http://example.com?something=value',
        'http://example.com/index.php?something=value&another=value2',
        'http://foo:bar@example.com',
        'http://foo:@example.com',
        'http://foo:@2001:fdf8:f53e:61e4::18:370:7334',
        'http://foo2:<EMAIL>%<EMAIL>',
        ]

    for value in urls:
        yield assert_equals, types.url(value), value

def check_raises(exception, func, value):
    assert_raises(exception, lambda: func(value))

def test_bad_urls():
    values = [
        'foo',
        'http://',
        'http://example',
        'http://example.',
        'http://.com',
        'http://invalid-.com',
        'http://-invalid.com',
        'http://inv-.alid-.com',
        'http://inv-.-alid.com',
        'http://@foo:bar@example.com',
        'http://:bar@<EMAIL>',
        'http://bar:bar:bar@example.com',
    ]

    for value in values:
        yield check_raises, ValueError, types.url, value

def test_bad_url_error_message():
    values = [
        'google.com',
        'domain.google.com',
        'kevin:pass@google.com/path?query'
    ]

    for value in values:
        yield check_url_error_message, value

def check_url_error_message(value):
    try:
        types.url(value)
        assert False, "types.url({}) should raise an exception".format(value)
    except ValueError as e:
        assert_equals(e.message, ("{0} is not a valid URL. Did you mean: "
                                  "http://{0}".format(value)))

class TypesTestCase(unittest.TestCase):

    def test_boolean_false(self):
        self.assertEquals(types.boolean("False"), False)


    def test_boolean_true(self):
        self.assertEquals(types.boolean("true"), True)


    def test_boolean_upper_case(self):<commit_msg>use more modern exception message format<commit_after>import unittest
from flask_restful import types
import datetime
#noinspection PyUnresolvedReferences
from nose.tools import assert_equals, assert_raises # you need it for tests in form of continuations

# http://docs.python.org/library/datetime.html?highlight=datetime#datetime.tzinfo.fromutc
ZERO = datetime.timedelta(0)
HOUR = datetime.timedelta(hours=1)


class UTC(datetime.tzinfo):
    """UTC"""

    def utcoffset(self, dt):
        return ZERO

    def tzname(self, dt):
        return "UTC"

    def dst(self, dt):
        return ZERO

def test_datetime_formatters():
    dates = [
        (datetime.datetime(2011, 1, 1), "Sat, 01 Jan 2011 00:00:00 -0000"),
        (datetime.datetime(2011, 1, 1, 23, 59, 59),
         "Sat, 01 Jan 2011 23:59:59 -0000"),
        (datetime.datetime(2011, 1, 1, 23, 59, 59, tzinfo=UTC()),
                  "Sat, 01 Jan 2011 23:59:59 -0000"),
        ]
    for date_obj, expected in dates:
        yield assert_equals, types.rfc822(date_obj), expected

def test_urls():
    urls = [
        'http://www.djangoproject.com/',
        'http://localhost/',
        'http://example.com/',
        'http://www.example.com/',
        'http://www.example.com:8000/test',
        'http://valid-with-hyphens.com/',
        'http://subdomain.example.com/',
        'http://192.168.3.11/',
        'http://192.168.3.11:8000/test',
        'http://valid-----hyphens.com/',
        'http://example.com?something=value',
        'http://example.com/index.php?something=value&another=value2',
        'http://foo:bar@example.com',
        'http://foo:@example.com',
        'http://foo:@2001:db8:85a3::8a2e:370:7334',
        'http://foo2:qd1%r@example.com',
        ]

    for value in urls:
        yield assert_equals, types.url(value), value

def check_raises(exception, func, value):
    assert_raises(exception, lambda: func(value))

def test_bad_urls():
    values = [
        'foo',
        'http://',
        'http://example',
        'http://example.',
        'http://.com',
        'http://invalid-.com',
        'http://-invalid.com',
        'http://inv-.alid-.com',
        'http://inv-.-alid.com',
        'http://@foo:bar@<EMAIL>',
        'http://:bar@<EMAIL>.<EMAIL>',
        'http://bar:bar:bar@example.com',
    ]

    for value in values:
        yield check_raises, ValueError, types.url, value

def test_bad_url_error_message():
    values = [
        'google.com',
        'domain.google.com',
        'kevin:pass@google.com/path?query'
    ]

    for value in values:
        yield check_url_error_message, value

def check_url_error_message(value):
    try:
        types.url(value)
        assert False, "types.url({}) should raise an exception".format(value)
    except ValueError as e:
        assert_equals(str(e), ("{0} is not a valid URL. Did you mean: "
                               "http://{0}".format(value)))

class TypesTestCase(unittest.TestCase):

    def test_boolean_false(self):
        self.assertEquals(types.boolean("False"), False)


    def test_boolean_true(self):
        self.assertEquals(types.boolean("true"), True)


    def test_boolean_upper_case(self):
{'fraction_non_alphanumeric': 0.16076765770017304, 'fraction_numerical': 0.041371716218341986, 'mean_word_length': 2.4724194429273623, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5353959', 'n_tokens_mistral': 2289, 'n_tokens_neox': 2070, 'n_words': 408}