Testing for empty iterators?

Roy Smith roy at panix.com
Sun Jul 4 01:42:15 CEST 2004


"Paul McGuire" <ptmcg at austin.stopthespam_rr.com> wrote:
> Suppose your iterator, through some bug in your code, pointed to a list of
> 100,000 database records, instead of an empty list as you expected.  Making
> a list from this iterator could be very time-consuming, when all you really
> needed to know was that the iterator pointed to at least one element.

I see your point, but this is a unit test.  Even more so than normally, 
in a unit test I think clarity of code is more important that 
efficiency.  And in this case, it's only inefficient if it fails the 
test, which should never happen :-)



More information about the Python-list mailing list