Commit 358fccbf authored by Federico Ceratto's avatar Federico Ceratto

Imported Upstream version 0.3.5

parent e88e10e0
[run]
include = freezegun/*
build
.coverage
*.egg-info
*.tox
dist
*.pyc
language: python
python:
- 2.6
- 2.7
- pypy
- 3.2
- 3.3
- 3.4
- pypy3
script: make travis
install:
- pip install .
- pip install -r requirements.txt
after_success:
- coveralls
SHELL := /bin/bash
init:
python setup.py develop
pip install -r requirements.txt
test:
rm -f .coverage
nosetests ./tests/
travis:
nosetests --with-coverage ./tests/
tdaemon:
tdaemon -t nose ./tests/ --custom-args="--with-growl"
publish:
python setup.py sdist bdist_wheel upload
Metadata-Version: 1.1
Name: freezegun
Version: 0.3.5
Summary: Let your Python tests travel through time
Home-page: https://github.com/spulec/freezegun
Author: Steve Pulec
Author-email: spulec@gmail
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
......@@ -25,7 +25,14 @@ Decorator
def test():
assert datetime.datetime.now() == datetime.datetime(2012, 01, 14)
# Or class based
# Or a unittest TestCase - freezes for every test, from the start of setUpClass to the end of tearDownClass
@freeze_time("1955-11-12")
class MyTests(unittest.TestCase):
def test_the_class(self):
assert datetime.datetime.now() == datetime.datetime(2012, 01, 14)
# Or any other class - freezes around each callable (may not work in every case)
@freeze_time("2012-01-14")
class Tester(object):
......@@ -70,7 +77,7 @@ Timezones
assert datetime.datetime.now() == datetime.datetime(2012, 01, 13, 23, 21, 34)
# datetime.date.today() uses local time
assert datetime.date.today() == datetime.datetime(2012, 01, 13)
assert datetime.date.today() == datetime.date(2012, 01, 13)
Nice inputs
~~~~~~~~~~~
......
Metadata-Version: 1.1
Name: freezegun
Version: 0.3.5
Summary: Let your Python tests travel through time
Home-page: https://github.com/spulec/freezegun
Author: Steve Pulec
Author-email: spulec@gmail
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
AUTHORS.rst
LICENSE
MANIFEST.in
README.rst
setup.cfg
setup.py
freezegun/__init__.py
freezegun/api.py
freezegun.egg-info/PKG-INFO
freezegun.egg-info/SOURCES.txt
freezegun.egg-info/dependency_links.txt
freezegun.egg-info/requires.txt
freezegun.egg-info/top_level.txt
tests/__init__.py
tests/__init__.pyc
tests/fake_module.py
tests/fake_module.pyc
tests/single_import_module.pyc
tests/test_class_import.py
tests/test_class_import.pyc
tests/test_datetimes.py
tests/test_datetimes.pyc
tests/test_import_alias.py
tests/test_import_alias.pyc
tests/test_operations.py
tests/test_operations.pyc
tests/test_pickle.py
tests/test_pickle.pyc
tests/test_sqlite2.pyc
tests/test_sqlite3.py
tests/test_sqlite3.pyc
tests/test_test.pyc
tests/test_ticking.py
tests/utils.py
tests/utils.pyc
tests/__pycache__/__init__.cpython-33.pyc
tests/__pycache__/fake_module.cpython-33.pyc
tests/__pycache__/test_class_import.cpython-27-PYTEST.pyc
tests/__pycache__/test_class_import.cpython-33.pyc
tests/__pycache__/test_datetimes.cpython-27-PYTEST.pyc
tests/__pycache__/test_datetimes.cpython-33.pyc
tests/__pycache__/test_import_alias.cpython-27-PYTEST.pyc
tests/__pycache__/test_operations.cpython-27-PYTEST.pyc
tests/__pycache__/test_operations.cpython-33.pyc
tests/__pycache__/test_pickle.cpython-27-PYTEST.pyc
tests/__pycache__/test_sqlite3.cpython-27-PYTEST.pyc
\ No newline at end of file
six
python-dateutil>=1.0, != 2.0
......@@ -10,7 +10,7 @@ freezegun
"""
__title__ = 'freezegun'
__version__ = '0.3.4'
__version__ = '0.3.5'
__author__ = 'Steve Pulec'
__license__ = 'Apache License 2.0'
__copyright__ = 'Copyright 2012 Steve Pulec'
......
This diff is collapsed.
[nosetests]
verbosity=1
detailed-errors=1
with-coverage=1
cover-package=freezegun
verbosity = 1
detailed-errors = 1
with-coverage = 1
cover-package = freezegun
[bdist_wheel]
universal=1
\ No newline at end of file
universal = 1
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
......@@ -13,7 +13,7 @@ else:
setup(
name='freezegun',
version='0.3.4',
version='0.3.5',
description='Let your Python tests travel through time',
author='Steve Pulec',
author_email='spulec@gmail',
......
......@@ -235,14 +235,54 @@ def test_decorator_wrapped_attribute():
assert wrapped.__wrapped__ is to_decorate
class Callable(object):
def __call__(self, *args, **kws):
return (args, kws)
@freeze_time("2012-01-14")
class Tester(object):
def test_the_class(self):
assert datetime.datetime.now() == datetime.datetime(2012, 1, 14)
def test_still_the_same(self):
assert datetime.datetime.now() == datetime.datetime(2012, 1, 14)
def test_class_name_preserved_by_decorator(self):
assert self.__class__.__name__ == "Tester"
class NotATestClass(object):
def perform_operation(self):
return datetime.date.today()
@freeze_time('2001-01-01')
def test_class_decorator_ignores_nested_class(self):
not_a_test = self.NotATestClass()
assert not_a_test.perform_operation() == datetime.date(2001, 1, 1)
a_mock = Callable()
def test_class_decorator_skips_callable_object_py2(self):
if sys.version_info[0] != 2:
raise skip.SkipTest("test target is Python2")
assert self.a_mock.__class__ == Callable
def test_class_decorator_wraps_callable_object_py3(self):
if sys.version_info[0] != 3:
raise skip.SkipTest("test target is Python3")
assert self.a_mock.__wrapped__.__class__ == Callable
@staticmethod
def helper():
return datetime.date.today()
def test_class_decorator_respects_staticmethod(self):
assert self.helper() == datetime.date(2012, 1, 14)
@freeze_time("Jan 14th, 2012")
def test_nice_datetime():
......@@ -308,73 +348,74 @@ def test_isinstance_without_active():
assert isinstance(today, datetime.date)
class Callable(object):
def __call__(self, *args, **kws):
return (args, kws)
@freeze_time('2013-04-09')
class TestUnitTestClassDecorator(unittest.TestCase):
a_mock = Callable()
class NotATestClass(object):
@classmethod
def setUpClass(cls):
assert datetime.date(2013, 4, 9) == datetime.date.today()
def perform_operation(self):
return datetime.date.today()
def setUp(self):
self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today())
@staticmethod
def helper():
return datetime.date.today()
def tearDown(self):
self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today())
@classmethod
def setUpClass(cls):
assert datetime.date(2013, 4, 9) != datetime.date.today()
def tearDownClass(cls):
assert datetime.date(2013, 4, 9) == datetime.date.today()
def setUp(self):
def test_class_decorator_works_on_unittest(self):
self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today())
def test_class_name_preserved_by_decorator(self):
self.assertEqual(self.__class__.__name__, "TestUnitTestClassDecorator")
@freeze_time('2013-04-09')
class TestUnitTestClassDecoratorWithNoSetUpOrTearDown(unittest.TestCase):
def test_class_decorator_works_on_unittest(self):
self.assertEqual(datetime.date(2013,4,9), datetime.date.today())
self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today())
def test_class_decorator_respects_staticmethod(self):
self.assertEqual(self.helper(), datetime.date(2013, 4, 9))
def test_class_decorator_skips_callable_object_py2(self):
if sys.version_info[0] != 2:
raise skip.SkipTest("test target is Python2")
self.assertEqual(self.a_mock.__class__, Callable)
class TestUnitTestClassDecoratorSubclass(TestUnitTestClassDecorator):
@classmethod
def setUpClass(cls):
# the super() call can fail if the class decoration was done wrong
super(TestUnitTestClassDecoratorSubclass, cls).setUpClass()
def test_class_decorator_wraps_callable_object_py3(self):
if sys.version_info[0] != 3:
raise skip.SkipTest("test target is Python3")
self.assertEqual(self.a_mock.__wrapped__.__class__, Callable)
@classmethod
def tearDownClass(cls):
# the super() call can fail if the class decoration was done wrong
super(TestUnitTestClassDecoratorSubclass, cls).tearDownClass()
@freeze_time('2001-01-01')
def test_class_decorator_ignores_nested_class(self):
not_a_test = self.NotATestClass()
self.assertEqual(not_a_test.perform_operation(), datetime.date(2001, 1, 1))
def test_class_name_preserved_by_decorator(self):
self.assertEqual(self.__class__.__name__,
"TestUnitTestClassDecoratorSubclass")
@freeze_time('2013-04-09')
class TestUnitTestClassDecoratorWithSetup(unittest.TestCase):
def setUp(self):
class BaseInheritanceFreezableTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass
def test_class_decorator_works_on_unittest(self):
self.assertEqual(datetime.date(2013,4,9), datetime.date.today())
def assert_class_of_datetimes(right_class, wrong_class):
assert datetime.datetime.min.__class__ == right_class
assert datetime.datetime.max.__class__ == right_class
assert datetime.date.min.__class__ == right_class
assert datetime.date.max.__class__ == right_class
assert datetime.datetime.min.__class__ != wrong_class
assert datetime.datetime.max.__class__ != wrong_class
assert datetime.date.min.__class__ != wrong_class
assert datetime.date.max.__class__ != wrong_class
@classmethod
def tearDownClass(cls):
pass
class UnfrozenInheritedTests(BaseInheritanceFreezableTests):
def test_time_is_not_frozen(self):
# In this class, time should not be frozen - and the below decorated
# class shouldn't affect that
self.assertNotEqual(datetime.date(2013, 4, 9), datetime.date.today())
@freeze_time('2013-04-09')
class FrozenInheritedTests(BaseInheritanceFreezableTests):
def test_time_is_frozen(self):
# In this class, time should be frozen
self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today())
def test_min_and_max():
......
import datetime
import time
import mock
from freezegun import freeze_time
from tests import utils
@utils.cpython_only
def test_ticking_datetime():
with freeze_time("Jan 14th, 2012", tick=True):
assert datetime.datetime.now() > datetime.datetime(2012, 1, 14)
@utils.cpython_only
def test_ticking_date():
with freeze_time("Jan 14th, 2012, 23:59:59.9999999", tick=True):
assert datetime.date.today() == datetime.date(2012, 1, 15)
@utils.cpython_only
def test_ticking_time():
with freeze_time("Jan 14th, 2012, 23:59:59", tick=True):
assert time.time() > 1326585599.0
@mock.patch('freezegun.api._is_cpython', lambda: False)
def test_pypy_compat():
try:
freeze_time("Jan 14th, 2012, 23:59:59", tick=True)
except SystemError:
pass
else:
raise AssertionError("tick=True should not error on cpython")
@mock.patch('freezegun.api._is_cpython', lambda: True)
def test_non_pypy_compat():
try:
freeze_time("Jan 14th, 2012, 23:59:59", tick=True)
except Exception:
raise AssertionError("tick=True should error on non cpython")
from freezegun.api import FakeDate, FakeDatetime
from functools import wraps
from nose.plugins import skip
from freezegun.api import FakeDate, FakeDatetime, _is_cpython
def is_fake_date(obj):
......@@ -7,3 +11,12 @@ def is_fake_date(obj):
def is_fake_datetime(obj):
return obj.__class__ is FakeDatetime
def cpython_only(func):
@wraps(func)
def wrapper(*args):
if not _is_cpython():
raise skip.SkipTest("tick=True on pypy")
return func(*args)
return wrapper
File added
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py26, py27, pypy, py32, py33, py34, pypy3
[testenv]
commands = make test
whitelist_externals = make
deps =
nose
coverage
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