Skip to content

Commit 16b039a

Browse files
committed
Subprocess error tests
1 parent d8dcaba commit 16b039a

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

tests/test_api.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,56 @@ def test_input_path_spaces(tmpdir):
208208
TESTDATA_DIR/"word_count/correct/output",
209209
tmpdir/"output",
210210
)
211+
212+
213+
def test_map_exe_error_msg(tmpdir):
214+
"""Map exe returns non-zero with stderr output should produce an
215+
error message and forward the stderr output.
216+
"""
217+
with tmpdir.as_cwd(), pytest.raises(madoop.MadoopError,
218+
match="Map error message"):
219+
madoop.mapreduce(
220+
input_path=TESTDATA_DIR/"word_count/input",
221+
output_dir="output",
222+
map_exe=TESTDATA_DIR/"word_count/map_error_msg.py",
223+
reduce_exe=TESTDATA_DIR/"word_count/reduce.py",
224+
num_reducers=4,
225+
partitioner=None,
226+
)
227+
228+
with tmpdir.as_cwd(), pytest.raises(madoop.MadoopError,
229+
match="Map error message"):
230+
map_stage(
231+
exe=TESTDATA_DIR/"word_count/map_error_msg.py",
232+
input_dir=TESTDATA_DIR/"word_count/input",
233+
output_dir=Path(tmpdir),
234+
)
235+
236+
237+
def test_partition_exe_error_msg(tmpdir):
238+
"""Partition exe returns non-zero with stderr output should produce an
239+
error message and forward the stderr output.
240+
"""
241+
with tmpdir.as_cwd(), pytest.raises(madoop.MadoopError,
242+
match="Partition error message"):
243+
madoop.mapreduce(
244+
input_path=TESTDATA_DIR/"word_count/input",
245+
output_dir="output",
246+
map_exe=TESTDATA_DIR/"word_count/map.py",
247+
reduce_exe=TESTDATA_DIR/"word_count/reduce.py",
248+
num_reducers=4,
249+
partitioner=TESTDATA_DIR/"word_count/partition_error_msg.py",
250+
)
251+
252+
253+
def test_reduce_exe_error_msg(tmpdir):
254+
"""Reduce exe returns non-zero with stderr output should produce an
255+
error message and forward the stderr output.
256+
"""
257+
with tmpdir.as_cwd(), pytest.raises(madoop.MadoopError,
258+
match="Reduce error message"):
259+
reduce_stage(
260+
exe=TESTDATA_DIR/"word_count/reduce_error_msg.py",
261+
input_dir=TESTDATA_DIR/"word_count/input",
262+
output_dir=Path(tmpdir),
263+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python3
2+
"""Invalid map executable returns non-zero with an error message."""
3+
4+
import sys
5+
6+
sys.stderr.write("Map error message")
7+
sys.exit(1)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python3
2+
"""Invalid partition executable returns non-zero with an error message."""
3+
4+
import sys
5+
6+
sys.stderr.write("Partition error message")
7+
sys.exit(1)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python3
2+
"""Invalid reduce executable returns non-zero with an error message."""
3+
4+
import sys
5+
6+
sys.stderr.write("Reduce error message")
7+
sys.exit(1)

0 commit comments

Comments
 (0)