<s> import sys <EOL> import unittest <EOL> from libcloud . common . types import LazyList <EOL> class TestLazyList ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestLazyList , self ) . setUp <EOL> self . _get_more_counter = <NUM_LIT:0> <EOL> def tearDown ( self ) : <EOL> super ( TestLazyList , self ) . tearDown <EOL> def test_init ( self ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> ll = LazyList ( get_more = self . _get_more_exhausted ) <EOL> ll_list = list ( ll ) <EOL> self . assertEqual ( ll_list , data ) <EOL> def test_iterator ( self ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> ll = LazyList ( get_more = self . _get_more_exhausted ) <EOL> for i , d in enumerate ( ll ) : <EOL> self . assertEqual ( d , data [ i ] ) <EOL> def test_empty_list ( self ) : <EOL> ll = LazyList ( get_more = self . _get_more_empty ) <EOL> self . assertEqual ( list ( ll ) , [ ] ) <EOL> self . assertEqual ( len ( ll ) , <NUM_LIT:0> ) <EOL> self . assertTrue ( <NUM_LIT:10> not in ll ) <EOL> def test_iterator_not_exhausted ( self ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] <EOL> ll = LazyList ( get_more = self . _get_more_not_exhausted ) <EOL> number_of_iterations = <NUM_LIT:0> <EOL> for i , d in enumerate ( ll ) : <EOL> self . assertEqual ( d , data [ i ] ) <EOL> number_of_iterations += <NUM_LIT:1> <EOL> self . assertEqual ( number_of_iterations , <NUM_LIT:10> ) <EOL> def test_len ( self ) : <EOL> ll = LazyList ( get_more = self . _get_more_not_exhausted ) <EOL> ll = LazyList ( get_more = self . _get_more_not_exhausted ) <EOL> self . assertEqual ( len ( ll ) , <NUM_LIT:10> ) <EOL> def test_contains ( self ) : <EOL> ll = LazyList ( get_more = self . _get_more_not_exhausted ) <EOL> self . assertTrue ( <NUM_LIT> not in ll ) <EOL> self . assertTrue ( <NUM_LIT:1> in ll ) <EOL> self . assertTrue ( <NUM_LIT:5> in ll ) <EOL> self . assertTrue ( <NUM_LIT:10> in ll ) <EOL> def test_indexing ( self ) : <EOL> ll = LazyList ( get_more = self . _get_more_not_exhausted ) <EOL> self . assertEqual ( ll [ <NUM_LIT:0> ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( ll [ <NUM_LIT:9> ] , <NUM_LIT:10> ) <EOL> self . assertEqual ( ll [ - <NUM_LIT:1> ] , <NUM_LIT:10> ) <EOL> try : <EOL> ll [ <NUM_LIT:11> ] <EOL> except IndexError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_repr ( self ) : <EOL> ll1 = LazyList ( get_more = self . _get_more_empty ) <EOL> ll2 = LazyList ( get_more = self . _get_more_exhausted ) <EOL> ll3 = LazyList ( get_more = self . _get_more_not_exhausted ) <EOL> self . assertEqual ( repr ( ll1 ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( ll2 ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( ll3 ) , '<STR_LIT>' ) <EOL> def _get_more_empty ( self , last_key , value_dict ) : <EOL> return [ ] , None , True <EOL> def _get_more_exhausted ( self , last_key , value_dict ) : <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> return data , <NUM_LIT:5> , True <EOL> def _get_more_not_exhausted ( self , last_key , value_dict ) : <EOL> self . _get_more_counter += <NUM_LIT:1> <EOL> if not last_key : <EOL> data , last_key , exhausted = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <NUM_LIT:5> , False <EOL> else : <EOL> data , last_key , exhausted = [ <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] , <NUM_LIT:10> , True <EOL> return data , last_key , exhausted <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( unittest . main ( ) ) </s>
