[Python-modules-commits] [python-mock] 03/12: Import python-mock_2.0.0.orig.tar.gz
Ondřej Nový
onovy-guest at moszumanska.debian.org
Tue Jun 7 10:47:13 UTC 2016
This is an automated email from the git hooks/post-receive script.
onovy-guest pushed a commit to branch master
in repository python-mock.
commit 6811a9d12ae8b5e8ba7ee0f6bca5b9b8d95530dc
Author: Ondřej Nový <novy at ondrej.org>
Date: Tue Jun 7 12:00:51 2016 +0200
Import python-mock_2.0.0.orig.tar.gz
---
.travis.yml | 3 +-
AUTHORS | 6 ++++
ChangeLog | 23 ++++++++++++
NEWS | 12 +++++++
PKG-INFO | 4 +--
README.rst | 2 +-
docs/conf.py | 6 ++--
docs/index.txt | 16 +++++----
mock.egg-info/PKG-INFO | 4 +--
mock.egg-info/pbr.json | 2 +-
mock.egg-info/requires.txt | 4 +--
mock/mock.py | 82 ++++++++++++++++++++++++------------------
mock/tests/support.py | 1 -
mock/tests/testhelpers.py | 24 ++++++++++---
mock/tests/testmagicmethods.py | 22 ++++++------
mock/tests/testmock.py | 39 ++++++++++++++++----
mock/tests/testpatch.py | 32 +++++++++++++++--
mock/tests/testwith.py | 28 +++++++++++++++
requirements.txt | 4 +--
setup.py | 14 +-------
tools/pre-applypatch | 1 -
21 files changed, 233 insertions(+), 96 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index ce2d439..7f855dd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,6 @@ language: python
python:
- "2.6"
- "2.7"
- - "3.2"
- "3.3"
- "3.4"
- pypy
@@ -23,4 +22,4 @@ install:
script:
- unit2
- if [ -z "$SKIP_DOCS" ]; then python setup.py build_sphinx; fi
- - rst2html.py README.rst README.html
+ - rst2html.py --strict README.rst README.html
diff --git a/AUTHORS b/AUTHORS
index 9e36071..64b4347 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -2,10 +2,13 @@ Andrew Svetlov <andrew.svetlov at gmail.com>
Antoine Pitrou <solipsis at pitrou.net>
Berker Peksag <berker.peksag at gmail.com>
Darragh Bailey <dbailey at hp.com>
+Frankie Robertson <frankie at robertson.name>
+Joachim Jablon <joachim.jablon at smart-impulse.com>
Konrad Delong <konryd at gmail.com>
Kumar McMillan <kumar.mcmillan at gmail.com>
Kushal Das <kushaldas at gmail.com>
Larry Hastings <larry at hastings.org>
+Michael Fladischer <FladischerMichael at fladi.at>
Michael Foord <mfoord at python.org>
Michael Foord <michael at python.org>
Michael Foord <michael at voidspace.org.uk>
@@ -13,10 +16,13 @@ Nick Coghlan <ncoghlan at gmail.com>
R David Murray <rdmurray at bitdance.com>
Rob McQueen <rob at nylas.com>
Robert Collins <rbtcollins at hp.com>
+Senthil Kumaran <senthil at uthcode.com>
Serhiy Storchaka <storchaka at gmail.com>
Terry Jan Reedy <tjreedy at udel.edu>
+Victor Stinner <victor.stinner at gmail.com>
convert-repo <convert-repo at localhost>
fuzzyman <fuzzyman at localhost>
konryd <konryd at localhost>
+lord63 <lord63.j at gmail.com>
unknown <unknown at localhost>
Łukasz Langa <lukasz at langa.pl>
diff --git a/ChangeLog b/ChangeLog
index c776da0..853b720 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,29 @@
CHANGES
=======
+2.0.0
+-----
+
+* Fix #338: depend on a fixed version of funcsigs
+* More 3.2 support dropping cleanup
+* Update sync point
+* Add Mock.assert_called()
+* Issue25347 - Format the error message output of mock's assert_has_calls method
+* Issue #22138: Fix mock.patch behavior when patching descriptors. Restore original values after patching
+* Issue #24857: Comparing call_args to a long sequence now correctly returns a boolean result instead of raising an exception
+* Issue #23004: mock_open() now reads binary data correctly when the type of read_data is bytes
+* Add version info in the docs
+* Update six to a version with raises_from
+* Fix #328 - handle unicode __repr__ on Python 2.x
+* Drop support for Python 3.2
+* Fix typo in docs/index.txt
+* Fix README.rst checking
+* Be clearer about Python version compat
+* Issue #295: use a setup_requires dependency
+* Improve grouping of imports in tests
+* Use six to detect python2/3 in main module
+* Use six to detect python2/3 in test modules
+
1.3.0
-----
diff --git a/NEWS b/NEWS
index f3f0086..2120418 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,18 @@
Library
-------
+- Issue #26323: Add Mock.assert_called() and Mock.assert_called_once()
+ methods to unittest.mock. Patch written by Amit Saha.
+
+- Issue #22138: Fix mock.patch behavior when patching descriptors. Restore
+ original values after patching. Patch contributed by Sean McCully.
+
+- Issue #24857: Comparing call_args to a long sequence now correctly returns a
+ boolean result instead of raising an exception. Patch by A Kaptur.
+
+- Issue #23004: mock_open() now reads binary data correctly when the type of
+ read_data is bytes. Initial patch by Aaron Hill.
+
- Issue #21750: mock_open.read_data can now be read from each instance, as it
could in Python 3.3.
diff --git a/PKG-INFO b/PKG-INFO
index f112102..7794c53 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: mock
-Version: 1.3.0
+Version: 2.0.0
Summary: Rolling backport of unittest.mock for all Pythons
Home-page: https://github.com/testing-cabal/mock
Author: Testing Cabal
@@ -15,7 +15,7 @@ Description: mock is a library for testing in Python. It allows you to replace p
onwards.
This package contains a rolling backport of the standard library mock code
- compatible with Python 2.6 and up, and 3.2 and up.
+ compatible with Python 2.6 and up, and 3.3 and up.
Please see the standard library documentation for more details.
diff --git a/README.rst b/README.rst
index 9bc1564..a7b632c 100644
--- a/README.rst
+++ b/README.rst
@@ -7,7 +7,7 @@ mock is now part of the Python standard library, available as `unittest.mock
onwards.
This package contains a rolling backport of the standard library mock code
-compatible with Python 2.6 and up, and 3.2 and up.
+compatible with Python 2.6 and up, and 3.3 and up.
Please see the standard library documentation for more details.
diff --git a/docs/conf.py b/docs/conf.py
index 912c891..d32357d 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -14,6 +14,8 @@
import sys, os
sys.path.insert(0, os.path.abspath('..'))
+import mock
+
# If your extensions are in another directory, add it here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
@@ -71,9 +73,9 @@ copyright = u'2007-2015, Michael Foord & the mock team'
# other places throughout the built documents. Supplied by pbr.
#
# The short X.Y version.
-version = None
+version = mock.mock._v.brief_string()
# The full version, including alpha/beta/rc tags.
-release = None
+release = mock.__version__
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used: (Set from pbr)
diff --git a/docs/index.txt b/docs/index.txt
index f8e2320..3889ab8 100644
--- a/docs/index.txt
+++ b/docs/index.txt
@@ -12,7 +12,7 @@
<http://lists.idyll.org/listinfo/testing-in-python>`_
:Issue tracker: `Github Issues
<https://github.com/testing-cabal/mock/issues>`_
-:Last sync: 3f409f756b7b8f75c4543b2c31566bd8b8dbb3dd
+:Last sync: cb6aab1248c4aec4dd578bea717854505a6fb55d
.. _Mock Homepage: https://github.com/testing-cabal/mock
.. _BSD License: http://github.com/testing-cabal/mock/blob/master/LICENSE.txt
@@ -45,7 +45,9 @@ the newest features from the latest release of Python available for all
Pythons.
The ``mock`` package contains a rolling backport of the standard library mock
-code compatible with Python 2.6 and up, and 3.2 and up.
+code compatible with Python 2.6 and up, and 3.3 and up. Python 3.2 is supported
+by mock 1.3.0 and below - with pip no longer supporting 3.2, we cannot test
+against that version anymore.
Please see the standard library documentation for usage details.
@@ -103,10 +105,10 @@ Python NEWS entries from cPython:
.. index:: older versions
-Older Versions
-++++++++++++++
+Older Versions of Python
+++++++++++++++++++++++++
-Version 1.0.1 is the last version compatible with Python 2.6.
+Version 1.0.1 is the last version compatible with Python < 2.6.
.. index:: maintainer notes
@@ -121,9 +123,9 @@ Checkout from git (see :ref:`installing`) and submit pull requests.
Committers can just push as desired: since all semantic development takes
place in cPython, the backport process is as lightweight as we can make it.
-mock is CI tested using Travis-CI on Python versions 2.6, 2.7, 3.2, 3.3, 3.4,
+mock is CI tested using Travis-CI on Python versions 2.6, 2.7, 3.3, 3.4,
3.5, nightly Python 3 builds, pypy, pypy3. Jython support is desired, if
-someone could contribute a patch to .travis.jml to support it that would be
+someone could contribute a patch to .travis.yml to support it that would be
excellent.
Releasing
diff --git a/mock.egg-info/PKG-INFO b/mock.egg-info/PKG-INFO
index f112102..7794c53 100644
--- a/mock.egg-info/PKG-INFO
+++ b/mock.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: mock
-Version: 1.3.0
+Version: 2.0.0
Summary: Rolling backport of unittest.mock for all Pythons
Home-page: https://github.com/testing-cabal/mock
Author: Testing Cabal
@@ -15,7 +15,7 @@ Description: mock is a library for testing in Python. It allows you to replace p
onwards.
This package contains a rolling backport of the standard library mock code
- compatible with Python 2.6 and up, and 3.2 and up.
+ compatible with Python 2.6 and up, and 3.3 and up.
Please see the standard library documentation for more details.
diff --git a/mock.egg-info/pbr.json b/mock.egg-info/pbr.json
index 5b2d822..e399123 100644
--- a/mock.egg-info/pbr.json
+++ b/mock.egg-info/pbr.json
@@ -1 +1 @@
-{"is_release": true, "git_version": "e34a7cb"}
\ No newline at end of file
+{"is_release": true, "git_version": "286792b"}
\ No newline at end of file
diff --git a/mock.egg-info/requires.txt b/mock.egg-info/requires.txt
index 34c5907..59ea880 100644
--- a/mock.egg-info/requires.txt
+++ b/mock.egg-info/requires.txt
@@ -1,8 +1,8 @@
pbr>=0.11
-six>=1.7
+six>=1.9
[:(python_version<"3.3")]
-funcsigs
+funcsigs>=1
[docs:(python_version<"3" or python_version>="3.3")]
sphinx
diff --git a/mock/mock.py b/mock/mock.py
index dc01947..c674a85 100644
--- a/mock/mock.py
+++ b/mock/mock.py
@@ -74,29 +74,11 @@ version_info = _v.version_tuple()
import mock
-inPy3k = sys.version_info[0] == 3
-
-
try:
inspectsignature = inspect.signature
except AttributeError:
import funcsigs
inspectsignature = funcsigs.signature
- # Has funcsigs been fixed?
- try:
- class F:
- def f(a, self):
- pass
- inspectsignature(partial(F.f, None)).bind(self=10)
- except TypeError:
- def fixedbind(*args, **kwargs):
- self = args[0]
- args = args[1:]
- return self._bind(args, kwargs)
- funcsigs.Signature.bind = fixedbind
- del fixedbind
- finally:
- del F
# TODO: use six.
@@ -118,7 +100,7 @@ except NameError:
# Python 2.4 compatibility
BaseException = Exception
-if not inPy3k:
+if six.PY2:
# Python 2's next() can't handle a non-iterator with a __next__ method.
_next = next
def next(obj, _next=_next):
@@ -151,7 +133,7 @@ except AttributeError:
self = 'im_self'
builtin = '__builtin__'
-if inPy3k:
+if six.PY3:
self = '__self__'
builtin = 'builtins'
@@ -250,7 +232,7 @@ def _copy_func_details(func, funcopy):
funcopy.__kwdefaults__ = func.__kwdefaults__
except AttributeError:
pass
- if not inPy3k:
+ if six.PY2:
funcopy.func_defaults = func.func_defaults
return
@@ -276,7 +258,7 @@ def _instance_callable(obj):
# already an instance
return getattr(obj, '__call__', None) is not None
- if inPy3k:
+ if six.PY3:
# *could* be broken by a class overriding __mro__ or __dict__ via
# a metaclass
for base in (obj,) + obj.__mro__:
@@ -410,7 +392,7 @@ def _copy(value):
ClassTypes = (type,)
-if not inPy3k:
+if six.PY2:
ClassTypes = (type, ClassType)
_allowed_names = set((
@@ -914,6 +896,24 @@ class NonCallableMock(Base):
(self._mock_name or 'mock', self.call_count))
raise AssertionError(msg)
+ def assert_called(_mock_self):
+ """assert that the mock was called at least once
+ """
+ self = _mock_self
+ if self.call_count == 0:
+ msg = ("Expected '%s' to have been called." %
+ self._mock_name or 'mock')
+ raise AssertionError(msg)
+
+ def assert_called_once(_mock_self):
+ """assert that the mock was called only once.
+ """
+ self = _mock_self
+ if not self.call_count == 1:
+ msg = ("Expected '%s' to have been called once. Called %s times." %
+ (self._mock_name or 'mock', self.call_count))
+ raise AssertionError(msg)
+
def assert_called_with(_mock_self, *args, **kwargs):
"""assert that the mock was called with the specified arguments.
@@ -926,7 +926,7 @@ class NonCallableMock(Base):
def _error_message(cause):
msg = self._format_mock_failure_message(args, kwargs)
- if not inPy3k and cause is not None:
+ if six.PY2 and cause is not None:
# Tack on some diagnostics for Python without __cause__
msg = '%s\n%s' % (msg, str(cause))
return msg
@@ -965,7 +965,7 @@ class NonCallableMock(Base):
if expected not in all_calls:
six.raise_from(AssertionError(
'Calls not found.\nExpected: %r\n'
- 'Actual: %r' % (calls, self.mock_calls)
+ 'Actual: %r' % (_CallList(calls), self.mock_calls)
), cause)
return
@@ -1480,7 +1480,10 @@ class _patch(object):
setattr(self.target, self.attribute, self.temp_original)
else:
delattr(self.target, self.attribute)
- if not self.create and not hasattr(self.target, self.attribute):
+ if not self.create and (not hasattr(self.target, self.attribute) or
+ self.attribute in ('__doc__', '__module__',
+ '__defaults__', '__annotations__',
+ '__kwdefaults__')):
# needed for proxy objects like django settings
setattr(self.target, self.attribute, self.temp_original)
@@ -1826,12 +1829,12 @@ magic_methods = (
numerics = (
"add sub mul matmul div floordiv mod lshift rshift and xor or pow"
)
-if inPy3k:
+if six.PY3:
numerics += ' truediv'
inplace = ' '.join('i%s' % n for n in numerics.split())
right = ' '.join('r%s' % n for n in numerics.split())
extra = ''
-if inPy3k:
+if six.PY3:
extra = 'bool next '
else:
extra = 'unicode long nonzero oct hex truediv rtruediv '
@@ -2062,8 +2065,15 @@ def _format_call_signature(name, args, kwargs):
message = '%s(%%s)' % name
formatted_args = ''
args_string = ', '.join([repr(arg) for arg in args])
+
+ def encode_item(item):
+ if six.PY2 and isinstance(item, unicode):
+ return item.encode("utf-8")
+ else:
+ return item
+
kwargs_string = ', '.join([
- '%s=%r' % (key, value) for key, value in sorted(kwargs.items())
+ '%s=%r' % (encode_item(key), value) for key, value in sorted(kwargs.items())
])
if args_string:
formatted_args = args_string
@@ -2165,8 +2175,7 @@ class _Call(tuple):
else:
other_args = ()
other_kwargs = value
- else:
- # len 2
+ elif len_other == 2:
# could be (name, args) or (name, kwargs) or (args, kwargs)
first, second = other
if isinstance(first, basestring):
@@ -2177,6 +2186,8 @@ class _Call(tuple):
other_args, other_kwargs = (), second
else:
other_args, other_kwargs = first, second
+ else:
+ return False
if self_name and other_name != self_name:
return False
@@ -2438,9 +2449,10 @@ def _iterate_read_data(read_data):
# Helper for mock_open:
# Retrieve lines from read_data via a generator so that separate calls to
# readline, read, and readlines are properly interleaved
- data_as_list = ['{0}\n'.format(l) for l in read_data.split('\n')]
+ sep = b'\n' if isinstance(read_data, bytes) else '\n'
+ data_as_list = [l + sep for l in read_data.split(sep)]
- if data_as_list[-1] == '\n':
+ if data_as_list[-1] == sep:
# If the last line ended in a newline, the list comprehension will have an
# extra entry that's just a newline. Remove this.
data_as_list = data_as_list[:-1]
@@ -2473,7 +2485,7 @@ def mock_open(mock=None, read_data=''):
def _read_side_effect(*args, **kwargs):
if handle.read.return_value is not None:
return handle.read.return_value
- return ''.join(_state[0])
+ return type(read_data)().join(_state[0])
def _readline_side_effect():
if handle.readline.return_value is not None:
@@ -2486,7 +2498,7 @@ def mock_open(mock=None, read_data=''):
global file_spec
if file_spec is None:
# set on first use
- if inPy3k:
+ if six.PY3:
import _io
file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
else:
diff --git a/mock/tests/support.py b/mock/tests/support.py
index 0cbdb2c..8e2082f 100644
--- a/mock/tests/support.py
+++ b/mock/tests/support.py
@@ -11,7 +11,6 @@ except NameError:
return hasattr(obj, '__call__')
-inPy3k = sys.version_info[0] == 3
with_available = sys.version_info[:2] >= (2, 5)
diff --git a/mock/tests/testhelpers.py b/mock/tests/testhelpers.py
index 99316e5..a87df1b 100644
--- a/mock/tests/testhelpers.py
+++ b/mock/tests/testhelpers.py
@@ -2,8 +2,8 @@
# E-mail: fuzzyman AT voidspace DOT org DOT uk
# http://www.voidspace.org.uk/python/mock/
+import six
import unittest2 as unittest
-from mock.tests.support import inPy3k
from mock import (
call, create_autospec, MagicMock,
@@ -403,7 +403,7 @@ class SpecSignatureTest(unittest.TestCase):
m = create_autospec(Foo, a='3')
self.assertEqual(m.a, '3')
- @unittest.skipUnless(inPy3k, "Keyword only arguments Python 3 specific")
+ @unittest.skipUnless(six.PY3, "Keyword only arguments Python 3 specific")
def test_create_autospec_keyword_only_arguments(self):
func_def = "def foo(a, *, b=None):\n pass\n"
namespace = {}
@@ -558,7 +558,7 @@ class SpecSignatureTest(unittest.TestCase):
mock.g.assert_called_once_with(3, 4)
- @unittest.skipIf(inPy3k, "No old style classes in Python 3")
+ @unittest.skipIf(six.PY3, "No old style classes in Python 3")
def test_old_style_classes(self):
class Foo:
def f(self, a, b):
@@ -745,7 +745,7 @@ class SpecSignatureTest(unittest.TestCase):
mock.assert_called_with(4, 5)
- @unittest.skipIf(inPy3k, 'no old style classes in Python 3')
+ @unittest.skipIf(six.PY3, 'no old style classes in Python 3')
def test_signature_old_style_class(self):
class Foo:
def __init__(self, a, b=3):
@@ -773,7 +773,7 @@ class SpecSignatureTest(unittest.TestCase):
create_autospec(Foo)
- @unittest.skipIf(inPy3k, 'no old style classes in Python 3')
+ @unittest.skipIf(six.PY3, 'no old style classes in Python 3')
def test_old_style_class_with_no_init(self):
# this used to raise an exception
# due to Foo.__init__ raising an AttributeError
@@ -928,6 +928,20 @@ class TestCallList(unittest.TestCase):
self.assertEqual(str(mock.mock_calls), expected)
+ @unittest.skipIf(six.PY3, "Unicode is properly handled with Python 3")
+ def test_call_list_unicode(self):
+ # See github issue #328
+ mock = Mock()
+
+ class NonAsciiRepr(object):
+ def __repr__(self):
+ return "\xe9"
+
+ mock(**{unicode("a"): NonAsciiRepr()})
+
+ self.assertEqual(str(mock.mock_calls), "[call(a=\xe9)]")
+
+
def test_propertymock(self):
p = patch('%s.SomeClass.one' % __name__, new_callable=PropertyMock)
mock = p.start()
diff --git a/mock/tests/testmagicmethods.py b/mock/tests/testmagicmethods.py
index 5e39770..f47a202 100644
--- a/mock/tests/testmagicmethods.py
+++ b/mock/tests/testmagicmethods.py
@@ -4,10 +4,6 @@
from __future__ import division
-import unittest2 as unittest
-
-from mock.tests.support import inPy3k
-
try:
unicode
except NameError:
@@ -18,6 +14,10 @@ except NameError:
import inspect
import sys
import textwrap
+
+import six
+import unittest2 as unittest
+
from mock import Mock, MagicMock
from mock.mock import _magics
@@ -86,7 +86,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(str(mock), 'foo')
- @unittest.skipIf(inPy3k, "no unicode in Python 3")
+ @unittest.skipIf(six.PY3, "no unicode in Python 3")
def test_unicode(self):
mock = Mock()
self.assertEqual(unicode(mock), unicode(str(mock)))
@@ -166,7 +166,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(mock.value, 16)
del mock.__truediv__
- if inPy3k:
+ if six.PY3:
def itruediv(mock):
mock /= 4
self.assertRaises(TypeError, itruediv, mock)
@@ -198,7 +198,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertTrue(bool(m))
nonzero = lambda s: False
- if not inPy3k:
+ if six.PY2:
m.__nonzero__ = nonzero
else:
m.__bool__ = nonzero
@@ -216,7 +216,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self. assertTrue(mock <= 3)
self. assertTrue(mock >= 3)
- if not inPy3k:
+ if six.PY2:
# incomparable in Python 3
self.assertEqual(Mock() < 3, object() < 3)
self.assertEqual(Mock() > 3, object() > 3)
@@ -294,7 +294,7 @@ class TestMockingMagicMethods(unittest.TestCase):
name = '__nonzero__'
other = '__bool__'
- if inPy3k:
+ if six.PY3:
name, other = other, name
getattr(mock, name).return_value = False
self.assertFalse(hasattr(mock, other))
@@ -330,7 +330,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(unicode(mock), object.__str__(mock))
self.assertIsInstance(unicode(mock), unicode)
self.assertTrue(bool(mock))
- if not inPy3k:
+ if six.PY2:
self.assertEqual(oct(mock), '1')
else:
# in Python 3 oct and hex use __index__
@@ -340,7 +340,7 @@ class TestMockingMagicMethods(unittest.TestCase):
# how to test __sizeof__ ?
- @unittest.skipIf(inPy3k, "no __cmp__ in Python 3")
+ @unittest.skipIf(six.PY3, "no __cmp__ in Python 3")
def test_non_default_magic_methods(self):
mock = MagicMock()
self.assertRaises(AttributeError, lambda: mock.__cmp__)
diff --git a/mock/tests/testmock.py b/mock/tests/testmock.py
index d956064..7511c23 100644
--- a/mock/tests/testmock.py
+++ b/mock/tests/testmock.py
@@ -2,16 +2,14 @@
# E-mail: fuzzyman AT voidspace DOT org DOT uk
# http://www.voidspace.org.uk/python/mock/
-import unittest2 as unittest
-from mock.tests.support import (
- callable, inPy3k, is_instance, next
-)
-
import copy
import pickle
import sys
import tempfile
+import six
+import unittest2 as unittest
+
import mock
from mock import (
call, DEFAULT, patch, sentinel,
@@ -20,6 +18,9 @@ from mock import (
create_autospec
)
from mock.mock import _CallList
+from mock.tests.support import (
+ callable, is_instance, next
+)
try:
@@ -325,6 +326,9 @@ class MockTest(unittest.TestCase):
self.assertEqual(mock.call_args,
((sentinel.Arg,), {"kw": sentinel.Kwarg}))
+ # Comparing call_args to a long sequence should not raise
+ # an exception. See issue 24857.
+ self.assertFalse(mock.call_args == "a long sequence")
def test_assert_called_with(self):
mock = Mock()
@@ -663,7 +667,7 @@ class MockTest(unittest.TestCase):
copy.copy(Mock())
- @unittest.skipIf(inPy3k, "no old style classes in Python 3")
+ @unittest.skipIf(six.PY3, "no old style classes in Python 3")
def test_spec_old_style_classes(self):
class Foo:
bar = 7
@@ -677,7 +681,7 @@ class MockTest(unittest.TestCase):
self.assertRaises(AttributeError, lambda: mock.foo)
- @unittest.skipIf(inPy3k, "no old style classes in Python 3")
+ @unittest.skipIf(six.PY3, "no old style classes in Python 3")
def test_spec_set_old_style_classes(self):
class Foo:
bar = 7
@@ -1284,6 +1288,27 @@ class MockTest(unittest.TestCase):
with self.assertRaises(AssertionError):
m.hello.assert_not_called()
+ def test_assert_called(self):
+ m = Mock()
+ with self.assertRaises(AssertionError):
+ m.hello.assert_called()
+ m.hello()
+ m.hello.assert_called()
+
+ m.hello()
+ m.hello.assert_called()
+
+ def test_assert_called_once(self):
+ m = Mock()
+ with self.assertRaises(AssertionError):
+ m.hello.assert_called_once()
+ m.hello()
+ m.hello.assert_called_once()
+
+ m.hello()
+ with self.assertRaises(AssertionError):
+ m.hello.assert_called_once()
+
#Issue21256 printout of keyword args should be in deterministic order
def test_sorted_call_signature(self):
m = Mock()
diff --git a/mock/tests/testpatch.py b/mock/tests/testpatch.py
index ce84df2..32a6c27 100644
--- a/mock/tests/testpatch.py
+++ b/mock/tests/testpatch.py
@@ -5,10 +5,11 @@
import os
import sys
+import six
import unittest2 as unittest
from mock.tests import support
-from mock.tests.support import inPy3k, SomeClass, is_instance, callable
+from mock.tests.support import SomeClass, is_instance, callable
from mock import (
NonCallableMock, CallableMixin, patch, sentinel,
@@ -18,7 +19,7 @@ from mock import (
from mock.mock import _patch, _get_target
builtin_string = '__builtin__'
-if inPy3k:
+if six.PY3:
builtin_string = 'builtins'
unicode = str
@@ -1851,5 +1852,32 @@ class PatchTest(unittest.TestCase):
self.assertEqual(stopped, ["three", "two", "one"])
+ def test_special_attrs(self):
+ def foo(x=0):
+ """TEST"""
+ return x
+ with patch.object(foo, '__defaults__', (1, )):
+ self.assertEqual(foo(), 1)
+ self.assertEqual(foo(), 0)
+
+ with patch.object(foo, '__doc__', "FUN"):
+ self.assertEqual(foo.__doc__, "FUN")
+ self.assertEqual(foo.__doc__, "TEST")
+
+ with patch.object(foo, '__module__', "testpatch2"):
+ self.assertEqual(foo.__module__, "testpatch2")
+ self.assertEqual(foo.__module__, __name__)
+
+ if hasattr(self.test_special_attrs, '__annotations__'):
+ with patch.object(foo, '__annotations__', dict([('s', 1, )])):
+ self.assertEqual(foo.__annotations__, dict([('s', 1, )]))
+ self.assertEqual(foo.__annotations__, dict())
+
+ if hasattr(self.test_special_attrs, '__kwdefaults__'):
+ foo = eval("lambda *a, x=0: x")
+ with patch.object(foo, '__kwdefaults__', dict([('x', 1, )])):
+ self.assertEqual(foo(), 1)
+ self.assertEqual(foo(), 0)
+
if __name__ == '__main__':
unittest.main()
diff --git a/mock/tests/testwith.py b/mock/tests/testwith.py
index b9cfab1..aa7812b 100644
--- a/mock/tests/testwith.py
+++ b/mock/tests/testwith.py
@@ -229,6 +229,34 @@ class TestMockOpen(unittest.TestCase):
self.assertEqual(result, ['foo\n', 'bar\n', 'baz'])
+ def test_read_bytes(self):
+ mock = mock_open(read_data=b'\xc6')
+ with patch('%s.open' % __name__, mock, create=True):
+ with open('abc', 'rb') as f:
+ result = f.read()
+ self.assertEqual(result, b'\xc6')
+
+
+ def test_readline_bytes(self):
+ m = mock_open(read_data=b'abc\ndef\nghi\n')
+ with patch('%s.open' % __name__, m, create=True):
+ with open('abc', 'rb') as f:
+ line1 = f.readline()
+ line2 = f.readline()
+ line3 = f.readline()
+ self.assertEqual(line1, b'abc\n')
+ self.assertEqual(line2, b'def\n')
+ self.assertEqual(line3, b'ghi\n')
+
+
+ def test_readlines_bytes(self):
+ m = mock_open(read_data=b'abc\ndef\nghi\n')
+ with patch('%s.open' % __name__, m, create=True):
+ with open('abc', 'rb') as f:
+ result = f.readlines()
+ self.assertEqual(result, [b'abc\n', b'def\n', b'ghi\n'])
+
+
def test_mock_open_read_with_argument(self):
# At one point calling read with an argument was broken
# for mocks returned by mock_open
diff --git a/requirements.txt b/requirements.txt
index 2ec028d..31bbe5d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,6 @@
-funcsigs;python_version<"3.3"
+funcsigs>=1;python_version<"3.3"
# For runtime needs this is correct. For setup_requires needs, 1.2.0 is needed
# but setuptools can't cope with conflicts in setup_requires, so thats
# unversioned.
pbr>=0.11
-six>=1.7
+six>=1.9
diff --git a/setup.py b/setup.py
index 161016b..5f727ae 100755
--- a/setup.py
+++ b/setup.py
@@ -1,18 +1,6 @@
#!/usr/bin/env python
-from distutils.version import StrictVersion
import setuptools
-import sys
-
-
-# Setuptools 17.1 is required, and setup_requires cannot upgrade setuptools
-# in-place, nor trigger the use of a newer version. Abort cleanly up-front.
-setuptools_required = StrictVersion("17.1")
-setuptools_installed = StrictVersion(setuptools.__version__)
-if setuptools_installed < setuptools_required:
- sys.stderr.write(
- "mock requires setuptools>=17.1. Aborting installation\n")
- sys.exit(1)
setuptools.setup(
- setup_requires=['pbr>=1.3'],
+ setup_requires=['pbr>=1.3', 'setuptools>=17.1'],
pbr=True)
diff --git a/tools/pre-applypatch b/tools/pre-applypatch
index 210b285..3198534 100755
--- a/tools/pre-applypatch
+++ b/tools/pre-applypatch
@@ -28,7 +28,6 @@ find . -name "*.pyc" -exec rm "{}" \;
test_version 2.6
test_version 2.7
-test_version 3.2
test_version 3.3
test_version 3.4
test_version 3.5
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-mock.git
More information about the Python-modules-commits
mailing list