<div dir="ltr"><div style>Hi, Julian,</div><div style><br></div><div style>Thanks for your comments...</div><div><br></div>On Mon, Apr 15, 2013 at 10:35 AM, Julian Berman <span dir="ltr">&lt;<a href="mailto:julian@grayvines.com" target="_blank" class="cremed">julian@grayvines.com</a>&gt;</span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="">
<div class="h5"><p dir="ltr">On Apr 15, 2013 1:11 PM, &quot;Chris Conway&quot; &lt;<a href="mailto:clconway@google.com" target="_blank" class="cremed">clconway@google.com</a>&gt; wrote:<br>
&gt;<br>
&gt; I&#39;ve recently started using the mock library in my code (transitioning from Mox) and I really like it a lot. There&#39;s a few little utilities I&#39;ve written for myself and I wonder if you&#39;d accept them as patches.<br>


&gt;<br>
&gt; First, I find that I strongly prefer to use autospecced instances for most of my mocks. To make that simpler, I wrote a create_strictspec() function as a wrapper around create_autospec() with instance=True.<br>
&gt;<br>
&gt; I also find that I frequently want a mock function that should never be called (e.g., in a test where I&#39;m patching open() and testing a code path where no file is opened). This can be asserted ex post by checking call_count, but then you don&#39;t get any information about where the call occurred. Alternatively, you can use a NoncallableMock, but then you get a fairly opaque error: &quot;TypeError: &#39;NonCallableMock&#39; object is not callable&quot;. I find it preferable to use a utility method expect_never_called() to set an AssertionError side effect on the mock.</p>


</div></div><p dir="ltr">I find this error message to be pretty transparent honestly.</p></blockquote><div style>I&#39;d prefer something like: &quot;AssertionError: Unexpected call: mock_fn(actual_arg)&quot;. I guess it would be pretty easy to get something like this without adding a new method by just implementing __call__ on NonCallableMock to raise an exception. </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<p dir="ltr">Hypothetically though, Mock&#39;s assertions are all state based and done after exercising, so starting to add preconfigured expectations would seem out of place to me. I personally wouldn&#39;t mind terribly much if you wanted to change the error message to say something more mock-specific, but nothing comes to me at the moment that would beat the current message.</p>
</blockquote><div style>I&#39;m very glad to be freed of the tyranny of setting required expectations in Mox. :-) But I think in cases like this an ex ante expectation is more natural than an ex post assertion.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<p dir="ltr">I don&#39;t have a meaningful opinion on the first thing since unfortunately I don&#39;t use tightly spec&#39;ed mocks as much as I should, mostly out of laziness :/. But it&#39;d have to be fairly common to deserve a separate function for a single parameter.</p>
</blockquote><div style>I agree it seems a bit much to have a wrapper just for one parameter. But... it&#39;s an optional parameter, which makes it easy to forget and I like the protection of having a simple alias for the call.</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<p dir="ltr">(Would love to hear more things you come up with coming from Mox certainly, there was someone else in the IRC channel who was discussing it [maybe that was you?])</p></blockquote><div style>Nope, wasn&#39;t me.</div>
<div style><br></div><div> <span style="color:rgb(80,0,80)">&gt; Do you think these would be helpful additions to the library?</span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
&gt;<br>
&gt; Best regards,<br>
&gt; Chris<br>
&gt;<br></div>
&gt; _______________________________________________<br>
&gt; testing-in-python mailing list<br>
&gt; <a href="mailto:testing-in-python@lists.idyll.org" target="_blank" class="cremed">testing-in-python@lists.idyll.org</a><br>
&gt; <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank" class="cremed">http://lists.idyll.org/listinfo/testing-in-python</a><br>
&gt;<br>
<p></p>
</blockquote></div><br></div></div>