tests_itertools.py 628 B

1234567891011121314151617181920212223242526
  1. """
  2. Tests for `tqdm.contrib.itertools`.
  3. """
  4. import itertools as it
  5. from tqdm.contrib.itertools import product
  6. from .tests_tqdm import StringIO, closing
  7. class NoLenIter(object):
  8. def __init__(self, iterable):
  9. self._it = iterable
  10. def __iter__(self):
  11. for i in self._it:
  12. yield i
  13. def test_product():
  14. """Test contrib.itertools.product"""
  15. with closing(StringIO()) as our_file:
  16. a = range(9)
  17. assert list(product(a, a[::-1], file=our_file)) == list(it.product(a, a[::-1]))
  18. assert list(product(a, NoLenIter(a), file=our_file)) == list(it.product(a, NoLenIter(a)))