@@ -1813,6 +1813,16 @@ def test_list(self):
18131813 a .append ('hello' )
18141814 self .assertEqual (f [0 ][:], [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 'hello' ])
18151815
1816+ def test_list_iter (self ):
1817+ a = self .list (list (range (10 )))
1818+ it = iter (a )
1819+ self .assertEqual (list (it ), list (range (10 )))
1820+ self .assertEqual (list (it ), []) # exhausted
1821+ # list modified during iteration
1822+ it = iter (a )
1823+ a [0 ] = 100
1824+ self .assertEqual (next (it ), 100 )
1825+
18161826 def test_list_proxy_in_list (self ):
18171827 a = self .list ([self .list (range (3 )) for _i in range (3 )])
18181828 self .assertEqual ([inner [:] for inner in a ], [[0 , 1 , 2 ]] * 3 )
@@ -1843,6 +1853,19 @@ def test_dict(self):
18431853 self .assertEqual (sorted (d .values ()), [chr (i ) for i in indices ])
18441854 self .assertEqual (sorted (d .items ()), [(i , chr (i )) for i in indices ])
18451855
1856+ def test_dict_iter (self ):
1857+ d = self .dict ()
1858+ indices = list (range (65 , 70 ))
1859+ for i in indices :
1860+ d [i ] = chr (i )
1861+ it = iter (d )
1862+ self .assertEqual (list (it ), indices )
1863+ self .assertEqual (list (it ), []) # exhausted
1864+ # dictionary changed size during iteration
1865+ it = iter (d )
1866+ d .clear ()
1867+ self .assertRaises (RuntimeError , next , it )
1868+
18461869 def test_dict_proxy_nested (self ):
18471870 pets = self .dict (ferrets = 2 , hamsters = 4 )
18481871 supplies = self .dict (water = 10 , feed = 3 )
0 commit comments