<commit_before>import time
import datetime
import unittest
import locale

from nose.plugins import skip

from freezegun import freeze_time


class temp_locale(object):
    """Temporarily change the locale."""

    def __init__(self, target):
        self.target = target

    def __enter__(self):
        self.old = locale.setlocale(locale.LC_ALL)
        try:
            locale.setlocale(locale.LC_ALL, self.target)
        except locale.Error, e:
            msg = 'could not set %s locale: %s' % (self.target, e)
            raise skip.SkipTest(msg)

    def __exit__(self, *args):
        locale.setlocale(locale.LC_ALL, self.old)


def test_simple_api():
    # time to freeze is always provided in UTC
    freezer = freeze_time("2012-01-14")
    # expected timestamp must be a timestamp, corresponding to 2012-01-14 UTC
    local_time = datetime.datetime(2012, 1, 14)
    utc_time = local_time - datetime.timedelta(seconds=time.timezone)
    expected_timestamp = time.mktime(utc_time.timetuple())

    freezer.start()
    assert time.time() == expected_timestamp
    assert datetime.datetime.now() == datetime.datetime(2012, 1, 14)
    assert datetime.datetime.utcnow() == datetime.datetime(2012, 1, 14)
    assert datetime.date.today() == datetime.date(2012, 1, 14)
    assert datetime.datetime.now().today() == datetime.date(2012, 1, 14)
    freezer.stop()
    assert time.time() != expected_timestamp
    assert datetime.datetime.now() != datetime.datetime(2012, 1, 14)<commit_msg>Use Python 3 compatible except syntax<commit_after>import time
import datetime
import unittest
import locale

from nose.plugins import skip

from freezegun import freeze_time


class temp_locale(object):
    """Temporarily change the locale."""

    def __init__(self, target):
        self.target = target

    def __enter__(self):
        self.old = locale.setlocale(locale.LC_ALL)
        try:
            locale.setlocale(locale.LC_ALL, self.target)
        except locale.Error:
            msg = 'could not set %s locale' % self.target
            raise skip.SkipTest(msg)

    def __exit__(self, *args):
        locale.setlocale(locale.LC_ALL, self.old)


def test_simple_api():
    # time to freeze is always provided in UTC
    freezer = freeze_time("2012-01-14")
    # expected timestamp must be a timestamp, corresponding to 2012-01-14 UTC
    local_time = datetime.datetime(2012, 1, 14)
    utc_time = local_time - datetime.timedelta(seconds=time.timezone)
    expected_timestamp = time.mktime(utc_time.timetuple())

    freezer.start()
    assert time.time() == expected_timestamp
    assert datetime.datetime.now() == datetime.datetime(2012, 1, 14)
    assert datetime.datetime.utcnow() == datetime.datetime(2012, 1, 14)
    assert datetime.date.today() == datetime.date(2012, 1, 14)
    assert datetime.datetime.now().today() == datetime.date(2012, 1, 14)
    freezer.stop()
    assert time.time() != expected_timestamp
    assert datetime.datetime.now() != datetime.datetime(2012, 1, 14)
{'fraction_non_alphanumeric': 0.11363636363636363, 'fraction_numerical': 0.03910427807486631, 'mean_word_length': 3.3693430656934305, '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': '3708299', 'n_tokens_mistral': 996, 'n_tokens_neox': 883, 'n_words': 235}