<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Python Is Mocking Me: A Ruby Programmer&#8217;s Adventures With Python/Mox</title>
	<atom:link href="http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/</link>
	<description></description>
	<lastBuildDate>Mon, 16 Aug 2010 19:53:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Brain Matters &#187; Blog Archive &#187; Mocking HTTP request and response with Python and Mox</title>
		<link>http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/comment-page-1/#comment-376</link>
		<dc:creator>Brain Matters &#187; Blog Archive &#187; Mocking HTTP request and response with Python and Mox</dc:creator>
		<pubDate>Thu, 01 Oct 2009 13:55:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.agoragames.com/?p=201#comment-376</guid>
		<description>[...] Tim, has written an excellent post on his adventures as a Ruby programmer getting up to speed on testing and mocking in Python using Mox. You should read [...]</description>
		<content:encoded><![CDATA[<p>[...] Tim, has written an excellent post on his adventures as a Ruby programmer getting up to speed on testing and mocking in Python using Mox. You should read [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Agora Games</title>
		<link>http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/comment-page-1/#comment-235</link>
		<dc:creator>Agora Games</dc:creator>
		<pubDate>Thu, 28 May 2009 12:27:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.agoragames.com/?p=201#comment-235</guid>
		<description>Finally went back and cleaned up the formatting a bit.  Also, a much more elegant way to mock local object construction was shown to me recently.  It&#039;s described in &lt;a href=&quot;http://groups.google.com/group/mox-discuss/browse_thread/thread/89b7629eaa2155d8#86a3bb8ae4fdf3e1&quot; rel=&quot;nofollow&quot;&gt;this post&lt;/a&gt; in the mox google group.

The summary is that we should just be using:
m.StubOutWithMock(my_module, &quot;MyClass&quot;, use_mock_anything = True)

Since classes, modules, etc, can be reassigned just as easily as methods we can easily substitute a MockAnything instance for our class.  Much nicer!  The trick is actually in the use_mock_anything keyword arg (which doesn&#039;t seem to be documented anywhere!).  This causes mox to replace the class with a MockAnything instance whereas normally it would replace it with a (non-callable) MockObject.

I believe this also solves the old-style class problem that was discussed previously (although I haven&#039;t tried).</description>
		<content:encoded><![CDATA[<p>Finally went back and cleaned up the formatting a bit.  Also, a much more elegant way to mock local object construction was shown to me recently.  It&#8217;s described in <a href="http://groups.google.com/group/mox-discuss/browse_thread/thread/89b7629eaa2155d8#86a3bb8ae4fdf3e1" rel="nofollow">this post</a> in the mox google group.</p>
<p>The summary is that we should just be using:<br />
m.StubOutWithMock(my_module, &#8220;MyClass&#8221;, use_mock_anything = True)</p>
<p>Since classes, modules, etc, can be reassigned just as easily as methods we can easily substitute a MockAnything instance for our class.  Much nicer!  The trick is actually in the use_mock_anything keyword arg (which doesn&#8217;t seem to be documented anywhere!).  This causes mox to replace the class with a MockAnything instance whereas normally it would replace it with a (non-callable) MockObject.</p>
<p>I believe this also solves the old-style class problem that was discussed previously (although I haven&#8217;t tried).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vitaly</title>
		<link>http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/comment-page-1/#comment-165</link>
		<dc:creator>Vitaly</dc:creator>
		<pubDate>Fri, 20 Mar 2009 04:47:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.agoragames.com/?p=201#comment-165</guid>
		<description>Hey thanks for the article it was very helpful. Just a note that the code formating is broken and all the code is left justified so it makes the code kinda hard to read.</description>
		<content:encoded><![CDATA[<p>Hey thanks for the article it was very helpful. Just a note that the code formating is broken and all the code is left justified so it makes the code kinda hard to read.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/comment-page-1/#comment-104</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Fri, 06 Mar 2009 14:46:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.agoragames.com/?p=201#comment-104</guid>
		<description>Hey K,
  I noticed this problem the other day too.  It&#039;s basically an issue with new-style vs. old-style classes.  Old-style classes don&#039;t use the same __new__ -&gt; __init__ step that new-style classes do.  In my case the class I was trying to mock was in my code so I just changed it to inherit from object and make it a new-style class.

  Unfortunately, you don&#039;t really have that option with HTTPConnection.  One thing you might try is creating a wrapper for HTTPConnection so you can treat it like a new-style class.

class MyHTTPConnection(httplib.HTTPConnection, object): pass

Then you can mock __new__ on MyHTTPConnection instead.

Admittedly the solution isn&#039;t ideal but, in my quick test, it did seem to work.  I need to do a bit more reading on old-style classes and I&#039;ll get back to you if I find a better (more direct) solution.</description>
		<content:encoded><![CDATA[<p>Hey K,<br />
  I noticed this problem the other day too.  It&#8217;s basically an issue with new-style vs. old-style classes.  Old-style classes don&#8217;t use the same __new__ -&gt; __init__ step that new-style classes do.  In my case the class I was trying to mock was in my code so I just changed it to inherit from object and make it a new-style class.</p>
<p>  Unfortunately, you don&#8217;t really have that option with HTTPConnection.  One thing you might try is creating a wrapper for HTTPConnection so you can treat it like a new-style class.</p>
<p>class MyHTTPConnection(httplib.HTTPConnection, object): pass</p>
<p>Then you can mock __new__ on MyHTTPConnection instead.</p>
<p>Admittedly the solution isn&#8217;t ideal but, in my quick test, it did seem to work.  I need to do a bit more reading on old-style classes and I&#8217;ll get back to you if I find a better (more direct) solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: K. Adam Christensen</title>
		<link>http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/comment-page-1/#comment-92</link>
		<dc:creator>K. Adam Christensen</dc:creator>
		<pubDate>Thu, 05 Mar 2009 05:27:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.agoragames.com/?p=201#comment-92</guid>
		<description>Hi.

I am trying to mock out httplib.HTTPConnection, however when I try self.mox.StubOutWithMock(httplib.HTTPConnection, &quot;__new__&quot;), I get an AttributeError: class HTTPConnection has no attribute &#039;__new__&#039;.

Would you happen to have any ideas?  Perhaps a work around?</description>
		<content:encoded><![CDATA[<p>Hi.</p>
<p>I am trying to mock out httplib.HTTPConnection, however when I try self.mox.StubOutWithMock(httplib.HTTPConnection, &#8220;__new__&#8221;), I get an AttributeError: class HTTPConnection has no attribute &#8216;__new__&#8217;.</p>
<p>Would you happen to have any ideas?  Perhaps a work around?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: K. Adam Christensen</title>
		<link>http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/comment-page-1/#comment-85</link>
		<dc:creator>K. Adam Christensen</dc:creator>
		<pubDate>Wed, 04 Mar 2009 04:26:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.agoragames.com/?p=201#comment-85</guid>
		<description>Thank you so much for this article.  This is exactly what I need!  Cheers!</description>
		<content:encoded><![CDATA[<p>Thank you so much for this article.  This is exactly what I need!  Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://blog.agoragames.com/2009/02/23/python-is-mocking-me-a-ruby-programmers-adventures-with-pythonmox/comment-page-1/#comment-59</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Wed, 25 Feb 2009 13:35:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.agoragames.com/?p=201#comment-59</guid>
		<description>A couple of other misc items:

* There&#039;s no way to mock statements (as far as I know).  This means you can&#039;t mock things like print and exec.

* I&#039;ve yet to try mocking private methods (double underscore) but I think it&#039;s possible as nothing is truly private in Python.  There&#039;s a discussion here (http://stackoverflow.com/questions/70528/why-are-pythons-private-methods-not-actually-private) of how private methods can be accessed.  I&#039;d imagine the same rules apply to mocking.  That being said, for clarity, I&#039;d recommend using private by convention (single underscore) except in special cases.</description>
		<content:encoded><![CDATA[<p>A couple of other misc items:</p>
<p>* There&#8217;s no way to mock statements (as far as I know).  This means you can&#8217;t mock things like print and exec.</p>
<p>* I&#8217;ve yet to try mocking private methods (double underscore) but I think it&#8217;s possible as nothing is truly private in Python.  There&#8217;s a discussion here (<a href="http://stackoverflow.com/questions/70528/why-are-pythons-private-methods-not-actually-private" rel="nofollow">http://stackoverflow.com/questions/70528/why-are-pythons-private-methods-not-actually-private</a>) of how private methods can be accessed.  I&#8217;d imagine the same rules apply to mocking.  That being said, for clarity, I&#8217;d recommend using private by convention (single underscore) except in special cases.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->