title: How can I assert calls that accept sequence arguments with Python Mock?
body: <p>I am processing a sequence of user-defined objects. It looks similar to the following:</p>
  
  <pre><code>class Thing(object):
      def __init__(self, x, y):
          self.x = x
          self.y = y
  </code></pre>
  
  <p>The method I am currently testing has functionality similar to the following:</p>
  
  <pre><code>def my_function(things):
      x_calc = calculate_something(t.x for t in things)
      y_calc = calculate_something(t.y for t in things)
      return x_calc / y_calc
  </code></pre>
  
  <p>The problem I am facing is testing the calls to <code>calculate_something</code>. I want to assert that these calls happened, something like so:</p>
  
  <pre><code>calculateSomethingMock.assert_any_call(the_sequence)
  </code></pre>
  
  <p>I don't care about the order of the sequence passed into <code>calculate_something</code>, but I do care that the elements are all present. I could wrap the generator function in a call to <code>set</code>, but I don't feel like my test should be dictating what type of sequence is passed into <code>calculate_something</code>. I should be able to pass it any kind of sequence. I could alternatively create a method that generates the sequence instead of using generator syntax and mock that method, but that seems like overkill.</p>
  
  <p>How can I best structure this assertion, or is my trouble testing here an indication of poorly structured code?</p>
  
  <p>I am using Python 2.7.3 with Mock 1.0.1.</p>
  
  <p>(For anyone who feels compelled to comment on it, I'm aware I'm doing test last and that this isn't considered the greatest practice.)</p>
  
  <p>Edit:</p>
  
  <p>After watch <a href="https://www.youtube.com/watch?v=R9FOchgTtLM" rel="nofollow">this marvelous talk entitled "Why You Don't Get Mock Objects by Gregory Moeck"</a>, I have reconsidered whether I should even be mocking the <code>calculate_something</code> method.</p>