def compare_generic_iter(make_it, match):
 it = make_it()
 n = 0
 for item in match:
  if (not (it[n] == item)):
   raise AssertionError
  n += 1
 try:
  it[n]
 except IndexError:
  pass
 else:
  raise AssertionError('Too many items from __getitem__', it)
 try:
  (iter, StopIteration)
 except NameError:
  pass
 else:
  it = make_it()
  if (not (iter(it) is it)):
   raise AssertionError
  for item in match:
   if (not (it.next() == item)):
    raise AssertionError
  try:
   it.next()
  except StopIteration:
   pass
  else:
   raise AssertionError('Too many items from .next()', it)

def compare_generic_iter ( make_it , match ) : it = make_it ( ) n = 0 for item in match : if ( not ( it [ n ] == item ) ) : raise AssertionError n += 1 try : it [ n ] except IndexError : pass else : raise AssertionError ( 'Too many items from __getitem__' , it ) try : ( iter , StopIteration ) except NameError : pass else : it = make_it ( ) if ( not ( iter ( it ) is it ) ) : raise AssertionError for item in match : if ( not ( it . next ( ) == item ) ) : raise AssertionError try : it . next ( ) except StopIteration : pass else : raise AssertionError ( 'Too many items from .next()' , it )
utility to compare a generic 2 .