<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Anyone was using pmock for unit testing with python?  I met a problem
> and hope someone to help me.  For short, the pmock seems can not mock a
> iterator object.

Why bother?

def mockit(): raise StopIteration

now pass mockit()

> For example, the tested object is foo, who need to send message to
> another object bar.  So, to test the foo, I need mock a mockBar.  But
> the bar is a iterator, the foo use the bar in this way:
>
>     foo.method(self, bar):
>         for n in bar:
>             do somthing
>              ...

To properly test the method, *also* feed it an iterator that yields a few 
objects of the appropriate type.  Assuming n is to be an int...

def intit(k):
  for i in range(k): yield i

Terry J. Reedy





-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to