title: How do I compare two nested data structures for unittesting?
body: <p>For those who know perl, I'm looking for something similar to <a href="http://search.cpan.org/~rjbs/Test-Deep-0.110/lib/Test/Deep.pm" rel="noreferrer"><code>Test::Deep::is_deeply()</code></a> in Python.</p>
  
  <p>In <a href="http://docs.python.org/release/3.2.3/library/unittest.html" rel="noreferrer">Python's unittest</a> I can conveniently compare nested data structures already, if I expect them to be equal:</p>
  
  <pre><code>self.assertEqual(os.walk('some_path'),
                   my.walk('some_path'),
                   "compare os.walk with my own implementation")
  </code></pre>
  
  <p>However, in the wanted test, the order of files in the respective sublist of the <code>os.walk</code> tuple shall be of no concern.</p>
  
  <p>If it was just this one test it would be ok to code an easy solution. But I envision several tests on differently structured nested data. And I am hoping for a general solution.</p>
  
  <p>I checked Python's own <a href="http://docs.python.org/release/3.2.3/library/unittest.html" rel="noreferrer">unittest documentation</a>, looked at <a href="http://pyunit.sourceforge.net/" rel="noreferrer">pyUnit</a>, and at <a href="https://nose.readthedocs.org/en/latest/plugins/builtin.html" rel="noreferrer">nose and it's plugins</a>. Active maintenance would also be an important aspect for usage.</p>
  
  <p>The ultimate goal for me would be to have a set of descriptive types like <code>UnorderedIterable</code>, <code>SubsetOf</code>, <code>SupersetOf</code>, etc which can be called to describe a nested data structure, and then use that description to compare two actual sets of data.</p>
  
  <p>In the os.walk example I'd like something like:</p>
  
  <pre><code>comparison = OrderedIterable(
                 OrderedIterable(
                   str,
                   UnorderedIterable(),
                   UnorderedIterable()
                 )
               )
  </code></pre>
  
  <p>The above describes the kind of data structure that <code>list(os.walk())</code> would return. For comparison of data <code>A</code> and data <code>B</code> in a unit test, the current path names would be cast into a <code>str()</code>, and the dir and file lists would be compared ignoring the order with:</p>
  
  <pre><code>self.assertDeep(A, B, comparison, msg)
  </code></pre>
  
  <p>Is there anything out there? Or is it such a trivial task that people write their own? I feel comfortable doing it, but I don't want to reinvent, and especially would not want to code the full orthogonal set of types, tests for those, etc. In short, I wouldn't publish it and thus the next one has to rewrite again...</p>