def test(): '''Test the basic workings of `iter_with`.''' active_context_manager = MyContextManager() inactive_context_manager = MyContextManager() iterator = iter_with(xrange(5), active_context_manager) for i, j in itertools.izip(iterator, xrange(5)): assert i == j == active_context_manager.counter assert active_context_manager.active is False assert inactive_context_manager.counter == -1 assert inactive_context_manager.active is False
def test(): '''Test the basic workings of `iter_with`.''' active_context_manager = MyContextManager() inactive_context_manager = MyContextManager() iterator = iter_with(range(5), active_context_manager) for i, j in zip(iterator, range(5)): assert i == j == active_context_manager.counter assert active_context_manager.active is False assert inactive_context_manager.counter == -1 assert inactive_context_manager.active is False
def test_lazy_tuple(): active_context_manager = MyContextManager() inactive_context_manager = MyContextManager() lazy_tuple = iter_with(range(5), active_context_manager, lazy_tuple=True) assert isinstance(lazy_tuple, nifty_collections.LazyTuple) assert not lazy_tuple.collected_data for i, j in itertools.izip(lazy_tuple, range(5)): assert i == j == active_context_manager.counter assert active_context_manager.active is False assert inactive_context_manager.counter == -1 assert inactive_context_manager.active is False assert lazy_tuple[2] == 2
def test_lazy_tuple(): active_context_manager = MyContextManager() inactive_context_manager = MyContextManager() lazy_tuple = iter_with(range(5), active_context_manager, lazy_tuple=True) assert isinstance(lazy_tuple, nifty_collections.LazyTuple) assert not lazy_tuple.collected_data for i, j in zip(lazy_tuple, range(5)): assert i == j == active_context_manager.counter assert active_context_manager.active is False assert inactive_context_manager.counter == -1 assert inactive_context_manager.active is False assert lazy_tuple[2] == 2