-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_bounded_iterator.py
43 lines (28 loc) · 1.08 KB
/
test_bounded_iterator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import time
import unittest
from itertools import count
from bounded_iterator import BoundedIterator
def _identity(item):
return item
def _sleep(secs):
time.sleep(secs)
return secs
class BoundedIteratorTest(unittest.TestCase):
def test_when_the_iterable_is_empty_then_it_produces_no_results(self):
subject = BoundedIterator(10, it=())
res = list(subject)
self.assertEqual([], res)
def test_when_the_max_number_of_items_were_yielded_then_it_will_not_yield_more(self):
subject = BoundedIterator(2, count())
chunk0 = next(subject), next(subject)
self.assertEqual((0, 1), chunk0)
with self.assertRaises(TimeoutError):
subject.next(timeout=0.01)
def test_when_a_value_is_acknowledged_then_it_will_yield_one_more(self):
subject = BoundedIterator(2, count())
chunk0 = next(subject), next(subject)
self.assertEqual((0, 1), chunk0)
with self.assertRaises(TimeoutError):
subject.next(timeout=0.01)
subject.processed()
self.assertEqual(2, next(subject))