2020-01-19 16:47:11 +00:00
|
|
|
"""
|
|
|
|
Tests for `tqdm.contrib.itertools`.
|
|
|
|
"""
|
|
|
|
import itertools
|
|
|
|
|
2020-10-24 20:56:26 +00:00
|
|
|
from tqdm.contrib.itertools import product
|
|
|
|
from .tests_tqdm import pretest_posttest # NOQA
|
|
|
|
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)))
|