Skip to content

Commit 88e0361

Browse files
authored
map(): Evaluate generator within with-statement (#812)
1 parent 3524942 commit 88e0361

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

tests/test_fluxjobexecutor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def test_single_task(self):
104104
block_allocation=True,
105105
pmi_mode=pmi,
106106
) as p:
107-
output = p.map(mpi_funct, [1, 2, 3])
107+
output = list(p.map(mpi_funct, [1, 2, 3]))
108108
self.assertEqual(
109-
list(output),
109+
output,
110110
[[(1, 2, 0), (1, 2, 1)], [(2, 2, 0), (2, 2, 1)], [(3, 2, 0), (3, 2, 1)]],
111111
)
112112

@@ -122,9 +122,9 @@ def test_output_files_cwd(self):
122122
block_allocation=True,
123123
flux_log_files=True,
124124
) as p:
125-
output = p.map(calc, [1, 2, 3])
125+
output = list(p.map(calc, [1, 2, 3]))
126126
self.assertEqual(
127-
list(output),
127+
output,
128128
[1, 2, 3],
129129
)
130130
self.assertTrue(os.path.exists(file_stdout))
@@ -142,9 +142,9 @@ def test_output_files_abs(self):
142142
block_allocation=True,
143143
flux_log_files=True,
144144
) as p:
145-
output = p.map(calc, [1, 2, 3])
145+
output = list(p.map(calc, [1, 2, 3]))
146146
self.assertEqual(
147-
list(output),
147+
output,
148148
[1, 2, 3],
149149
)
150150
self.assertTrue(os.path.exists(file_stdout))

tests/test_fluxpythonspawner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ def test_single_task(self):
9999
},
100100
spawner=FluxPythonSpawner,
101101
) as p:
102-
output = p.map(mpi_funct, [1, 2, 3])
102+
output = list(p.map(mpi_funct, [1, 2, 3]))
103103
self.assertEqual(
104-
list(output),
104+
output,
105105
[[(1, 2, 0), (1, 2, 1)], [(2, 2, 0), (2, 2, 1)], [(3, 2, 0), (3, 2, 1)]],
106106
)
107107

tests/test_mpiexecspawner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ def test_pool_serial_map(self):
323323
executor_kwargs={"cores": 1},
324324
spawner=MpiExecSpawner,
325325
) as p:
326-
output = p.map(calc_array, [1, 2, 3])
327-
self.assertEqual(list(output), [np.array(1), np.array(4), np.array(9)])
326+
output = list(p.map(calc_array, [1, 2, 3]))
327+
self.assertEqual(output, [np.array(1), np.array(4), np.array(9)])
328328

329329
def test_executor_exception(self):
330330
with self.assertRaises(RuntimeError):
@@ -430,9 +430,9 @@ def test_pool_multi_core_map(self):
430430
executor_kwargs={"cores": 2},
431431
spawner=MpiExecSpawner,
432432
) as p:
433-
output = p.map(mpi_funct, [1, 2, 3])
433+
output = list(p.map(mpi_funct, [1, 2, 3]))
434434
self.assertEqual(
435-
list(output),
435+
output,
436436
[[(1, 2, 0), (1, 2, 1)], [(2, 2, 0), (2, 2, 1)], [(3, 2, 0), (3, 2, 1)]],
437437
)
438438

tests/test_singlenodeexecutor_mpi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ def test_output_files_cwd(self):
119119
resource_dict={"cores": 1, "cwd": dirname},
120120
block_allocation=True,
121121
) as p:
122-
output = p.map(calc, [1, 2, 3])
122+
output = list(p.map(calc, [1, 2, 3]))
123123
self.assertEqual(
124-
list(output),
124+
output,
125125
[1, 2, 3],
126126
)
127127

0 commit comments

Comments
 (0)