@@ -2080,6 +2080,16 @@ def test_list(self):
20802080 a .append ('hello' )
20812081 self .assertEqual (f [0 ][:], [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 'hello' ])
20822082
2083+ def test_list_iter (self ):
2084+ a = self .list (list (range (10 )))
2085+ it = iter (a )
2086+ self .assertEqual (list (it ), list (range (10 )))
2087+ self .assertEqual (list (it ), []) # exhausted
2088+ # list modified during iteration
2089+ it = iter (a )
2090+ a [0 ] = 100
2091+ self .assertEqual (next (it ), 100 )
2092+
20832093 def test_list_proxy_in_list (self ):
20842094 a = self .list ([self .list (range (3 )) for _i in range (3 )])
20852095 self .assertEqual ([inner [:] for inner in a ], [[0 , 1 , 2 ]] * 3 )
@@ -2110,6 +2120,19 @@ def test_dict(self):
21102120 self .assertEqual (sorted (d .values ()), [chr (i ) for i in indices ])
21112121 self .assertEqual (sorted (d .items ()), [(i , chr (i )) for i in indices ])
21122122
2123+ def test_dict_iter (self ):
2124+ d = self .dict ()
2125+ indices = list (range (65 , 70 ))
2126+ for i in indices :
2127+ d [i ] = chr (i )
2128+ it = iter (d )
2129+ self .assertEqual (list (it ), indices )
2130+ self .assertEqual (list (it ), []) # exhausted
2131+ # dictionary changed size during iteration
2132+ it = iter (d )
2133+ d .clear ()
2134+ self .assertRaises (RuntimeError , next , it )
2135+
21132136 def test_dict_proxy_nested (self ):
21142137 pets = self .dict (ferrets = 2 , hamsters = 4 )
21152138 supplies = self .dict (water = 10 , feed = 3 )
0 commit comments