@@ -71,21 +71,30 @@ def test_map(self):
7171
7272 @warnings_helper .ignore_fork_in_thread_deprecation_warnings ()
7373 def test_map_exception (self ):
74- i = self .executor .map (divmod , [1 , 1 , 1 , 1 ], [2 , 3 , 0 , 5 ])
75- self .assertEqual (i .__next__ (), (0 , 1 ))
76- self .assertEqual (i .__next__ (), (0 , 1 ))
77- with self .assertRaises (ZeroDivisionError ):
78- i .__next__ ()
74+ i = self .executor .map (divmod , [5 , 5 , 5 , 5 ], [2 , 3 , 0 , 5 ])
75+ self .assertEqual (next (i ), (2 , 1 ))
76+ self .assertEqual (next (i ), (1 , 2 ))
77+ self .assertRaises (ZeroDivisionError , next , i )
78+ self .assertEqual (next (i ), (1 , 0 ))
79+ self .assertRaises (StopIteration , next , i )
80+ self .assertRaises (StopIteration , next , i )
81+
82+ i = self .executor .map (divmod , [5 , 5 , 5 , 5 ], [2 , 0 , 3 , 5 ], chunksize = 3 )
83+ self .assertEqual (next (i ), (2 , 1 ))
84+ self .assertRaises (ZeroDivisionError , next , i )
85+ self .assertEqual (next (i ), (1 , 2 ))
86+ self .assertEqual (next (i ), (1 , 0 ))
87+ self .assertRaises (StopIteration , next , i )
88+ self .assertRaises (StopIteration , next , i )
7989
8090 @warnings_helper .ignore_fork_in_thread_deprecation_warnings ()
8191 @support .requires_resource ('walltime' )
8292 def test_map_timeout (self ):
8393 results = []
94+ i = self .executor .map (time .sleep , [0 , 0 , 6 ], timeout = 5 )
8495 try :
85- for i in self .executor .map (time .sleep ,
86- [0 , 0 , 6 ],
87- timeout = 5 ):
88- results .append (i )
96+ for result in i :
97+ results .append (result )
8998 except futures .TimeoutError :
9099 pass
91100 else :
@@ -95,6 +104,24 @@ def test_map_timeout(self):
95104 # take longer than the specified timeout.
96105 self .assertIn (results , ([None , None ], [None ], []))
97106
107+ # The remaining calls are cancelled, so the iterator is exhausted.
108+ self .assertRaises (StopIteration , next , i )
109+ self .assertRaises (StopIteration , next , i )
110+
111+ @warnings_helper .ignore_fork_in_thread_deprecation_warnings ()
112+ def test_map_close (self ):
113+ i = self .executor .map (divmod , [5 , 5 , 5 , 5 ], [2 , 0 , 3 , 5 ])
114+ self .assertEqual (next (i ), (2 , 1 ))
115+ i .close ()
116+ self .assertRaises (StopIteration , next , i )
117+ self .assertRaises (StopIteration , next , i )
118+
119+ i = self .executor .map (divmod , [5 , 5 , 5 , 5 ], [2 , 0 , 3 , 5 ], chunksize = 3 )
120+ self .assertEqual (next (i ), (2 , 1 ))
121+ i .close ()
122+ self .assertRaises (StopIteration , next , i )
123+ self .assertRaises (StopIteration , next , i )
124+
98125 def test_map_buffersize_type_validation (self ):
99126 for buffersize in ("foo" , 2.0 ):
100127 with self .subTest (buffersize = buffersize ):
0 commit comments