<br><br><div class="gmail_quote">On Mon, Jan 9, 2012 at 6:16 PM, Michael Foord <span dir="ltr">&lt;<a href="mailto:michael@voidspace.org.uk">michael@voidspace.org.uk</a>&gt;</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=&#39;bar&#39;)<br>
        <br>
      </div>
      Unfortunately, this results in:<br>
      <br>
      <div style="margin-left:40px">AssertionError: Expected call:
        mock(now=&lt;ANY&gt;, foo=&#39;bar&#39;)<br>
        Actual call: mock(now=datetime.datetime(2012, 1, 9, 22, 36, 41,
        264838), foo=&#39;bar&#39;)<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>
    &gt;&gt;&gt; from mock import Mock, ANY<br>
    &gt;&gt;&gt; from datetime import datetime<br>
    &gt;&gt;&gt; d = datetime.now()<br>
    &gt;&gt;&gt; m = Mock()<br>
    &gt;&gt;&gt; m(d)<br>
    &lt;Mock name=&#39;mock()&#39; id=&#39;4312271632&#39;&gt;<br>
    &gt;&gt;&gt; m.assert_called_with(ANY)<br>
    Traceback (most recent call last):<br>
     ...<br>
    AssertionError: Expected call: mock(&lt;ANY&gt;)<br>
    Actual call: mock(datetime.datetime(2012, 1, 10, 0, 13, 52, 593795))<br>
    &gt;&gt;&gt; ANY == d<br>
    True<br>
    &gt;&gt;&gt; d == ANY<br>
    False<br>
    <br>
    It only happens with certain types:<br>
    <br>
    &gt;&gt;&gt; m(3)<br>
    &lt;Mock name=&#39;mock()&#39; id=&#39;4312271632&#39;&gt;<br>
    &gt;&gt;&gt; m.assert_called_with(ANY)<br>
    &gt;&gt;&gt;<br>
    <br>
    I&#39;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 href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a>
<a 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 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 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 href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a 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&#39;s infinite wisdom), does not return NotImplemented from __eq__ on non-timedelta values, so ANY.__eq__ isn&#39;t invoked.<div><br></div><div>Alex<br clear="all">
<div><br></div>-- <br>&quot;I disapprove of what you say, but I will defend to the death your right to say it.&quot; -- Evelyn Beatrice Hall (summarizing Voltaire)<br>&quot;The people&#39;s good is the highest law.&quot; -- Cicero<br>
<br>
</div>