Update upstream source from tag 'upstream/1.0.0'
Update to upstream version '1.0.0'
with Debian dir 1675e992f9ab869dbc503fa54f54e984d3bfcc62
Federico Ceratto
3 years ago
14 | 14 | - `Alex Ehlke <https://github.com/aehlke>`_ |
15 | 15 | - `James Lu <github.com/CrazyPython>`_ |
16 | 16 | - `Dan Elkis <github.com/rinslow>`_ |
17 | - `Bastien Vallet <github.com/djailla>`_ |
2 | 2 | |
3 | 3 | Latest |
4 | 4 | ------ |
5 | ||
6 | 1.0.0 | |
7 | ------ | |
8 | ||
9 | * Dropped Py2 support | |
10 | * Added as_kwarg argument in order to have the frozen time object passed with the name provided in as_kwarg argument | |
5 | 11 | |
6 | 12 | 0.3.15 |
7 | 13 | ------ |
0 | 0 | Metadata-Version: 1.2 |
1 | 1 | Name: freezegun |
2 | Version: 0.3.15 | |
2 | Version: 1.0.0 | |
3 | 3 | Summary: Let your Python tests travel through time |
4 | 4 | Home-page: https://github.com/spulec/freezegun |
5 | 5 | Author: Steve Pulec |
50 | 50 | def test_the_class(self): |
51 | 51 | assert datetime.datetime.now() == datetime.datetime(2012, 1, 14) |
52 | 52 | |
53 | # Or method decorator, might also pass frozen time object as kwarg | |
54 | ||
55 | class TestUnitTestMethodDecorator(unittest.TestCase): | |
56 | @freeze_time('2013-04-09') | |
57 | def test_method_decorator_works_on_unittest(self): | |
58 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
59 | ||
60 | @freeze_time('2013-04-09', as_kwarg='frozen_time') | |
61 | def test_method_decorator_works_on_unittest(self, frozen_time): | |
62 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
63 | self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today()) | |
64 | ||
65 | @freeze_time('2013-04-09', as_kwarg='hello') | |
66 | def test_method_decorator_works_on_unittest(self, **kwargs): | |
67 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
68 | self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.today()) | |
69 | ||
53 | 70 | Context manager |
54 | 71 | ~~~~~~~~~~~~~~~ |
55 | 72 | |
244 | 261 | |
245 | 262 | Platform: UNKNOWN |
246 | 263 | Classifier: License :: OSI Approved :: Apache Software License |
247 | Classifier: Programming Language :: Python :: 2 | |
248 | Classifier: Programming Language :: Python :: 2.7 | |
249 | 264 | Classifier: Programming Language :: Python :: 3 |
250 | 265 | Classifier: Programming Language :: Python :: 3.5 |
251 | 266 | Classifier: Programming Language :: Python :: 3.6 |
253 | 268 | Classifier: Programming Language :: Python :: 3.8 |
254 | 269 | Classifier: Programming Language :: Python :: Implementation :: CPython |
255 | 270 | Classifier: Programming Language :: Python :: Implementation :: PyPy |
256 | Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* | |
271 | Requires-Python: >=3.5 |
42 | 42 | def test_the_class(self): |
43 | 43 | assert datetime.datetime.now() == datetime.datetime(2012, 1, 14) |
44 | 44 | |
45 | # Or method decorator, might also pass frozen time object as kwarg | |
46 | ||
47 | class TestUnitTestMethodDecorator(unittest.TestCase): | |
48 | @freeze_time('2013-04-09') | |
49 | def test_method_decorator_works_on_unittest(self): | |
50 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
51 | ||
52 | @freeze_time('2013-04-09', as_kwarg='frozen_time') | |
53 | def test_method_decorator_works_on_unittest(self, frozen_time): | |
54 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
55 | self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today()) | |
56 | ||
57 | @freeze_time('2013-04-09', as_kwarg='hello') | |
58 | def test_method_decorator_works_on_unittest(self, **kwargs): | |
59 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
60 | self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.today()) | |
61 | ||
45 | 62 | Context manager |
46 | 63 | ~~~~~~~~~~~~~~~ |
47 | 64 |
8 | 8 | from .api import freeze_time |
9 | 9 | |
10 | 10 | __title__ = 'freezegun' |
11 | __version__ = '0.3.15' | |
11 | __version__ = '1.0.0' | |
12 | 12 | __author__ = 'Steve Pulec' |
13 | 13 | __license__ = 'Apache License 2.0' |
14 | 14 | __copyright__ = 'Copyright 2012 Steve Pulec' |
512 | 512 | |
513 | 513 | class _freeze_time(object): |
514 | 514 | |
515 | ||
516 | def __init__(self, time_to_freeze_str, tz_offset, ignore, tick, as_arg, auto_tick_seconds): | |
515 | def __init__(self, time_to_freeze_str, tz_offset, ignore, tick, as_arg, as_kwarg, auto_tick_seconds): | |
517 | 516 | self.time_to_freeze = _parse_time_to_freeze(time_to_freeze_str) |
518 | 517 | self.tz_offset = _parse_tz_offset(tz_offset) |
519 | 518 | self.ignore = tuple(ignore) |
522 | 521 | self.undo_changes = [] |
523 | 522 | self.modules_at_start = set() |
524 | 523 | self.as_arg = as_arg |
524 | self.as_kwarg = as_kwarg | |
525 | 525 | |
526 | 526 | def __call__(self, func): |
527 | 527 | if inspect.isclass(func): |
692 | 692 | continue |
693 | 693 | elif mod_name.startswith(self.ignore) or mod_name.endswith('.six.moves'): |
694 | 694 | continue |
695 | elif (not hasattr(module, "__name__") or module.__name__ in ('datetime', 'time')): | |
695 | elif not hasattr(module, "__name__") or module.__name__ in ('datetime', 'time'): | |
696 | 696 | continue |
697 | 697 | for module_attribute in dir(module): |
698 | 698 | |
728 | 728 | def decorate_callable(self, func): |
729 | 729 | def wrapper(*args, **kwargs): |
730 | 730 | with self as time_factory: |
731 | if self.as_arg: | |
731 | if self.as_arg and self.as_kwarg: | |
732 | assert False, "You can't specify both as_arg and as_kwarg at the same time. Pick one." | |
733 | elif self.as_arg: | |
732 | 734 | result = func(time_factory, *args, **kwargs) |
735 | elif self.as_kwarg: | |
736 | kwargs[self.as_kwarg] = time_factory | |
737 | result = func(*args, **kwargs) | |
733 | 738 | else: |
734 | 739 | result = func(*args, **kwargs) |
735 | 740 | return result |
742 | 747 | return wrapper |
743 | 748 | |
744 | 749 | |
745 | def freeze_time(time_to_freeze=None, tz_offset=0, ignore=None, tick=False, as_arg=False, auto_tick_seconds=0): | |
750 | def freeze_time(time_to_freeze=None, tz_offset=0, ignore=None, tick=False, as_arg=False, as_kwarg='', | |
751 | auto_tick_seconds=0): | |
746 | 752 | acceptable_times = (type(None), _string_type, datetime.date, datetime.timedelta, |
747 | 753 | types.FunctionType, types.GeneratorType) |
748 | 754 | |
769 | 775 | if ignore is None: |
770 | 776 | ignore = [] |
771 | 777 | ignore = ignore[:] |
772 | ignore.append('nose.plugins') | |
773 | ignore.append('six.moves') | |
774 | ignore.append('django.utils.six.moves') | |
775 | ignore.append('google.gax') | |
776 | ignore.append('threading') | |
777 | ignore.append('Queue') | |
778 | ignore.append('selenium') | |
779 | ignore.append('_pytest.terminal.') | |
780 | ignore.append('_pytest.runner.') | |
781 | ||
782 | return _freeze_time(time_to_freeze, tz_offset, ignore, tick, as_arg, auto_tick_seconds) | |
778 | ignore.extend(['nose.plugins', | |
779 | 'six.moves', | |
780 | 'django.utils.six.moves', | |
781 | 'google.gax', | |
782 | 'threading', | |
783 | 'Queue', | |
784 | 'selenium', | |
785 | '_pytest.terminal.', | |
786 | '_pytest.runner.', | |
787 | 'gi', | |
788 | ]) | |
789 | ||
790 | return _freeze_time(time_to_freeze, tz_offset, ignore, tick, as_arg, as_kwarg, auto_tick_seconds) | |
783 | 791 | |
784 | 792 | |
785 | 793 | # Setup adapters for sqlite |
0 | 0 | Metadata-Version: 1.2 |
1 | 1 | Name: freezegun |
2 | Version: 0.3.15 | |
2 | Version: 1.0.0 | |
3 | 3 | Summary: Let your Python tests travel through time |
4 | 4 | Home-page: https://github.com/spulec/freezegun |
5 | 5 | Author: Steve Pulec |
50 | 50 | def test_the_class(self): |
51 | 51 | assert datetime.datetime.now() == datetime.datetime(2012, 1, 14) |
52 | 52 | |
53 | # Or method decorator, might also pass frozen time object as kwarg | |
54 | ||
55 | class TestUnitTestMethodDecorator(unittest.TestCase): | |
56 | @freeze_time('2013-04-09') | |
57 | def test_method_decorator_works_on_unittest(self): | |
58 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
59 | ||
60 | @freeze_time('2013-04-09', as_kwarg='frozen_time') | |
61 | def test_method_decorator_works_on_unittest(self, frozen_time): | |
62 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
63 | self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today()) | |
64 | ||
65 | @freeze_time('2013-04-09', as_kwarg='hello') | |
66 | def test_method_decorator_works_on_unittest(self, **kwargs): | |
67 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
68 | self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.today()) | |
69 | ||
53 | 70 | Context manager |
54 | 71 | ~~~~~~~~~~~~~~~ |
55 | 72 | |
244 | 261 | |
245 | 262 | Platform: UNKNOWN |
246 | 263 | Classifier: License :: OSI Approved :: Apache Software License |
247 | Classifier: Programming Language :: Python :: 2 | |
248 | Classifier: Programming Language :: Python :: 2.7 | |
249 | 264 | Classifier: Programming Language :: Python :: 3 |
250 | 265 | Classifier: Programming Language :: Python :: 3.5 |
251 | 266 | Classifier: Programming Language :: Python :: 3.6 |
253 | 268 | Classifier: Programming Language :: Python :: 3.8 |
254 | 269 | Classifier: Programming Language :: Python :: Implementation :: CPython |
255 | 270 | Classifier: Programming Language :: Python :: Implementation :: PyPy |
256 | Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* | |
271 | Requires-Python: >=3.5 |
0 | 0 | #!/usr/bin/env python |
1 | 1 | |
2 | import sys | |
3 | 2 | from setuptools import setup |
4 | ||
5 | requires = ['six'] | |
6 | tests_require = [ | |
7 | 'mock;python_version<"3.4"', | |
8 | 'nose' | |
9 | ] | |
10 | ||
11 | if sys.version_info.major == 2: | |
12 | requires += ['python-dateutil>=1.0, != 2.0'] | |
13 | else: | |
14 | # Py3k | |
15 | requires += ['python-dateutil>=2.0'] | |
16 | ||
17 | 3 | |
18 | 4 | with open('README.rst') as f: |
19 | 5 | readme = f.read() |
20 | 6 | |
21 | 7 | setup( |
22 | 8 | name='freezegun', |
23 | version='0.3.15', | |
9 | version='1.0.0', | |
24 | 10 | description='Let your Python tests travel through time', |
25 | 11 | long_description=readme, |
26 | 12 | author='Steve Pulec', |
27 | 13 | author_email='spulec@gmail.com', |
28 | 14 | url='https://github.com/spulec/freezegun', |
29 | 15 | packages=['freezegun'], |
30 | install_requires=requires, | |
31 | tests_require=tests_require, | |
16 | install_requires=['python-dateutil>=2.7'], | |
32 | 17 | include_package_data=True, |
33 | 18 | license='Apache 2.0', |
34 | python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', | |
19 | python_requires='>=3.5', | |
35 | 20 | classifiers=[ |
36 | 21 | 'License :: OSI Approved :: Apache Software License', |
37 | 'Programming Language :: Python :: 2', | |
38 | 'Programming Language :: Python :: 2.7', | |
39 | 22 | 'Programming Language :: Python :: 3', |
40 | 23 | 'Programming Language :: Python :: 3.5', |
41 | 24 | 'Programming Language :: Python :: 3.6', |
0 | from datetime import datetime | |
1 | from datetime import date | |
0 | from datetime import date, datetime | |
2 | 1 | from time import time, localtime, gmtime, strftime |
3 | 2 | |
4 | 3 |
0 | import asyncio | |
0 | 1 | import datetime |
1 | 2 | from textwrap import dedent |
2 | 3 | from unittest import SkipTest |
3 | 4 | |
4 | ||
5 | 5 | from freezegun import freeze_time |
6 | ||
7 | try: | |
8 | import asyncio | |
9 | except ImportError: | |
10 | asyncio = False | |
11 | 6 | |
12 | 7 | |
13 | 8 | def test_time_freeze_coroutine(): |
14 | 9 | if not asyncio: |
15 | 10 | raise SkipTest('asyncio required') |
16 | @asyncio.coroutine | |
11 | ||
17 | 12 | @freeze_time('1970-01-01') |
18 | def frozen_coroutine(): | |
13 | async def frozen_coroutine(): | |
19 | 14 | assert datetime.date.today() == datetime.date(1970, 1, 1) |
20 | 15 | |
21 | 16 | asyncio.get_event_loop().run_until_complete(frozen_coroutine()) |
14 | 14 | |
15 | 15 | try: |
16 | 16 | import maya |
17 | ||
18 | 17 | except ImportError: |
19 | 18 | maya = None |
20 | 19 | |
260 | 259 | |
261 | 260 | |
262 | 261 | def test_real_strftime_fall_through(): |
263 | with freeze_time(ignore=['_pytest']): | |
264 | time.strftime('%Y') | |
265 | time.strftime('%Y', (2001, 1, 1, 1, 1, 1, 1, 1, 1)) == '2001' | |
262 | this_real_year = datetime.datetime.now().year | |
263 | with freeze_time(): | |
264 | assert time.strftime('%Y') == str(this_real_year) | |
265 | assert time.strftime('%Y', (2001, 1, 1, 1, 1, 1, 1, 1, 1)) == '2001' | |
266 | 266 | |
267 | 267 | |
268 | 268 | def test_date_object(): |
481 | 481 | |
482 | 482 | today = datetime.date.today() |
483 | 483 | assert isinstance(today, datetime.date) |
484 | ||
485 | ||
486 | class TestUnitTestMethodDecorator(unittest.TestCase): | |
487 | @freeze_time('2013-04-09') | |
488 | def test_method_decorator_works_on_unittest(self): | |
489 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
490 | ||
491 | @freeze_time('2013-04-09', as_kwarg='frozen_time') | |
492 | def test_method_decorator_works_on_unittest_kwarg_frozen_time(self, frozen_time): | |
493 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
494 | self.assertEqual(datetime.date(2013, 4, 9), frozen_time.time_to_freeze.today()) | |
495 | ||
496 | @freeze_time('2013-04-09', as_kwarg='hello') | |
497 | def test_method_decorator_works_on_unittest_kwarg_hello(self, **kwargs): | |
498 | self.assertEqual(datetime.date(2013, 4, 9), datetime.date.today()) | |
499 | self.assertEqual(datetime.date(2013, 4, 9), kwargs.get('hello').time_to_freeze.today()) | |
484 | 500 | |
485 | 501 | |
486 | 502 | @freeze_time('2013-04-09') |
0 | 0 | import datetime |
1 | 1 | import time |
2 | try: | |
3 | from unittest import mock | |
4 | except (ImportError, AttributeError): | |
5 | import mock | |
2 | ||
3 | from unittest import mock | |
6 | 4 | import pytest |
7 | 5 | |
8 | 6 | from freezegun import freeze_time |