Skip to content

Commit

Permalink
Merge pull request #12 from NextThought/issue11
Browse files Browse the repository at this point in the history
Use unittest.mock instead of fudge.
  • Loading branch information
jamadden committed Oct 23, 2017
2 parents 4e48341 + 2cf5c9a commit b625050
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.installed.cfg
.dir-locals.el
.pydevproject
.project

*.egg-info
*.pyc
.coverage
Expand Down
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
=========


2.0.2 (unreleased)
2.1.0 (unreleased)
==================

- Make ``Acquisition`` an optional dependency. If it is not installed,
the ``aq_inContextOf`` matcher will always return False.

- Remove dependency on ``fudge``. Instead, we now use ``unittest.mock`` on
Python 3, or its backport ``mock`` on Python 2. See `issue 11
<https://github.com/NextThought/nti.testing/issues/11>`_.

2.0.1 (2017-10-18)
==================
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup, find_packages


version = '2.0.2.dev0'
version = '2.1.0.dev0'

entry_points = {
}
Expand Down Expand Up @@ -49,7 +49,6 @@ def _read(fname):
namespace_packages=['nti'],
install_requires=[
'zope.interface >= 4.1.2', # Listing first to work around a Travis CI issue
'fudge',
'pyhamcrest',
'six',
'setuptools',
Expand All @@ -68,5 +67,9 @@ def _read(fname):
'Sphinx',
'sphinx_rtd_theme',
],
':python_version == "2.7"' : [
# backport of unittest.mock for Python 2.7.
'mock',
],
},
)
13 changes: 8 additions & 5 deletions src/nti/testing/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import functools
from time import time as _real_time

import fudge
try:
from unittest import mock
except ImportError:
import mock

import six

__docformat__ = "restructuredtext en"
Expand All @@ -25,21 +29,20 @@ def __init__(self, granularity=1.0):
self._granularity = granularity

def __call__(self, func):
@fudge.patch('time.time')
@mock.patch('time.time')
@functools.wraps(func)
def wrapper(*args, **kwargs):

fake_time = args[-1]
assert isinstance(fake_time, fudge.Fake), args
assert isinstance(fake_time, mock.Mock), args
args = args[:-1]

# make time monotonically increasing
def incr():
global _current_time # pylint:disable=global-statement
_current_time = max(_real_time(), _current_time + self._granularity)
return _current_time
fake_time.is_callable()
fake_time._callable.call_replacement = incr # pylint:disable=protected-access
fake_time.side_effect = incr

return func(*args, **kwargs)
return wrapper
Expand Down

0 comments on commit b625050

Please sign in to comment.