commit python-freezegun for openSUSE:Factory
Hello community, here is the log from the commit of package python-freezegun for openSUSE:Factory checked in at 2019-07-05 13:47:03 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-freezegun (Old) and /work/SRC/openSUSE:Factory/.python-freezegun.new.4615 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-freezegun" Fri Jul 5 13:47:03 2019 rev:7 rq:713090 version:0.3.12 Changes: -------- --- /work/SRC/openSUSE:Factory/python-freezegun/python-freezegun.changes 2019-02-08 13:48:15.086782043 +0100 +++ /work/SRC/openSUSE:Factory/.python-freezegun.new.4615/python-freezegun.changes 2019-07-05 13:47:05.161302287 +0200 @@ -1,0 +2,10 @@ +Tue Jul 2 18:11:23 CEST 2019 - Matej Cepl <mcepl@suse.com> + +- Upgrade to 0.3.12: + * Refactor classes to functions + * Ignore Selenium + * Move to pytest + * Conditionally patch time.clock (removed in 3.8) + * Patch time.time_ns added in Python 3.7 + +------------------------------------------------------------------- Old: ---- freezegun-0.3.11.tar.gz New: ---- freezegun-0.3.12.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-freezegun.spec ++++++ --- /var/tmp/diff_new_pack.kBUtwp/_old 2019-07-05 13:47:06.341304107 +0200 +++ /var/tmp/diff_new_pack.kBUtwp/_new 2019-07-05 13:47:06.349304119 +0200 @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-freezegun -Version: 0.3.11 +Version: 0.3.12 Release: 0 Summary: Mock time date for Python License: Apache-2.0 @@ -29,6 +29,7 @@ Patch0: remove_dependency_on_mock.patch # gh#spulec/freezegun#280 Removal of nose dependency Patch1: denose.patch +BuildRequires: %{python_module pytest} BuildRequires: %{python_module python-dateutil > 2.0} BuildRequires: %{python_module setuptools} BuildRequires: %{python_module six} ++++++ denose.patch ++++++ ++++ 1149 lines (skipped) ++++ between /work/SRC/openSUSE:Factory/python-freezegun/denose.patch ++++ and /work/SRC/openSUSE:Factory/.python-freezegun.new.4615/denose.patch ++++++ freezegun-0.3.11.tar.gz -> freezegun-0.3.12.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/CHANGELOG new/freezegun-0.3.12/CHANGELOG --- old/freezegun-0.3.11/CHANGELOG 2018-10-15 05:05:22.000000000 +0200 +++ new/freezegun-0.3.12/CHANGELOG 2019-05-30 03:55:02.000000000 +0200 @@ -4,6 +4,14 @@ Latest ------ +0.3.12 +------ + +* Refactor classes to functions +* Ignore Selenium +* Move to pytest +* Conditionally patch time.clock + 0.3.11 ------ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/PKG-INFO new/freezegun-0.3.12/PKG-INFO --- old/freezegun-0.3.11/PKG-INFO 2018-10-15 05:09:26.000000000 +0200 +++ new/freezegun-0.3.12/PKG-INFO 2019-05-30 04:02:10.000000000 +0200 @@ -1,16 +1,16 @@ Metadata-Version: 1.2 Name: freezegun -Version: 0.3.11 +Version: 0.3.12 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: FreezeGun: Let your Python tests travel through time ==================================================== - + .. image:: https://img.shields.io/pypi/v/freezegun.svg + :target: https://pypi.python.org/pypi/freezegun/ .. image:: https://secure.travis-ci.org/spulec/freezegun.svg?branch=master :target: https://travis-ci.org/spulec/freezegun .. image:: https://coveralls.io/repos/spulec/freezegun/badge.svg?branch=master @@ -141,6 +141,22 @@ def test_nice_datetime(): assert datetime.datetime.now() > datetime.datetime(2020, 1, 14) + ``auto_tick_seconds`` argument + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + FreezeGun has an additional ``auto_tick_seconds`` argument which will autoincrement the + value every time by the given amount from the start value. This is alternative to the default + parameters which will keep time stopped. Note that given ``auto_tick_seconds`` the ``tick`` parameter will be ignored. + + .. code-block:: python + + @freeze_time("Jan 14th, 2020", auto_tick_seconds=15) + def test_nice_datetime(): + first_time = datetime.datetime.now() + auto_incremented_time = datetime.datetime.now() + assert first_time + datetime.timedelta(seconds=15) == auto_incremented_time + + Manual ticks ~~~~~~~~~~~~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/README.rst new/freezegun-0.3.12/README.rst --- old/freezegun-0.3.11/README.rst 2018-10-15 04:31:36.000000000 +0200 +++ new/freezegun-0.3.12/README.rst 2019-05-30 04:02:08.000000000 +0200 @@ -1,7 +1,8 @@ FreezeGun: Let your Python tests travel through time ==================================================== - +.. image:: https://img.shields.io/pypi/v/freezegun.svg + :target: https://pypi.python.org/pypi/freezegun/ .. image:: https://secure.travis-ci.org/spulec/freezegun.svg?branch=master :target: https://travis-ci.org/spulec/freezegun .. image:: https://coveralls.io/repos/spulec/freezegun/badge.svg?branch=master @@ -132,6 +133,22 @@ def test_nice_datetime(): assert datetime.datetime.now() > datetime.datetime(2020, 1, 14) +``auto_tick_seconds`` argument +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +FreezeGun has an additional ``auto_tick_seconds`` argument which will autoincrement the +value every time by the given amount from the start value. This is alternative to the default +parameters which will keep time stopped. Note that given ``auto_tick_seconds`` the ``tick`` parameter will be ignored. + +.. code-block:: python + + @freeze_time("Jan 14th, 2020", auto_tick_seconds=15) + def test_nice_datetime(): + first_time = datetime.datetime.now() + auto_incremented_time = datetime.datetime.now() + assert first_time + datetime.timedelta(seconds=15) == auto_incremented_time + + Manual ticks ~~~~~~~~~~~~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/freezegun/__init__.py new/freezegun-0.3.12/freezegun/__init__.py --- old/freezegun-0.3.11/freezegun/__init__.py 2018-10-15 05:05:33.000000000 +0200 +++ new/freezegun-0.3.12/freezegun/__init__.py 2019-05-30 03:55:25.000000000 +0200 @@ -9,7 +9,7 @@ from .api import freeze_time __title__ = 'freezegun' -__version__ = '0.3.11' +__version__ = '0.3.12' __author__ = 'Steve Pulec' __license__ = 'Apache License 2.0' __copyright__ = 'Copyright 2012 Steve Pulec' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/freezegun/api.py new/freezegun-0.3.12/freezegun/api.py --- old/freezegun-0.3.11/freezegun/api.py 2018-10-15 04:58:23.000000000 +0200 +++ new/freezegun-0.3.12/freezegun/api.py 2019-05-30 03:52:31.000000000 +0200 @@ -25,20 +25,34 @@ real_localtime = time.localtime real_gmtime = time.gmtime real_strftime = time.strftime -real_clock = time.clock real_date = datetime.date real_datetime = datetime.datetime real_date_objects = [real_time, real_localtime, real_gmtime, real_strftime, real_date, real_datetime] _real_time_object_ids = set(id(obj) for obj in real_date_objects) -times_to_freeze = [] +# time.clock is deprecated and was removed in Python 3.8 +real_clock = getattr(time, 'clock', None) + +freeze_factories = [] tz_offsets = [] +ignore_lists = [] +tick_flags = [] + +# Python3 doesn't have basestring, but it does have str. +try: + # noinspection PyUnresolvedReferences + string_type = basestring +except NameError: + string_type = str try: + # noinspection PyUnresolvedReferences real_uuid_generate_time = uuid._uuid_generate_time uuid_generate_time_attr = '_uuid_generate_time' except AttributeError: + # noinspection PyUnresolvedReferences uuid._load_system_functions() + # noinspection PyUnresolvedReferences real_uuid_generate_time = uuid._generate_time_safe uuid_generate_time_attr = '_generate_time_safe' except ImportError: @@ -46,6 +60,7 @@ uuid_generate_time_attr = None try: + # noinspection PyUnresolvedReferences real_uuid_create = uuid._UuidCreate except (AttributeError, ImportError): real_uuid_create = None @@ -73,7 +88,7 @@ result = [] try: module_attributes = dir(module) - except TypeError: + except (ImportError, TypeError): return result for attribute_name in module_attributes: try: @@ -98,7 +113,7 @@ def _get_module_attributes_hash(module): try: module_dir = dir(module) - except TypeError: + except (ImportError, TypeError): module_dir = [] return '{0}-{1}'.format(id(module), hash(frozenset(module_dir))) @@ -126,104 +141,84 @@ ) -class BaseFakeTime(object): - call_stack_inspection_limit = 5 +call_stack_inspection_limit = 5 - def _should_use_real_time(self): - if not self.call_stack_inspection_limit: - return False - - if not self.ignore: - return False - - frame = inspect.currentframe().f_back.f_back - - for _ in range(self.call_stack_inspection_limit): - module_name = frame.f_globals.get('__name__') - if module_name and module_name.startswith(self.ignore): - return True - - frame = frame.f_back - if frame is None: - break +def _should_use_real_time(): + if not call_stack_inspection_limit: return False + if not ignore_lists[-1]: + return False -class FakeTime(BaseFakeTime): + frame = inspect.currentframe().f_back.f_back - def __init__(self, previous_time_function, ignore=None): - self.previous_time_function = previous_time_function - self.ignore = ignore + for _ in range(call_stack_inspection_limit): + module_name = frame.f_globals.get('__name__') + if module_name and module_name.startswith(ignore_lists[-1]): + return True - def __call__(self): - if self._should_use_real_time(): - return real_time() - current_time = times_to_freeze[-1]() - return calendar.timegm(current_time.timetuple()) + current_time.microsecond / 1000000.0 - - -class FakeLocalTime(BaseFakeTime): - def __init__(self, previous_localtime_function=None, ignore=None): - self.previous_localtime_function = previous_localtime_function - self.ignore = ignore - - def __call__(self, t=None): - if t is not None: - return real_localtime(t) - if self._should_use_real_time(): - return real_localtime() - shifted_time = times_to_freeze[-1]() - datetime.timedelta(seconds=time.timezone) - return shifted_time.timetuple() - - -class FakeGMTTime(BaseFakeTime): - def __init__(self, previous_gmtime_function, ignore=None): - self.previous_gmtime_function = previous_gmtime_function - self.ignore = ignore - - def __call__(self, t=None): - if t is not None: - return real_gmtime(t) - if self._should_use_real_time(): - return real_gmtime() - return times_to_freeze[-1]().timetuple() - - -class FakeStrfTime(BaseFakeTime): - def __init__(self, previous_strftime_function, ignore=None): - self.previous_strftime_function = previous_strftime_function - self.ignore = ignore - - def __call__(self, format, time_to_format=None): - if time_to_format is None: - if not self._should_use_real_time(): - time_to_format = FakeLocalTime()() + frame = frame.f_back + if frame is None: + break - return real_strftime(format, time_to_format) + return False -class FakeClock(BaseFakeTime): - def __init__(self, previous_clock_function, tick=False, ignore=None): - self.previous_clock_function = previous_clock_function - self.tick = tick - self.ignore = ignore +def get_current_time(): + return freeze_factories[-1]() + + +def fake_time(): + if _should_use_real_time(): + return real_time() + current_time = get_current_time() + return calendar.timegm(current_time.timetuple()) + current_time.microsecond / 1000000.0 + + +def fake_localtime(t=None): + if t is not None: + return real_localtime(t) + if _should_use_real_time(): + return real_localtime() + shifted_time = get_current_time() - datetime.timedelta(seconds=time.timezone) + return shifted_time.timetuple() - def __call__(self, *args, **kwargs): - if self._should_use_real_time(): + +def fake_gmtime(t=None): + if t is not None: + return real_gmtime(t) + if _should_use_real_time(): + return real_gmtime() + return get_current_time().timetuple() + + +def fake_strftime(format, time_to_format=None): + if time_to_format is None: + if not _should_use_real_time(): + time_to_format = fake_localtime() + + if time_to_format is None: + return real_strftime(format) + else: + return real_strftime(format, time_to_format) + +if real_clock is not None: + def fake_clock(): + if _should_use_real_time(): return real_clock() - if len(times_to_freeze) == 1: - return 0.0 if not self.tick else self.previous_clock_function() + if len(freeze_factories) == 1: + return 0.0 if not tick_flags[-1] else real_clock() - first_frozen_time = times_to_freeze[0]() - last_frozen_time = times_to_freeze[-1]() + first_frozen_time = freeze_factories[0]() + last_frozen_time = get_current_time() timedelta = (last_frozen_time - first_frozen_time) total_seconds = timedelta.total_seconds() - if self.tick: - total_seconds += self.previous_clock_function() + if tick_flags[-1]: + total_seconds += real_clock() return total_seconds @@ -233,6 +228,10 @@ def __instancecheck__(self, obj): return isinstance(obj, real_date) + @classmethod + def __subclasscheck__(cls, subclass): + return issubclass(subclass, real_date) + def datetime_to_fakedatetime(datetime): return FakeDatetime(datetime.year, @@ -277,7 +276,7 @@ @staticmethod def _date_to_freeze(): - return times_to_freeze[-1]() + return get_current_time() @classmethod def _tz_offset(cls): @@ -292,6 +291,10 @@ def __instancecheck__(self, obj): return isinstance(obj, real_datetime) + @classmethod + def __subclasscheck__(cls, subclass): + return issubclass(subclass, real_datetime) + class FakeDatetime(with_metaclass(FakeDatetimeMeta, real_datetime, FakeDate)): def __new__(cls, *args, **kwargs): @@ -332,6 +335,7 @@ @property def nanosecond(self): try: + # noinspection PyUnresolvedReferences return real_datetime.nanosecond except AttributeError: return 0 @@ -347,8 +351,8 @@ @staticmethod def _time_to_freeze(): - if times_to_freeze: - return times_to_freeze[-1]() + if freeze_factories: + return get_current_time() @classmethod def _tz_offset(cls): @@ -438,6 +442,7 @@ def tick(self, delta=datetime.timedelta(seconds=1)): if isinstance(delta, numbers.Real): + # noinspection PyTypeChecker self.time_to_freeze += datetime.timedelta(seconds=delta) else: self.time_to_freeze += delta @@ -449,14 +454,41 @@ self.tick(delta=delta) +class StepTickTimeFactory(object): + + def __init__(self, time_to_freeze, step_width): + self.time_to_freeze = time_to_freeze + self.step_width = step_width + + def __call__(self): + return_time = self.time_to_freeze + self.tick() + return return_time + + def tick(self, delta=None): + if not delta: + delta = datetime.timedelta(seconds=self.step_width) + self.time_to_freeze += delta + + def update_step_width(self, step_width): + self.step_width = step_width + + def move_to(self, target_datetime): + """Moves frozen date to the given ``target_datetime``""" + target_datetime = _parse_time_to_freeze(target_datetime) + delta = target_datetime - self.time_to_freeze + self.tick(delta=delta) + + class _freeze_time(object): - def __init__(self, time_to_freeze_str, tz_offset, ignore, tick, as_arg): + def __init__(self, time_to_freeze_str, tz_offset, ignore, tick, as_arg, auto_tick_seconds): self.time_to_freeze = _parse_time_to_freeze(time_to_freeze_str) self.tz_offset = _parse_tz_offset(tz_offset) self.ignore = tuple(ignore) self.tick = tick + self.auto_tick_seconds = auto_tick_seconds self.undo_changes = [] self.modules_at_start = set() self.as_arg = as_arg @@ -477,12 +509,14 @@ orig_setUpClass = getattr(klass, 'setUpClass', None) orig_tearDownClass = getattr(klass, 'tearDownClass', None) + # noinspection PyDecorator @classmethod def setUpClass(cls): self.start() if orig_setUpClass is not None: orig_setUpClass() + # noinspection PyDecorator @classmethod def tearDownClass(cls): if orig_tearDownClass is not None: @@ -522,33 +556,31 @@ self.stop() def start(self): - if self.tick: - time_to_freeze = TickingDateTimeFactory(self.time_to_freeze, real_datetime.now()) + + if self.auto_tick_seconds: + freeze_factory = StepTickTimeFactory(self.time_to_freeze, self.auto_tick_seconds) + elif self.tick: + freeze_factory = TickingDateTimeFactory(self.time_to_freeze, real_datetime.now()) else: - time_to_freeze = FrozenDateTimeFactory(self.time_to_freeze) + freeze_factory = FrozenDateTimeFactory(self.time_to_freeze) - # Change the modules - is_already_started = len(times_to_freeze) > 0 - times_to_freeze.append(time_to_freeze) + is_already_started = len(freeze_factories) > 0 + freeze_factories.append(freeze_factory) tz_offsets.append(self.tz_offset) + ignore_lists.append(self.ignore) + tick_flags.append(self.tick) if is_already_started: - return time_to_freeze + return freeze_factory + # Change the modules datetime.datetime = FakeDatetime datetime.date = FakeDate - fake_time = FakeTime(time.time, ignore=self.ignore) - fake_localtime = FakeLocalTime(time.localtime, ignore=self.ignore) - fake_gmtime = FakeGMTTime(time.gmtime, ignore=self.ignore) - fake_strftime = FakeStrfTime(time.strftime, ignore=self.ignore) - fake_clock = FakeClock(time.clock, tick=self.tick, ignore=self.ignore) - time.time = fake_time time.localtime = fake_localtime time.gmtime = fake_gmtime time.strftime = fake_strftime - time.clock = fake_clock if uuid_generate_time_attr: setattr(uuid, uuid_generate_time_attr, None) uuid._UuidCreate = None @@ -559,17 +591,22 @@ # Change any place where the module had already been imported to_patch = [ - ('real_date', real_date, 'FakeDate', FakeDate), - ('real_datetime', real_datetime, 'FakeDatetime', FakeDatetime), - ('real_gmtime', real_gmtime, 'FakeGMTTime', fake_gmtime), - ('real_localtime', real_localtime, 'FakeLocalTime', fake_localtime), - ('real_strftime', real_strftime, 'FakeStrfTime', fake_strftime), - ('real_time', real_time, 'FakeTime', fake_time), - ('real_clock', real_clock, 'FakeClock', fake_clock), + ('real_date', real_date, FakeDate), + ('real_datetime', real_datetime, FakeDatetime), + ('real_gmtime', real_gmtime, fake_gmtime), + ('real_localtime', real_localtime, fake_localtime), + ('real_strftime', real_strftime, fake_strftime), + ('real_time', real_time, fake_time), ] - self.fake_names = tuple(fake_name for real_name, real, fake_name, fake in to_patch) - self.reals = dict((id(fake), real) for real_name, real, fake_name, fake in to_patch) - fakes = dict((id(real), fake) for real_name, real, fake_name, fake in to_patch) + + if real_clock is not None: + # time.clock is deprecated and was removed in Python 3.8 + time.clock = fake_clock + to_patch.append(('real_clock', real_clock, fake_clock)) + + self.fake_names = tuple(fake.__name__ for real_name, real, fake in to_patch) + self.reals = dict((id(fake), real) for real_name, real, fake in to_patch) + fakes = dict((id(real), fake) for real_name, real, fake in to_patch) add_change = self.undo_changes.append # Save the current loaded modules @@ -593,13 +630,15 @@ setattr(module, attribute_name, fake) add_change((module, attribute_name, attribute_value)) - return time_to_freeze + return freeze_factory def stop(self): - times_to_freeze.pop() + freeze_factories.pop() + ignore_lists.pop() + tick_flags.pop() tz_offsets.pop() - if not times_to_freeze: + if not freeze_factories: datetime.datetime = real_datetime datetime.date = real_date copyreg.dispatch_table.pop(real_datetime) @@ -635,11 +674,11 @@ if real: setattr(module, module_attribute, real) - time.time = time.time.previous_time_function - time.gmtime = time.gmtime.previous_gmtime_function - time.localtime = time.localtime.previous_localtime_function - time.strftime = time.strftime.previous_strftime_function - time.clock = time.clock.previous_clock_function + time.time = real_time + time.gmtime = real_gmtime + time.localtime = real_localtime + time.strftime = real_strftime + time.clock = real_clock if uuid_generate_time_attr: setattr(uuid, uuid_generate_time_attr, real_uuid_generate_time) @@ -666,13 +705,7 @@ return wrapper -def freeze_time(time_to_freeze=None, tz_offset=0, ignore=None, tick=False, as_arg=False): - # Python3 doesn't have basestring, but it does have str. - try: - string_type = basestring - except NameError: - string_type = str - +def freeze_time(time_to_freeze=None, tz_offset=0, ignore=None, tick=False, as_arg=False, auto_tick_seconds=0): acceptable_times = (type(None), string_type, datetime.date, datetime.timedelta, types.FunctionType, types.GeneratorType) @@ -687,10 +720,10 @@ raise SystemError('Calling freeze_time with tick=True is only compatible with CPython') if isinstance(time_to_freeze, types.FunctionType): - return freeze_time(time_to_freeze(), tz_offset, ignore, tick) + return freeze_time(time_to_freeze(), tz_offset, ignore, tick, auto_tick_seconds) if isinstance(time_to_freeze, types.GeneratorType): - return freeze_time(next(time_to_freeze), tz_offset, ignore, tick) + return freeze_time(next(time_to_freeze), tz_offset, ignore, tick, auto_tick_seconds) if MayaDT is not None and isinstance(time_to_freeze, MayaDT): return freeze_time(time_to_freeze.datetime(), tz_offset, ignore, @@ -705,11 +738,16 @@ ignore.append('google.gax') ignore.append('threading') ignore.append('Queue') - return _freeze_time(time_to_freeze, tz_offset, ignore, tick, as_arg) + ignore.append('selenium') + ignore.append('_pytest.terminal.') + ignore.append('_pytest.runner.') + + return _freeze_time(time_to_freeze, tz_offset, ignore, tick, as_arg, auto_tick_seconds) # Setup adapters for sqlite try: + # noinspection PyUnresolvedReferences import sqlite3 except ImportError: # Some systems have trouble with this diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/freezegun.egg-info/PKG-INFO new/freezegun-0.3.12/freezegun.egg-info/PKG-INFO --- old/freezegun-0.3.11/freezegun.egg-info/PKG-INFO 2018-10-15 05:09:26.000000000 +0200 +++ new/freezegun-0.3.12/freezegun.egg-info/PKG-INFO 2019-05-30 04:02:10.000000000 +0200 @@ -1,16 +1,16 @@ Metadata-Version: 1.2 Name: freezegun -Version: 0.3.11 +Version: 0.3.12 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: FreezeGun: Let your Python tests travel through time ==================================================== - + .. image:: https://img.shields.io/pypi/v/freezegun.svg + :target: https://pypi.python.org/pypi/freezegun/ .. image:: https://secure.travis-ci.org/spulec/freezegun.svg?branch=master :target: https://travis-ci.org/spulec/freezegun .. image:: https://coveralls.io/repos/spulec/freezegun/badge.svg?branch=master @@ -141,6 +141,22 @@ def test_nice_datetime(): assert datetime.datetime.now() > datetime.datetime(2020, 1, 14) + ``auto_tick_seconds`` argument + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + FreezeGun has an additional ``auto_tick_seconds`` argument which will autoincrement the + value every time by the given amount from the start value. This is alternative to the default + parameters which will keep time stopped. Note that given ``auto_tick_seconds`` the ``tick`` parameter will be ignored. + + .. code-block:: python + + @freeze_time("Jan 14th, 2020", auto_tick_seconds=15) + def test_nice_datetime(): + first_time = datetime.datetime.now() + auto_incremented_time = datetime.datetime.now() + assert first_time + datetime.timedelta(seconds=15) == auto_incremented_time + + Manual ticks ~~~~~~~~~~~~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/freezegun.egg-info/SOURCES.txt new/freezegun-0.3.12/freezegun.egg-info/SOURCES.txt --- old/freezegun-0.3.11/freezegun.egg-info/SOURCES.txt 2018-10-15 05:09:26.000000000 +0200 +++ new/freezegun-0.3.12/freezegun.egg-info/SOURCES.txt 2019-05-30 04:02:10.000000000 +0200 @@ -19,6 +19,7 @@ tests/test_asyncio.py tests/test_class_import.py tests/test_datetimes.py +tests/test_errors.py tests/test_import_alias.py tests/test_operations.py tests/test_pickle.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/setup.py new/freezegun-0.3.12/setup.py --- old/freezegun-0.3.11/setup.py 2018-10-15 05:05:29.000000000 +0200 +++ new/freezegun-0.3.12/setup.py 2019-05-30 04:01:14.000000000 +0200 @@ -18,7 +18,7 @@ setup( name='freezegun', - version='0.3.11', + version='0.3.12', description='Let your Python tests travel through time', long_description=readme, author='Steve Pulec', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/another_module.py new/freezegun-0.3.12/tests/another_module.py --- old/freezegun-0.3.11/tests/another_module.py 2018-03-06 01:33:10.000000000 +0100 +++ new/freezegun-0.3.12/tests/another_module.py 2019-05-30 03:52:31.000000000 +0200 @@ -4,10 +4,10 @@ from freezegun.api import ( FakeDatetime, FakeDate, - FakeTime, - FakeLocalTime, - FakeGMTTime, - FakeStrfTime, + fake_time, + fake_localtime, + fake_gmtime, + fake_strftime, ) @@ -48,16 +48,16 @@ def get_fake_time(): - return FakeTime + return fake_time def get_fake_localtime(): - return FakeLocalTime + return fake_localtime def get_fake_gmtime(): - return FakeGMTTime + return fake_gmtime def get_fake_strftime(): - return FakeStrfTime + return fake_strftime diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/test_asyncio.py new/freezegun-0.3.12/tests/test_asyncio.py --- old/freezegun-0.3.11/tests/test_asyncio.py 2018-03-06 03:30:32.000000000 +0100 +++ new/freezegun-0.3.12/tests/test_asyncio.py 2019-05-30 03:52:31.000000000 +0200 @@ -1,7 +1,7 @@ import datetime from textwrap import dedent +from unittest import SkipTest -from nose.plugins import skip from freezegun import freeze_time @@ -13,7 +13,7 @@ def test_time_freeze_coroutine(): if not asyncio: - raise skip.SkipTest('asyncio required') + raise SkipTest('asyncio required') @asyncio.coroutine @freeze_time('1970-01-01') def frozen_coroutine(): @@ -26,7 +26,7 @@ try: exec('async def foo(): pass') except SyntaxError: - raise skip.SkipTest('async def not supported') + raise SkipTest('async def not supported') else: exec(dedent(''' @freeze_time('1970-01-01') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/test_class_import.py new/freezegun-0.3.12/tests/test_class_import.py --- old/freezegun-0.3.11/tests/test_class_import.py 2018-10-15 04:31:36.000000000 +0200 +++ new/freezegun-0.3.12/tests/test_class_import.py 2019-05-30 03:52:31.000000000 +0200 @@ -13,10 +13,10 @@ from freezegun.api import ( FakeDatetime, FakeDate, - FakeTime, - FakeLocalTime, - FakeGMTTime, - FakeStrfTime, + fake_time, + fake_localtime, + fake_gmtime, + fake_strftime, ) import datetime @@ -70,6 +70,17 @@ freezer.stop() +def test_issubclass_works(): + real_date = datetime.date + real_datetime = datetime.datetime + + freezer = freeze_time('2011-01-01') + freezer.start() + assert issubclass(real_date, datetime.date) + assert issubclass(real_datetime, datetime.datetime) + freezer.stop() + + def test_fake_uses_real_when_ignored(): real_time_before = time.time() with freeze_time('2012-01-14', ignore=['tests.fake_module']): @@ -130,21 +141,21 @@ assert another_module.get_date() is datetime.date assert another_module.get_date() is FakeDate assert another_module.get_time() is time.time - assert isinstance(another_module.get_time(), FakeTime) + assert another_module.get_time() is fake_time assert another_module.get_localtime() is time.localtime - assert isinstance(another_module.get_localtime(), FakeLocalTime) + assert another_module.get_localtime() is fake_localtime assert another_module.get_gmtime() is time.gmtime - assert isinstance(another_module.get_gmtime(), FakeGMTTime) + assert another_module.get_gmtime() is fake_gmtime assert another_module.get_strftime() is time.strftime - assert isinstance(another_module.get_strftime(), FakeStrfTime) + assert another_module.get_strftime() is fake_strftime # Fakes assert another_module.get_fake_datetime() is FakeDatetime assert another_module.get_fake_date() is FakeDate - assert another_module.get_fake_time() is FakeTime - assert another_module.get_fake_localtime() is FakeLocalTime - assert another_module.get_fake_gmtime() is FakeGMTTime - assert another_module.get_fake_strftime() is FakeStrfTime + assert another_module.get_fake_time() is fake_time + assert another_module.get_fake_localtime() is fake_localtime + assert another_module.get_fake_gmtime() is fake_gmtime + assert another_module.get_fake_strftime() is fake_strftime # Reals assert another_module.get_datetime() is datetime.datetime @@ -152,21 +163,21 @@ assert another_module.get_date() is datetime.date assert not another_module.get_date() is FakeDate assert another_module.get_time() is time.time - assert not isinstance(another_module.get_time(), FakeTime) + assert not another_module.get_time() is fake_time assert another_module.get_localtime() is time.localtime - assert not isinstance(another_module.get_localtime(), FakeLocalTime) + assert not another_module.get_localtime() is fake_localtime assert another_module.get_gmtime() is time.gmtime - assert not isinstance(another_module.get_gmtime(), FakeGMTTime) + assert not another_module.get_gmtime() is fake_gmtime assert another_module.get_strftime() is time.strftime - assert not isinstance(another_module.get_strftime(), FakeStrfTime) + assert not another_module.get_strftime() is fake_strftime # Fakes assert another_module.get_fake_datetime() is FakeDatetime assert another_module.get_fake_date() is FakeDate - assert another_module.get_fake_time() is FakeTime - assert another_module.get_fake_localtime() is FakeLocalTime - assert another_module.get_fake_gmtime() is FakeGMTTime - assert another_module.get_fake_strftime() is FakeStrfTime + assert another_module.get_fake_time() is fake_time + assert another_module.get_fake_localtime() is fake_localtime + assert another_module.get_fake_gmtime() is fake_gmtime + assert another_module.get_fake_strftime() is fake_strftime def test_none_as_initial(): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/test_datetimes.py new/freezegun-0.3.12/tests/test_datetimes.py --- old/freezegun-0.3.11/tests/test_datetimes.py 2018-10-15 04:58:23.000000000 +0200 +++ new/freezegun-0.3.12/tests/test_datetimes.py 2019-05-30 03:52:31.000000000 +0200 @@ -3,13 +3,13 @@ import unittest import locale import sys +from unittest import SkipTest -from nose.plugins import skip -from nose.tools import assert_raises +import pytest from tests import utils from freezegun import freeze_time -from freezegun.api import FakeDatetime, FakeDate, BaseFakeTime +from freezegun.api import FakeDatetime, FakeDate try: import maya @@ -17,6 +17,8 @@ except ImportError: maya = None +# time.clock was removed in Python 3.8 +HAS_CLOCK = hasattr(time, 'clock') class temp_locale(object): """Temporarily change the locale.""" @@ -33,7 +35,7 @@ except locale.Error: pass msg = 'could not set locale to any of: %s' % ', '.join(self.targets) - raise skip.SkipTest(msg) + raise SkipTest(msg) def __exit__(self, *args): locale.setlocale(locale.LC_ALL, self.old) @@ -207,6 +209,8 @@ assert time_struct.tm_isdst == -1 +@pytest.mark.skipif(not HAS_CLOCK, + reason="time.clock was removed in Python 3.8") def test_time_clock(): with freeze_time('2012-01-14 03:21:34'): assert time.clock() == 0 @@ -253,6 +257,12 @@ assert time.strftime("%Y") == "1970" +def test_real_strftime_fall_through(): + with freeze_time(ignore=['_pytest']): + time.strftime('%Y') + time.strftime('%Y', (2001, 1, 1, 1, 1, 1, 1, 1, 1)) == '2001' + + def test_date_object(): frozen_date = datetime.date(year=2012, month=11, day=10) date_freezer = freeze_time(frozen_date) @@ -316,12 +326,13 @@ with freeze_time(frozen_datetimes): assert datetime.datetime(2011, 1, 1) == datetime.datetime.now() - assert_raises(StopIteration, freeze_time, frozen_datetimes) + with pytest.raises(StopIteration): + freeze_time(frozen_datetimes) def test_maya_datetimes(): if not maya: - raise skip.SkipTest("maya is optional since it's not supported for " + raise SkipTest("maya is optional since it's not supported for " "enough python versions") with freeze_time(maya.when("October 2nd, 1997")): @@ -392,12 +403,12 @@ def test_class_decorator_skips_callable_object_py2(self): if sys.version_info[0] != 2: - raise skip.SkipTest("test target is Python2") + raise 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") + raise SkipTest("test target is Python3") assert self.a_mock.__wrapped__.__class__ == Callable @staticmethod @@ -629,16 +640,19 @@ expected_frozen_gmt = (2015, 3, 5, 0, 0, 0, 3, 64, -1) expected_clock = 0 - BaseFakeTime.call_stack_inspection_limit = 100 # just to increase coverage + from freezegun import api + api.call_stack_inspection_limit = 100 # just to increase coverage with freeze_time(frozen): assert time.time() == expected_frozen # assert time.localtime() == expected_frozen_local assert time.gmtime() == expected_frozen_gmt - assert time.clock() == expected_clock + if HAS_CLOCK: + assert time.clock() == expected_clock with freeze_time(frozen, ignore=['_pytest', 'nose']): assert time.time() != expected_frozen # assert time.localtime() != expected_frozen_local assert time.gmtime() != expected_frozen_gmt - assert time.clock() != expected_clock + if HAS_CLOCK: + assert time.clock() != expected_clock diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/test_errors.py new/freezegun-0.3.12/tests/test_errors.py --- old/freezegun-0.3.11/tests/test_errors.py 1970-01-01 01:00:00.000000000 +0100 +++ new/freezegun-0.3.12/tests/test_errors.py 2019-05-30 03:52:31.000000000 +0200 @@ -0,0 +1,58 @@ +import contextlib +import datetime +import sys + +import pytest +from freezegun import freeze_time + + +class ModuleWithError(object): + """ + A module that triggers an error on __dir__ access. + + This could happen with modules that overrides its __dir__ method and + performing non standard operations. + + One such example is IPython which adds shim modules when certain packages + are imported. (Eg. `import IPython.html`) This leads to errors upon + activating freezegun if the modules being shimmed are not installed. + + See: https://github.com/ipython/ipython/blob/5.8.0/IPython/utils/shimmodule.py#L7... + """ + __name__ = 'module_with_error' + __dict__ = {} + + def __init__(self, error_type): + self.error_triggered = False + self.error_type = error_type + + def __dir__(self): + try: + raise self.error_type() + finally: + self.error_triggered = True + + +@contextlib.contextmanager +def assert_module_with_raised_error(error_type): + """Install a module into sys.modules that raises an error upon invoking + __dir__.""" + module = sys.modules['module_with_error'] = ModuleWithError(error_type) + + try: + yield + finally: + del sys.modules['module_with_error'] + + assert module.error_triggered + + +@pytest.mark.parametrize('error_type', [ImportError, TypeError]) +def test_ignore_errors_in_start(error_type): + with assert_module_with_raised_error(error_type): + freezer = freeze_time(datetime.datetime(2019, 1, 11, 9, 34)) + + try: + freezer.start() + finally: + freezer.stop() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/test_operations.py new/freezegun-0.3.12/tests/test_operations.py --- old/freezegun-0.3.11/tests/test_operations.py 2018-03-06 01:33:10.000000000 +0100 +++ new/freezegun-0.3.12/tests/test_operations.py 2019-05-30 03:52:31.000000000 +0200 @@ -93,3 +93,11 @@ today = datetime.date.today() modified_date = today.replace(year=2013) assert utils.is_fake_date(modified_date) + + +@freeze_time("Jan 14th, 2020", auto_tick_seconds=15) +def test_auto_tick(): + first_time = datetime.datetime.now() + auto_incremented_time = datetime.datetime.now() + assert first_time + datetime.timedelta(seconds=15) == auto_incremented_time + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/test_ticking.py new/freezegun-0.3.12/tests/test_ticking.py --- old/freezegun-0.3.11/tests/test_ticking.py 2018-10-15 04:58:23.000000000 +0200 +++ new/freezegun-0.3.12/tests/test_ticking.py 2019-05-30 03:52:31.000000000 +0200 @@ -1,11 +1,11 @@ import datetime import time import mock +import pytest from freezegun import freeze_time from tests import utils - @utils.cpython_only def test_ticking_datetime(): with freeze_time("Jan 14th, 2012", tick=True): @@ -13,6 +13,8 @@ assert datetime.datetime.now() > datetime.datetime(2012, 1, 14) +@pytest.mark.skipif(not hasattr(time, "clock"), + reason="time.clock was removed in Python 3.8") @utils.cpython_only def test_ticking_time_clock(): with freeze_time('2012-01-14 03:21:34', tick=True): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/test_utils.py new/freezegun-0.3.12/tests/test_utils.py --- old/freezegun-0.3.11/tests/test_utils.py 2018-03-06 01:33:10.000000000 +0100 +++ new/freezegun-0.3.12/tests/test_utils.py 2019-05-30 03:52:31.000000000 +0200 @@ -1,5 +1,6 @@ +from unittest import SkipTest + import mock -from nose.plugins import skip from freezegun import api from tests import utils @@ -20,7 +21,7 @@ function_mock = mock.MagicMock(__name__='function') try: utils.cpython_only(function_mock)() - except skip.SkipTest: + except SkipTest: raise AssertionError("Test was skipped in CPython") assert function_mock.called @@ -32,7 +33,7 @@ function_mock = mock.MagicMock(__name__='function', skipped=False) try: utils.cpython_only(function_mock)() - except skip.SkipTest: + except SkipTest: function_mock.skipped = True assert not function_mock.called assert function_mock.skipped diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/test_uuid.py new/freezegun-0.3.12/tests/test_uuid.py --- old/freezegun-0.3.11/tests/test_uuid.py 2018-03-06 03:30:32.000000000 +0100 +++ new/freezegun-0.3.12/tests/test_uuid.py 2019-05-30 03:52:31.000000000 +0200 @@ -2,8 +2,6 @@ import datetime import uuid -from nose.tools import assert_equal - from freezegun import freeze_time @@ -25,11 +23,11 @@ """ future_target = datetime.datetime(2056, 2, 6, 14, 3, 21) with freeze_time(future_target): - assert_equal(time_from_uuid(uuid.uuid1()), future_target) + assert 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) + assert time_from_uuid(uuid.uuid1()) == past_target def test_uuid1_past(): @@ -39,8 +37,8 @@ """ past_target = datetime.datetime(1978, 7, 6, 23, 6, 31) with freeze_time(past_target): - assert_equal(time_from_uuid(uuid.uuid1()), past_target) + assert 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) + assert time_from_uuid(uuid.uuid1()) == future_target diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/freezegun-0.3.11/tests/utils.py new/freezegun-0.3.12/tests/utils.py --- old/freezegun-0.3.11/tests/utils.py 2018-03-08 15:55:24.000000000 +0100 +++ new/freezegun-0.3.12/tests/utils.py 2019-05-30 03:52:31.000000000 +0200 @@ -1,6 +1,5 @@ from functools import wraps - -from nose.plugins import skip +from unittest import SkipTest from freezegun.api import FakeDate, FakeDatetime, _is_cpython @@ -17,6 +16,6 @@ @wraps(func) def wrapper(*args): if not _is_cpython: - raise skip.SkipTest("Requires CPython") + raise SkipTest("Requires CPython") return func(*args) return wrapper ++++++ remove_dependency_on_mock.patch ++++++ --- /var/tmp/diff_new_pack.kBUtwp/_old 2019-07-05 13:47:06.537304409 +0200 +++ /var/tmp/diff_new_pack.kBUtwp/_new 2019-07-05 13:47:06.537304409 +0200 @@ -1,9 +1,10 @@ --- a/tests/test_ticking.py +++ b/tests/test_ticking.py -@@ -1,6 +1,9 @@ +@@ -1,7 +1,10 @@ import datetime import time -import mock + import pytest +try: + import mock +except ImportError: @@ -13,12 +14,14 @@ from tests import utils --- a/tests/test_utils.py +++ b/tests/test_utils.py -@@ -1,4 +1,7 @@ +@@ -1,6 +1,9 @@ + from unittest import SkipTest + -import mock +try: + import mock +except ImportError: + import unittest.mock as mock - from nose.plugins import skip from freezegun import api + from tests import utils
participants (1)
-
root