<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 10/01/2012 00:23, Alex Gaynor wrote:
<blockquote
cite="mid:CAFRnB2URwnwqaqbqZ00-sBD0AbCgDMEfHdg95uDrtSg6WY1rZg@mail.gmail.com"
type="cite"><br>
<br>
<div class="gmail_quote">On Mon, Jan 9, 2012 at 6:16 PM, Michael
Foord <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:michael@voidspace.org.uk">michael@voidspace.org.uk</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div>
<div class="h5"> On 09/01/2012 22:41, Tom Davis wrote:
<blockquote type="cite">I have a mock that is using
assert_called_with() and mock.ANY thus:<br>
<br>
<div style="margin-left:40px">m = mock.Mock()<br>
do_stuff(m)<br>
m.assert_called_with(now=mock.ANY, foo='bar')<br>
<br>
</div>
Unfortunately, this results in:<br>
<br>
<div style="margin-left:40px">AssertionError: Expected
call: mock(now=<ANY>, foo='bar')<br>
Actual call: mock(now=datetime.datetime(2012, 1, 9,
22, 36, 41, 264838), foo='bar')<br>
</div>
<br>
I could have sworn that ANY used to work perfectly
fine when used in this way. Is this a datetime thing
or...?<br>
<br>
Using mock==dev<br>
</blockquote>
<br>
</div>
</div>
Hmmm... dammit. I see the same thing, but I think I see the
cause of the problem:<br>
<br>
>>> from mock import Mock, ANY<br>
>>> from datetime import datetime<br>
>>> d = datetime.now()<br>
>>> m = Mock()<br>
>>> m(d)<br>
<Mock name='mock()' id='4312271632'><br>
>>> m.assert_called_with(ANY)<br>
Traceback (most recent call last):<br>
...<br>
AssertionError: Expected call: mock(<ANY>)<br>
Actual call: mock(datetime.datetime(2012, 1, 10, 0, 13, 52,
593795))<br>
>>> ANY == d<br>
True<br>
>>> d == ANY<br>
False<br>
<br>
It only happens with certain types:<br>
<br>
>>> m(3)<br>
<Mock name='mock()' id='4312271632'><br>
>>> m.assert_called_with(ANY)<br>
>>><br>
<br>
I'll try and fix this, thanks for the report.<br>
<br>
All the best,<br>
<br>
Michael Foord<br>
<blockquote type="cite"> <br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
testing-in-python mailing list
<a moz-do-not-send="true" href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a>
<a moz-do-not-send="true" href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><span class="HOEnZb"><font color="#888888">
</font></span></pre>
<span class="HOEnZb"><font color="#888888"> </font></span></blockquote>
<span class="HOEnZb"><font color="#888888"> <br>
<br>
<pre cols="72">--
<a moz-do-not-send="true" href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a>
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing <a moz-do-not-send="true" href="http://www.sqlite.org/different.html" target="_blank">http://www.sqlite.org/different.html</a>
</pre>
</font></span></div>
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a moz-do-not-send="true"
href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a moz-do-not-send="true"
href="http://lists.idyll.org/listinfo/testing-in-python"
target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br>
</blockquote>
</div>
<br>
The issue is, timedelta (in it's infinite wisdom), does not return
NotImplemented from __eq__ on non-timedelta values, so ANY.__eq__
isn't invoked.</blockquote>
<br>
Yeah, swapping the order of the comparison in _Call.__eq__ causes
the ANY.__eq__ to be used.<br>
<br>
Michael<br>
<br>
<blockquote
cite="mid:CAFRnB2URwnwqaqbqZ00-sBD0AbCgDMEfHdg95uDrtSg6WY1rZg@mail.gmail.com"
type="cite">
<div><br>
</div>
<div>Alex<br clear="all">
<div><br>
</div>
-- <br>
"I disapprove of what you say, but I will defend to the death
your right to say it." -- Evelyn Beatrice Hall (summarizing
Voltaire)<br>
"The people's good is the highest law." -- Cicero<br>
<br>
</div>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.voidspace.org.uk/">http://www.voidspace.org.uk/</a>
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing <a class="moz-txt-link-freetext" href="http://www.sqlite.org/different.html">http://www.sqlite.org/different.html</a>
</pre>
</body>
</html>