diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-01-10 00:22:44 +0000 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-01-10 00:22:44 +0000 |
commit | d311f604c97c49253ec316fe206af8da2ca95d4d (patch) | |
tree | 0b9608d50466c7223573a044edff2b1a0712846c | |
parent | bb4646c35f1fda5bba00af04e18bef57a7c884fa (diff) | |
download | mock-d311f604c97c49253ec316fe206af8da2ca95d4d.tar.gz |
Fix ANY equality with some types in assert_called_with calls
-rw-r--r-- | docs/changelog.txt | 1 | ||||
-rw-r--r-- | docs/index.txt | 4 | ||||
-rw-r--r-- | mock.py | 7 | ||||
-rw-r--r-- | tests/testhelpers.py | 9 |
4 files changed, 18 insertions, 3 deletions
diff --git a/docs/changelog.txt b/docs/changelog.txt index 72a71a0..b4f2ac1 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -171,6 +171,7 @@ mock 0.8.0 is the last version that will support Python 2.4. * Removed the `configure` keyword argument to `create_autospec` and allow arbitrary keyword arguments (for the `Mock` constructor) instead +* Fixed `ANY` equality with some types in `assert_called_with` calls * Switched to a standard Sphinx theme (compatible with `readthedocs.org <http://mock.readthedocs.org>`_) diff --git a/docs/index.txt b/docs/index.txt index 005b79c..3a9c791 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -360,8 +360,8 @@ Documentation for older versions of mock: * `mock 0.7 <http://www.voidspace.org.uk/python/mock/0.7/>`_ * `mock 0.6 <http://www.voidspace.org.uk/python/mock/0.6.0/>`_ -Docs from the in-development version of `mock` can be found on -`readthedocs.org <http://mock.readthedocs.org>`_. +Docs from the in-development version of `mock` can be found at +`mock.readthedocs.org <http://mock.readthedocs.org>`_. Terminology @@ -1883,6 +1883,9 @@ class _ANY(object): def __eq__(self, other): return True + def __ne__(self, other): + return False + def __repr__(self): return '<ANY>' @@ -2010,7 +2013,9 @@ class _Call(tuple): if self_name and other_name != self_name: return False - return (self_args, self_kwargs) == (other_args, other_kwargs) + + # this order is important for ANY to work! + return (other_args, other_kwargs) == (self_args, self_kwargs) def __ne__(self, other): diff --git a/tests/testhelpers.py b/tests/testhelpers.py index 345d648..51f8d13 100644 --- a/tests/testhelpers.py +++ b/tests/testhelpers.py @@ -10,6 +10,8 @@ from mock import ( mocksignature ) +from datetime import datetime + class SomeClass(object): def one(self, a, b): pass @@ -38,6 +40,13 @@ class AnyTest(unittest2.TestCase): self.assertEqual(str(ANY), '<ANY>') + def test_any_and_datetime(self): + mock = Mock() + mock(datetime.now(), foo=datetime.now()) + + mock.assert_called_with(ANY, foo=ANY) + + class CallTest(unittest2.TestCase): |