コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
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