Hello community,
here is the log from the commit of package python-freezegun for
openSUSE:Factory checked in at 2020-03-27 00:20:24
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-freezegun (Old)
and /work/SRC/openSUSE:Factory/.python-freezegun.new.3160 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-freezegun"
Fri Mar 27 00:20:24 2020 rev:9 rq:783995 version:0.3.15
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-freezegun/python-freezegun.changes
2019-11-22 10:25:08.297278608 +0100
+++
/work/SRC/openSUSE:Factory/.python-freezegun.new.3160/python-freezegun.changes
2020-03-27 00:20:27.456109708 +0100
@@ -1,0 +2,16 @@
+Wed Mar 11 17:29:52 UTC 2020 - Tomáš Chvátal <[email protected]>
+
+- Fix build without python2 available
+
+-------------------------------------------------------------------
+Wed Mar 11 08:59:55 UTC 2020 - Dirk Mueller <[email protected]>
+
+- update to 0.3.15:
+ * Fix locale timestamp bug. CC #328
+ * Fix calendar.timegm behavior
+ * Fix for Py3.8
+ * Reset time.time_ns on stop
+
+- drop remove_dependency_on_mock.patch
+
+-------------------------------------------------------------------
Old:
----
freezegun-0.3.12.tar.gz
remove_dependency_on_mock.patch
New:
----
freezegun-0.3.15.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-freezegun.spec ++++++
--- /var/tmp/diff_new_pack.uX02EX/_old 2020-03-27 00:20:29.068110525 +0100
+++ /var/tmp/diff_new_pack.uX02EX/_new 2020-03-27 00:20:29.112110548 +0100
@@ -1,7 +1,7 @@
#
# spec file for package python-freezegun
#
-# Copyright (c) 2019 SUSE LLC.
+# Copyright (c) 2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -17,32 +17,30 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
+%bcond_without python2
Name: python-freezegun
-Version: 0.3.12
+Version: 0.3.15
Release: 0
Summary: Mock time date for Python
License: Apache-2.0
-Group: Development/Languages/Python
URL: https://github.com/spulec/freezegun
Source:
https://files.pythonhosted.org/packages/source/f/freezegun/freezegun-%{version}.tar.gz
# gh#spulec/freezegun#259
-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}
BuildRequires: %{pythons}
-%ifpython2
-BuildRequires: python-mock
-%endif
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Requires: python
Requires: python-python-dateutil > 2.0
Requires: python-six
BuildArch: noarch
+%if %{with python2}
+BuildRequires: python-mock
+%endif
%python_subpackages
%description
++++++ denose.patch ++++++
--- /var/tmp/diff_new_pack.uX02EX/_old 2020-03-27 00:20:29.408110697 +0100
+++ /var/tmp/diff_new_pack.uX02EX/_new 2020-03-27 00:20:29.432110710 +0100
@@ -1,11 +1,14 @@
---- a/setup.py
-+++ b/setup.py
-@@ -4,7 +4,7 @@ import sys
- from setuptools import setup
+Index: freezegun-0.3.15/setup.py
+===================================================================
+--- freezegun-0.3.15.orig/setup.py
++++ freezegun-0.3.15/setup.py
+@@ -5,8 +5,7 @@ from setuptools import setup
requires = ['six']
--tests_require = ['mock', 'nose']
-+tests_require = ['mock']
+ tests_require = [
+- 'mock;python_version<"3.4"',
+- 'nose'
++ 'mock;python_version<"3.4"'
+ ]
if sys.version_info.major == 2:
- requires += ['python-dateutil>=1.0, != 2.0']
++++++ freezegun-0.3.12.tar.gz -> freezegun-0.3.15.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/CHANGELOG
new/freezegun-0.3.15/CHANGELOG
--- old/freezegun-0.3.12/CHANGELOG 2019-05-30 03:55:02.000000000 +0200
+++ new/freezegun-0.3.15/CHANGELOG 2020-02-18 01:24:32.000000000 +0100
@@ -4,6 +4,22 @@
Latest
------
+0.3.15
+------
+
+* Fix locale timestamp bug. CC #328
+
+0.3.14
+------
+
+* Fix calendar.timegm behavior
+
+0.3.13
+------
+
+* Fix for Py3.8
+* Reset time.time_ns on stop
+
0.3.12
------
@@ -11,6 +27,7 @@
* Ignore Selenium
* Move to pytest
* Conditionally patch time.clock
+* Patch time.time_ns added in Python 3.7
0.3.11
------
@@ -57,4 +74,4 @@
* Add `tick` argument to allow time to move forward
* Performance improvements
-* Fix timezone example in README
\ No newline at end of file
+* Fix timezone example in README
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/MANIFEST.in
new/freezegun-0.3.15/MANIFEST.in
--- old/freezegun-0.3.12/MANIFEST.in 2018-03-06 01:33:10.000000000 +0100
+++ new/freezegun-0.3.15/MANIFEST.in 2019-07-09 04:03:36.000000000 +0200
@@ -1,4 +1,4 @@
-include README.rst LICENSE AUTHORS.rst CHANGELOG
+include README.rst LICENSE AUTHORS.rst CHANGELOG pyproject.toml
recursive-include tests *
global-exclude __pycache__
global-exclude *.py[co]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/PKG-INFO
new/freezegun-0.3.15/PKG-INFO
--- old/freezegun-0.3.12/PKG-INFO 2019-05-30 04:02:10.000000000 +0200
+++ new/freezegun-0.3.15/PKG-INFO 2020-02-18 01:25:22.000000000 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 1.2
Name: freezegun
-Version: 0.3.12
+Version: 0.3.15
Summary: Let your Python tests travel through time
Home-page: https://github.com/spulec/freezegun
Author: Steve Pulec
@@ -237,7 +237,7 @@
$ pip install freezegun
- On Debian (Testing and Unstable) systems:
+ On Debian systems:
.. code-block:: bash
@@ -248,10 +248,10 @@
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
-Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
+Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
-Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
+Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/README.rst
new/freezegun-0.3.15/README.rst
--- old/freezegun-0.3.12/README.rst 2019-05-30 04:02:08.000000000 +0200
+++ new/freezegun-0.3.15/README.rst 2019-07-09 04:03:36.000000000 +0200
@@ -229,7 +229,7 @@
$ pip install freezegun
-On Debian (Testing and Unstable) systems:
+On Debian systems:
.. code-block:: bash
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/freezegun/__init__.py
new/freezegun-0.3.15/freezegun/__init__.py
--- old/freezegun-0.3.12/freezegun/__init__.py 2019-05-30 03:55:25.000000000
+0200
+++ new/freezegun-0.3.15/freezegun/__init__.py 2020-02-18 01:24:45.000000000
+0100
@@ -9,7 +9,7 @@
from .api import freeze_time
__title__ = 'freezegun'
-__version__ = '0.3.12'
+__version__ = '0.3.15'
__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.12/freezegun/_async.py
new/freezegun-0.3.15/freezegun/_async.py
--- old/freezegun-0.3.12/freezegun/_async.py 2018-03-06 03:30:32.000000000
+0100
+++ new/freezegun-0.3.15/freezegun/_async.py 2020-01-14 03:31:03.000000000
+0100
@@ -5,13 +5,12 @@
def wrap_coroutine(api, coroutine):
@functools.wraps(coroutine)
- @asyncio.coroutine
- def wrapper(*args, **kwargs):
+ async def wrapper(*args, **kwargs):
with api as time_factory:
if api.as_arg:
- result = yield from coroutine(time_factory, *args, **kwargs)
+ result = await coroutine(time_factory, *args, **kwargs)
else:
- result = yield from coroutine(*args, **kwargs)
+ result = await coroutine(*args, **kwargs)
return result
return wrapper
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/freezegun/_async_coroutine.py
new/freezegun-0.3.15/freezegun/_async_coroutine.py
--- old/freezegun-0.3.12/freezegun/_async_coroutine.py 1970-01-01
01:00:00.000000000 +0100
+++ new/freezegun-0.3.15/freezegun/_async_coroutine.py 2020-01-14
03:31:03.000000000 +0100
@@ -0,0 +1,17 @@
+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
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/freezegun/api.py
new/freezegun-0.3.15/freezegun/api.py
--- old/freezegun-0.3.12/freezegun/api.py 2019-05-30 03:52:31.000000000
+0200
+++ new/freezegun-0.3.15/freezegun/api.py 2020-02-18 01:23:41.000000000
+0100
@@ -1,3 +1,4 @@
+import dateutil
import datetime
import functools
import sys
@@ -20,6 +21,9 @@
except ImportError:
MayaDT = None
+_TIME_NS_PRESENT = hasattr(time, 'time_ns')
+_EPOCH = datetime.datetime(1970, 1, 1)
+_EPOCHTZ = datetime.datetime(1970, 1, 1, tzinfo=dateutil.tz.UTC)
real_time = time.time
real_localtime = time.localtime
@@ -28,7 +32,12 @@
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)
+
+if _TIME_NS_PRESENT:
+ real_time_ns = time.time_ns
+ real_date_objects.append(real_time_ns)
+
+_real_time_object_ids = {id(obj) for obj in real_date_objects}
# time.clock is deprecated and was removed in Python 3.8
real_clock = getattr(time, 'clock', None)
@@ -41,9 +50,9 @@
# Python3 doesn't have basestring, but it does have str.
try:
# noinspection PyUnresolvedReferences
- string_type = basestring
+ _string_type = basestring
except NameError:
- string_type = str
+ _string_type = str
try:
# noinspection PyUnresolvedReferences
@@ -72,7 +81,10 @@
try:
iscoroutinefunction = inspect.iscoroutinefunction
- from freezegun._async import wrap_coroutine
+ if sys.version_info < (3, 5):
+ from freezegun._async_coroutine import wrap_coroutine
+ else:
+ from freezegun._async import wrap_coroutine
except AttributeError:
iscoroutinefunction = lambda x: False
@@ -115,7 +127,7 @@
module_dir = dir(module)
except (ImportError, TypeError):
module_dir = []
- return '{0}-{1}'.format(id(module), hash(frozenset(module_dir)))
+ return '{}-{}'.format(id(module), hash(frozenset(module_dir)))
def _get_cached_module_attributes(module):
@@ -175,6 +187,12 @@
current_time = get_current_time()
return calendar.timegm(current_time.timetuple()) +
current_time.microsecond / 1000000.0
+if _TIME_NS_PRESENT:
+ def fake_time_ns():
+ if _should_use_real_time():
+ return real_time_ns()
+ return int(int(fake_time()) * 1e9)
+
def fake_localtime(t=None):
if t is not None:
@@ -321,6 +339,19 @@
return datetime_to_fakedatetime(real_datetime.astimezone(self, tz))
@classmethod
+ def fromtimestamp(cls, t, tz=None):
+ if tz is None:
+ return real_datetime.fromtimestamp(
+ t, tz=dateutil.tz.tzoffset("freezegun", cls._tz_offset())
+ ).replace(tzinfo=None)
+ return datetime_to_fakedatetime(real_datetime.fromtimestamp(t, tz))
+
+ def timestamp(self):
+ if self.tzinfo is None:
+ return (self - _EPOCH - self._tz_offset()).total_seconds()
+ return (self - _EPOCHTZ).total_seconds()
+
+ @classmethod
def now(cls, tz=None):
now = cls._time_to_freeze() or real_datetime.now()
if tz:
@@ -331,7 +362,7 @@
def date(self):
return date_to_fakedate(self)
-
+
@property
def nanosecond(self):
try:
@@ -599,14 +630,18 @@
('real_time', real_time, fake_time),
]
+ if _TIME_NS_PRESENT:
+ time.time_ns = fake_time_ns
+ to_patch.append(('real_time_ns', real_time_ns, fake_time_ns))
+
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)
+ self.reals = {id(fake): real for real_name, real, fake in to_patch}
+ fakes = {id(real): fake for real_name, real, fake in to_patch}
add_change = self.undo_changes.append
# Save the current loaded modules
@@ -680,6 +715,9 @@
time.strftime = real_strftime
time.clock = real_clock
+ if _TIME_NS_PRESENT:
+ time.time_ns = real_time_ns
+
if uuid_generate_time_attr:
setattr(uuid, uuid_generate_time_attr, real_uuid_generate_time)
uuid._UuidCreate = real_uuid_create
@@ -706,7 +744,7 @@
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,
+ acceptable_times = (type(None), _string_type, datetime.date,
datetime.timedelta,
types.FunctionType, types.GeneratorType)
if MayaDT is not None:
@@ -715,7 +753,7 @@
if not isinstance(time_to_freeze, acceptable_times):
raise TypeError(('freeze_time() expected None, a string, date
instance, datetime '
'instance, MayaDT, timedelta instance, function or a
generator, but got '
- 'type {0}.').format(type(time_to_freeze)))
+ 'type {}.').format(type(time_to_freeze)))
if tick and not _is_cpython:
raise SystemError('Calling freeze_time with tick=True is only
compatible with CPython')
@@ -741,7 +779,7 @@
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)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/freezegun.egg-info/PKG-INFO
new/freezegun-0.3.15/freezegun.egg-info/PKG-INFO
--- old/freezegun-0.3.12/freezegun.egg-info/PKG-INFO 2019-05-30
04:02:10.000000000 +0200
+++ new/freezegun-0.3.15/freezegun.egg-info/PKG-INFO 2020-02-18
01:25:22.000000000 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 1.2
Name: freezegun
-Version: 0.3.12
+Version: 0.3.15
Summary: Let your Python tests travel through time
Home-page: https://github.com/spulec/freezegun
Author: Steve Pulec
@@ -237,7 +237,7 @@
$ pip install freezegun
- On Debian (Testing and Unstable) systems:
+ On Debian systems:
.. code-block:: bash
@@ -248,10 +248,10 @@
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
-Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
+Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
-Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
+Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/freezegun.egg-info/SOURCES.txt
new/freezegun-0.3.15/freezegun.egg-info/SOURCES.txt
--- old/freezegun-0.3.12/freezegun.egg-info/SOURCES.txt 2019-05-30
04:02:10.000000000 +0200
+++ new/freezegun-0.3.15/freezegun.egg-info/SOURCES.txt 2020-02-18
01:25:22.000000000 +0100
@@ -3,10 +3,12 @@
LICENSE
MANIFEST.in
README.rst
+pyproject.toml
setup.cfg
setup.py
freezegun/__init__.py
freezegun/_async.py
+freezegun/_async_coroutine.py
freezegun/api.py
freezegun.egg-info/PKG-INFO
freezegun.egg-info/SOURCES.txt
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/pyproject.toml
new/freezegun-0.3.15/pyproject.toml
--- old/freezegun-0.3.12/pyproject.toml 1970-01-01 01:00:00.000000000 +0100
+++ new/freezegun-0.3.15/pyproject.toml 2019-07-09 04:03:36.000000000 +0200
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["setuptools", "wheel"]
+build-backend = "setuptools.build_meta"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/setup.py
new/freezegun-0.3.15/setup.py
--- old/freezegun-0.3.12/setup.py 2019-05-30 04:01:14.000000000 +0200
+++ new/freezegun-0.3.15/setup.py 2020-02-18 01:24:40.000000000 +0100
@@ -4,7 +4,10 @@
from setuptools import setup
requires = ['six']
-tests_require = ['mock', 'nose']
+tests_require = [
+ 'mock;python_version<"3.4"',
+ 'nose'
+]
if sys.version_info.major == 2:
requires += ['python-dateutil>=1.0, != 2.0']
@@ -18,7 +21,7 @@
setup(
name='freezegun',
- version='0.3.12',
+ version='0.3.15',
description='Let your Python tests travel through time',
long_description=readme,
author='Steve Pulec',
@@ -29,16 +32,16 @@
tests_require=tests_require,
include_package_data=True,
license='Apache 2.0',
- python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
+ python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
- 'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
+ 'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/tests/test_datetimes.py
new/freezegun-0.3.15/tests/test_datetimes.py
--- old/freezegun-0.3.12/tests/test_datetimes.py 2019-05-30
03:52:31.000000000 +0200
+++ new/freezegun-0.3.15/tests/test_datetimes.py 2020-02-18
01:23:41.000000000 +0100
@@ -1,9 +1,11 @@
import time
+import calendar
import datetime
import unittest
import locale
import sys
from unittest import SkipTest
+from dateutil.tz import UTC
import pytest
from tests import utils
@@ -19,6 +21,7 @@
# time.clock was removed in Python 3.8
HAS_CLOCK = hasattr(time, 'clock')
+HAS_TIME_NS = hasattr(time, 'time_ns')
class temp_locale(object):
"""Temporarily change the locale."""
@@ -407,8 +410,8 @@
assert self.a_mock.__class__ == Callable
def test_class_decorator_wraps_callable_object_py3(self):
- if sys.version_info[0] != 3:
- raise SkipTest("test target is Python3")
+ if sys.version_info[0] == 2:
+ raise SkipTest("test target is Python3+")
assert self.a_mock.__wrapped__.__class__ == Callable
@staticmethod
@@ -447,9 +450,7 @@
def _assert_datetime_date_and_time_are_all_equal(expected_datetime):
assert datetime.datetime.now() == expected_datetime
assert datetime.date.today() == expected_datetime.date()
- datetime_from_time = datetime.datetime.fromtimestamp(time.time())
- timezone_adjusted_datetime = datetime_from_time +
datetime.timedelta(seconds=time.timezone)
- assert timezone_adjusted_datetime == expected_datetime
+ assert datetime.datetime.fromtimestamp(time.time()) == expected_datetime
def test_nested_context_manager_with_tz_offsets():
@@ -643,12 +644,20 @@
from freezegun import api
api.call_stack_inspection_limit = 100 # just to increase coverage
+ timestamp_to_convert = 1579602312
+ time_tuple = time.gmtime(timestamp_to_convert)
+
with freeze_time(frozen):
assert time.time() == expected_frozen
# assert time.localtime() == expected_frozen_local
assert time.gmtime() == expected_frozen_gmt
if HAS_CLOCK:
assert time.clock() == expected_clock
+ if HAS_TIME_NS:
+ assert time.time_ns() == expected_frozen * 1e9
+
+ assert calendar.timegm(time.gmtime()) == expected_frozen
+ assert calendar.timegm(time_tuple) == timestamp_to_convert
with freeze_time(frozen, ignore=['_pytest', 'nose']):
assert time.time() != expected_frozen
@@ -656,3 +665,72 @@
assert time.gmtime() != expected_frozen_gmt
if HAS_CLOCK:
assert time.clock() != expected_clock
+ if HAS_TIME_NS:
+ assert time.time_ns() != expected_frozen * 1e9
+
+ assert calendar.timegm(time.gmtime()) != expected_frozen
+ assert calendar.timegm(time_tuple) == timestamp_to_convert
+
+
[email protected](not HAS_TIME_NS,
+ reason="time.time_ns is present only on 3.7 and above")
+def test_time_ns():
+ freezer = freeze_time("2012-01-14")
+ 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 time.time_ns() == expected_timestamp * 1e9
+ freezer.stop()
+ assert time.time() != expected_timestamp
+ assert time.time_ns() != expected_timestamp * 1e9
+
+
+def test_compare_datetime_and_time_with_timezone(monkeypatch):
+ """
+ Compare the result of datetime.datetime.now() and time.time() in a non-UTC
timezone. These
+ should be consistent.
+ """
+ try:
+ with monkeypatch.context() as m, freeze_time("1970-01-01 00:00:00"):
+ m.setenv("TZ", "Europe/Berlin")
+ time.tzset()
+
+ now = datetime.datetime.now()
+ assert now == datetime.datetime.fromtimestamp(time.time())
+ assert now == datetime.datetime.utcfromtimestamp(time.time())
+ assert now == datetime.datetime.utcnow()
+ assert now.timestamp() == time.time()
+ finally:
+ time.tzset() # set the timezone back to what is was before
+
+
+def test_timestamp_with_tzoffset():
+ with freeze_time("2000-01-01", tz_offset=6):
+ utcnow = datetime.datetime(2000, 1, 1, 0)
+ nowtz = datetime.datetime(2000, 1, 1, 0, tzinfo=UTC)
+ now = datetime.datetime(2000, 1, 1, 6)
+ assert now == datetime.datetime.now()
+ assert now == datetime.datetime.fromtimestamp(time.time())
+ assert now.timestamp() == time.time()
+ assert nowtz.timestamp() == time.time()
+
+ assert utcnow == datetime.datetime.utcfromtimestamp(time.time())
+ assert utcnow == datetime.datetime.utcnow()
+
[email protected]("timezone handling is currently incorrect")
+def test_datetime_in_timezone(monkeypatch):
+ """
+ It is assumed that the argument passed to freeze_time is in UTC, unless
explicitly indicated
+ otherwise. Therefore datetime.now() should return the frozen time with an
offset.
+ """
+ try:
+ with monkeypatch.context() as m, freeze_time("1970-01-01 00:00:00"):
+ m.setenv("TZ", "Europe/Berlin")
+ time.tzset()
+
+ assert datetime.datetime.now() == datetime.datetime(1970, 1, 1, 1,
0, 0)
+ finally:
+ time.tzset() # set the timezone back to what is was before
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/tests/test_ticking.py
new/freezegun-0.3.15/tests/test_ticking.py
--- old/freezegun-0.3.12/tests/test_ticking.py 2019-05-30 03:52:31.000000000
+0200
+++ new/freezegun-0.3.15/tests/test_ticking.py 2020-01-14 03:31:03.000000000
+0100
@@ -1,6 +1,9 @@
import datetime
import time
-import mock
+try:
+ from unittest import mock
+except (ImportError, AttributeError):
+ import mock
import pytest
from freezegun import freeze_time
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/freezegun-0.3.12/tests/test_utils.py
new/freezegun-0.3.15/tests/test_utils.py
--- old/freezegun-0.3.12/tests/test_utils.py 2019-05-30 03:52:31.000000000
+0200
+++ new/freezegun-0.3.15/tests/test_utils.py 2020-01-14 03:31:03.000000000
+0100
@@ -1,6 +1,9 @@
from unittest import SkipTest
-import mock
+try:
+ from unittest import mock
+except (ImportError, AttributeError):
+ import mock
from freezegun import api
from tests import utils