title: How to mock pysvn
body: <p>I am working on a Python module that suppose to checkout some code from SVN and build it. After much refactoring of some legacy code, I got a fairly decent coverage of the code, however, I have a gaping hole in the code that uses <a href="http://pysvn.tigris.org/docs/pysvn_prog_guide.html" rel="nofollow noreferrer">pysvn</a>.</p>
  
  <p>Admittedly the concept of Mock object is new to me, but after reading some of the documentation of <a href="http://pypi.python.org/pypi/MiniMock" rel="nofollow noreferrer">MiniMock</a> and <a href="http://code.google.com/p/pymox/" rel="nofollow noreferrer">pymox</a> (both are available in my environment), I came to the conclusion that I will need to capture some pysvn output and have it returned in my test code.</p>
  
  <p>But here I find myself (pardon the pun) in a pickle. The objects returned from the pysvn.Client() commands do not behave nicely when I try to pickle them, or even to compare them.</p>
  
  <p>Any suggestion of how to serialize or otherwise mock pysvn or some other non-pythonic behaving objects?</p>
  
  <p>Naturally, I am willing to accept that I am approaching this problem from the wrong direction, or that I am simply an idiot. In that case any advice will be helpful.</p>
  
  <p><strong>Additional information 0:</strong></p>
  
  <p>Some <code>pysvn</code> object can be reduced to a <code>dict</code> by accessing their <code>data</code> property, and can be reproduced by passing this <code>dict</code> into the appropriate <code>__init__()</code> </p>
  
  <p>For example:</p>
  
  <pre><code>&gt;&gt;&gt; svn=pysvn.Client()
  &gt;&gt;&gt; svn.list('http://svn/svn/')[0][0]
  &lt;PysvnList u'http://svn/svn'&gt;
  &gt;&gt;&gt; d=svn.list('http://svn/svn/')[0][0].data
  &gt;&gt;&gt; pysvn.PysvnList(d)
  &lt;PysvnList u'http://svn/svn'&gt;
  </code></pre>
  
  <p>However inside this object there might be some unpicklable objects:</p>
  
  <pre><code>&gt;&gt;&gt; cPickle.dumps(d)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in ?
  cPickle.UnpickleableError: Cannot pickle &lt;type 'node_kind'&gt; objects
  </code></pre>
  
  <p><strong>Additional Information 1:</strong></p>
  
  <p>As for <a href="https://stackoverflow.com/users/639295/h-dunlop">@H. Dunlop</a> request, here is a (simplified) snippet of my code,
  It allow to get a list out of SVN, and let the user choose an item from that list:</p>
  
  <pre><code>class Menu(object):
      """a well covered class"""
      # ...
  
  class VersionControl(object):
      """A poorly covered class"""
  
      def __init__(self):
          self.svn = pysvn.Client()
  
      # ...
  
      def list(self, url):
          """svn ls $url"""
          return [os.path.basename(x['path']) for (x,_) in self.svn.list(url)[1:]]
  
      def choose(self, choice, url):
          """Displays a menu from svn list, and get's the users choice form it.
  
          Returns the svn item (path).
          """
          menu = Menu(prompt="Please choose %s from list:\n" % choice,
                      items=self.list(url),
                      muliple_choice=False)
          menu.present()
          return menu.chosen()
  </code></pre>