Skip to content

Commit 0ad083a

Browse files
committed
-
1 parent c2fb19f commit 0ad083a

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

source_py3/test_python_toolbox/test_cute_iter_tools/test_iter_with.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import itertools
77

8+
from python_toolbox import nifty_collections
89
from python_toolbox import context_management
910

1011
from python_toolbox.cute_iter_tools import iter_with
@@ -37,4 +38,20 @@ def test():
3738
assert inactive_context_manager.counter == -1
3839
assert inactive_context_manager.active is False
3940

40-
41+
42+
def test_lazy_tuple():
43+
44+
active_context_manager = MyContextManager()
45+
inactive_context_manager = MyContextManager()
46+
47+
lazy_tuple = iter_with(range(5), active_context_manager, lazy_tuple=True)
48+
assert isinstance(lazy_tuple, nifty_collections.LazyTuple)
49+
assert not lazy_tuple.collected_data
50+
51+
for i, j in zip(lazy_tuple, range(5)):
52+
assert i == j == active_context_manager.counter
53+
assert active_context_manager.active is False
54+
assert inactive_context_manager.counter == -1
55+
assert inactive_context_manager.active is False
56+
57+
assert lazy_tuple[2] == 2

source_py3/test_python_toolbox/test_cute_iter_tools/test_iterate_overlapping_subsequences.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'''Testing module for `cute_iter_tools.iterate_overlapping_subsequences`.'''
55

66
from python_toolbox import gc_tools
7+
from python_toolbox import nifty_collections
78
from python_toolbox import cute_testing
89
from python_toolbox import sequence_tools
910

@@ -53,6 +54,17 @@ def test_various_lengths():
5354
(6, 0, 1, 2, 3))
5455

5556

57+
def test_lazy_tuple():
58+
lazy_tuple = \
59+
iterate_overlapping_subsequences(range(7), length=3, lazy_tuple=True)
60+
assert isinstance(lazy_tuple, nifty_collections.LazyTuple)
61+
assert not lazy_tuple.collected_data
62+
63+
assert lazy_tuple == \
64+
((0, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6))
65+
66+
67+
5668
def test_garbage_collection():
5769

5870
garbage_collected = set()

0 commit comments

Comments
 (0)