tqdm/tests/tests_itertools.py

29 lines
664 B
Python
Raw Normal View History

2020-01-19 16:47:11 +00:00
"""
Tests for `tqdm.contrib.itertools`.
"""
import itertools
from tqdm.contrib.itertools import product
2021-01-09 17:00:18 +00:00
from .tests_tqdm import StringIO, closing
2020-01-19 16:47:11 +00:00
2020-01-19 18:10:41 +00:00
class NoLenIter(object):
def __init__(self, iterable):
self._it = iterable
def __iter__(self):
for i in self._it:
yield i
2020-10-24 18:36:45 +00:00
def test_product():
"""Test contrib.itertools.product"""
with closing(StringIO()) as our_file:
a = range(9)
assert list(product(a, a[::-1], file=our_file)) == \
list(itertools.product(a, a[::-1]))
2020-01-19 18:10:41 +00:00
2020-10-24 18:36:45 +00:00
assert list(product(a, NoLenIter(a), file=our_file)) == \
list(itertools.product(a, NoLenIter(a)))