Commit 72e3341a authored by Federico Ceratto's avatar Federico Ceratto

New upstream version 0.3.10

parent eb75dec2
......@@ -13,3 +13,4 @@ Patches and Suggestions
- `Zach Smith <https://github.com/zmsmith>`_
- `Adam Johnson <https://github.com/adamchainz>`_
- `Alex Ehlke <https://github.com/aehlke>`_
- `James Lu <github.com/CrazyPython>`_
......@@ -4,6 +4,13 @@ Freezegun Changelog
Latest
------
0.3.10
------
* Performance improvements
* Coroutine support
*
0.3.9
-----
......
Metadata-Version: 1.1
Name: freezegun
Version: 0.3.9
Version: 0.3.10
Summary: Let your Python tests travel through time
Home-page: https://github.com/spulec/freezegun
Author: Steve Pulec
Author-email: spulec@gmail.com
License: Apache 2.0
Description-Content-Type: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Classifier: License :: OSI Approved :: Apache Software License
......@@ -14,3 +15,5 @@ Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.6
......@@ -82,6 +82,10 @@ Timezones
# datetime.date.today() uses local time
assert datetime.date.today() == datetime.date(2012, 1, 13)
@freeze_time("2012-01-14 03:21:34", tz_offset=-datetime.timedelta(hours=3, minutes=30))
def test_timedelta_offset():
assert datetime.datetime.now() == datetime.datetime(2012, 1, 13, 23, 51, 34)
Nice inputs
~~~~~~~~~~~
......@@ -93,6 +97,28 @@ FreezeGun uses dateutil behind the scenes so you can have nice-looking datetimes
def test_nice_datetime():
assert datetime.datetime.now() == datetime.datetime(2012, 1, 14)
Function and generator objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FreezeGun is able to handle function and generator objects.
.. code-block:: python
def test_lambda():
with freeze_time(lambda: datetime.datetime(2012, 1, 14)):
assert datetime.datetime.now() == datetime.datetime(2012, 1, 14)
def test_generator():
datetimes = (datetime.datetime(year, 1, 1) for year in range(2010, 2012))
with freeze_time(datetimes):
assert datetime.datetime.now() == datetime.datetime(2010, 1, 1)
with freeze_time(datetimes):
assert datetime.datetime.now() == datetime.datetime(2011, 1, 1)
# The next call to freeze_time(datetimes) would raise a StopIteration exception.
``tick`` argument
~~~~~~~~~~~~~~~~~
......@@ -149,6 +175,13 @@ Freezegun allows moving time to specific dates.
frozen_datetime.move_to(initial_datetime)
assert frozen_datetime() == initial_datetime
@freeze_time("2012-01-14", as_arg=True)
def test(frozen_time):
assert datetime.datetime.now() == datetime.datetime(2012, 1, 14)
frozen_time.move_to("2014-02-12")
assert datetime.datetime.now() == datetime.datetime(2014, 2, 12)
Parameter for ``move_to`` can be any valid ``freeze_time`` date (string, date, datetime).
......
Metadata-Version: 1.1
Name: freezegun
Version: 0.3.9
Version: 0.3.10
Summary: Let your Python tests travel through time
Home-page: https://github.com/spulec/freezegun
Author: Steve Pulec
Author-email: spulec@gmail.com
License: Apache 2.0
Description-Content-Type: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Classifier: License :: OSI Approved :: Apache Software License
......@@ -14,3 +15,5 @@ Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.6
......@@ -6,6 +6,7 @@ README.rst
setup.cfg
setup.py
freezegun/__init__.py
freezegun/_async.py
freezegun/api.py
freezegun.egg-info/PKG-INFO
freezegun.egg-info/SOURCES.txt
......@@ -15,6 +16,7 @@ freezegun.egg-info/top_level.txt
tests/__init__.py
tests/another_module.py
tests/fake_module.py
tests/test_asyncio.py
tests/test_class_import.py
tests/test_datetimes.py
tests/test_import_alias.py
......
six
python-dateutil>=1.0, != 2.0
python-dateutil!=2.0,>=1.0
......@@ -9,7 +9,7 @@ freezegun
from .api import freeze_time
__title__ = 'freezegun'
__version__ = '0.3.9'
__version__ = '0.3.10'
__author__ = 'Steve Pulec'
__license__ = 'Apache License 2.0'
__copyright__ = 'Copyright 2012 Steve Pulec'
......
import functools
import asyncio
def wrap_coroutine(api, coroutine):
@functools.wraps(coroutine)
@asyncio.coroutine
def wrapper(*args, **kwargs):
with api as time_factory:
if api.as_arg:
result = yield from coroutine(time_factory, *args, **kwargs)
else:
result = yield from coroutine(*args, **kwargs)
return result
return wrapper
This diff is collapsed.
......@@ -10,5 +10,4 @@ universal = 1
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
......@@ -11,10 +11,14 @@ else:
# Py3k
requires += ['python-dateutil>=2.0']
with open('README.rst') as f:
readme = f.read()
setup(
name='freezegun',
version='0.3.9',
version='0.3.10',
description='Let your Python tests travel through time',
long_desciption=readme,
author='Steve Pulec',
author_email='spulec@gmail.com',
url='https://github.com/spulec/freezegun',
......@@ -29,5 +33,7 @@ setup(
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.6',
],
)
import datetime
from textwrap import dedent
from nose.plugins import skip
from freezegun import freeze_time
try:
import asyncio
except ImportError:
asyncio = False
def test_time_freeze_coroutine():
if not asyncio:
raise skip.SkipTest('asyncio required')
@asyncio.coroutine
@freeze_time('1970-01-01')
def frozen_coroutine():
assert datetime.date.today() == datetime.date(1970, 1, 1)
asyncio.get_event_loop().run_until_complete(frozen_coroutine())
def test_time_freeze_async_def():
try:
exec('async def foo(): pass')
except SyntaxError:
raise skip.SkipTest('async def not supported')
else:
exec(dedent('''
@freeze_time('1970-01-01')
async def frozen_coroutine():
assert datetime.date.today() == datetime.date(1970, 1, 1)
asyncio.get_event_loop().run_until_complete(frozen_coroutine())
'''))
......@@ -5,6 +5,7 @@ import locale
import sys
from nose.plugins import skip
from nose.tools import assert_raises
from tests import utils
from freezegun import freeze_time
......@@ -76,6 +77,15 @@ def test_tz_offset():
freezer.stop()
def test_timedelta_tz_offset():
freezer = freeze_time("2012-01-14 03:21:34",
tz_offset=-datetime.timedelta(hours=3, minutes=30))
freezer.start()
assert datetime.datetime.now() == datetime.datetime(2012, 1, 13, 23, 51, 34)
assert datetime.datetime.utcnow() == datetime.datetime(2012, 1, 14, 3, 21, 34)
freezer.stop()
def test_tz_offset_with_today():
freezer = freeze_time("2012-01-14", tz_offset=-4)
freezer.start()
......@@ -137,6 +147,21 @@ def test_manual_increment():
assert frozen_datetime() == initial_datetime
def test_manual_increment_seconds():
initial_datetime = datetime.datetime(year=1, month=7, day=12,
hour=15, minute=6, second=3)
with freeze_time(initial_datetime) as frozen_datetime:
assert frozen_datetime() == initial_datetime
frozen_datetime.tick()
initial_datetime += datetime.timedelta(seconds=1)
assert frozen_datetime() == initial_datetime
frozen_datetime.tick(10)
initial_datetime += datetime.timedelta(seconds=10)
assert frozen_datetime() == initial_datetime
def test_move_to():
initial_datetime = datetime.datetime(year=1, month=7, day=12,
hour=15, minute=6, second=3)
......@@ -248,6 +273,35 @@ def test_datetime_object():
assert datetime_freezer.time_to_freeze == regular_freezer.time_to_freeze
def test_function_object():
frozen_datetime = datetime.datetime(year=2012, month=11, day=10,
hour=4, minute=15, second=30)
def function(): return frozen_datetime
with freeze_time(function):
assert frozen_datetime == datetime.datetime.now()
def test_lambda_object():
frozen_datetime = datetime.datetime(year=2012, month=11, day=10,
hour=4, minute=15, second=30)
with freeze_time(lambda: frozen_datetime):
assert frozen_datetime == datetime.datetime.now()
def test_generator_object():
frozen_datetimes = (datetime.datetime(year=y, month=1, day=1)
for y in range(2010, 2012))
with freeze_time(frozen_datetimes):
assert datetime.datetime(2010, 1, 1) == datetime.datetime.now()
with freeze_time(frozen_datetimes):
assert datetime.datetime(2011, 1, 1) == datetime.datetime.now()
assert_raises(StopIteration, freeze_time, frozen_datetimes)
def test_old_datetime_object():
frozen_datetime = datetime.datetime(year=1, month=7, day=12,
hour=15, minute=6, second=3)
......
from __future__ import print_function, absolute_import, unicode_literals
import datetime
import uuid
from nose.tools import assert_equal
from freezegun import freeze_time
def time_from_uuid(value):
"""Converts an UUID(1) to it's datetime value"""
"""
Converts an UUID(1) to it's datetime value
"""
uvalue = value if isinstance(value, uuid.UUID) else uuid.UUID(value)
assert uvalue.version == 1
return (datetime.datetime(1582, 10, 15) +
datetime.timedelta(microseconds=uvalue.time // 10))
def test_uuid1():
# Test that the uuid.uuid1() methods generate a value from the freezed date
# This was not always the case as python is
# using the system's one if available through ctypes
target = datetime.datetime(2017, 2, 6, 14, 8, 21)
with freeze_time(target):
assert time_from_uuid(uuid.uuid1()) == target
def test_uuid1_future():
"""
Test that we can go back in time after setting a future date.
Normally UUID1 would disallow this, since it keeps track of
the _last_timestamp, but we override that now.
"""
future_target = datetime.datetime(2056, 2, 6, 14, 3, 21)
with freeze_time(future_target):
assert_equal(time_from_uuid(uuid.uuid1()), future_target)
past_target = datetime.datetime(1978, 7, 6, 23, 6, 31)
with freeze_time(past_target):
assert_equal(time_from_uuid(uuid.uuid1()), past_target)
def test_uuid1_past():
"""
Test that we can go forward in time after setting some time in the past.
This is simply the opposite of test_uuid1_future()
"""
past_target = datetime.datetime(1978, 7, 6, 23, 6, 31)
with freeze_time(past_target):
assert_equal(time_from_uuid(uuid.uuid1()), past_target)
future_target = datetime.datetime(2056, 2, 6, 14, 3, 21)
with freeze_time(future_target):
assert_equal(time_from_uuid(uuid.uuid1()), future_target)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment