From 6f84f80ae708e1a83686ae761c8295cce62c5188 Mon Sep 17 00:00:00 2001 From: noah-weingarden Date: Wed, 22 Nov 2023 18:30:02 -0500 Subject: [PATCH] Increase API coverage --- tests/test_api.py | 32 ++++++++++++++++++++++ tests/testdata/word_count/reduce_exit_1.py | 6 ++++ 2 files changed, 38 insertions(+) create mode 100755 tests/testdata/word_count/reduce_exit_1.py diff --git a/tests/test_api.py b/tests/test_api.py index 8754970..88d0ed6 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,6 +1,9 @@ """System tests for the API interface.""" +from pathlib import Path import pytest import madoop +from madoop.exceptions import MadoopError +from madoop.mapreduce import map_stage, reduce_stage from . import utils from .utils import TESTDATA_DIR @@ -53,6 +56,18 @@ def test_bash_executable(tmpdir): ) +def test_output_already_exists(tmpdir): + """Output already existing should raise an error.""" + with tmpdir.as_cwd(), pytest.raises(madoop.MadoopError): + madoop.mapreduce( + input_path=TESTDATA_DIR/"word_count/input", + output_dir=tmpdir, + map_exe=TESTDATA_DIR/"word_count/map.py", + reduce_exe=TESTDATA_DIR/"word_count/reduce.py", + num_reducers=2, + ) + + def test_bad_map_exe(tmpdir): """Map exe returns non-zero should produce an error message.""" with tmpdir.as_cwd(), pytest.raises(madoop.MadoopError): @@ -64,6 +79,23 @@ def test_bad_map_exe(tmpdir): num_reducers=4 ) + with tmpdir.as_cwd(), pytest.raises(madoop.MadoopError): + map_stage( + exe=TESTDATA_DIR/"word_count/map_invalid.py", + input_dir=TESTDATA_DIR/"word_count/input", + output_dir=Path(tmpdir), + ) + + +def test_bad_reduce_exe(tmpdir): + """Reduce exe returns non-zero should produce an error message.""" + with tmpdir.as_cwd(), pytest.raises(madoop.MadoopError): + reduce_stage( + exe=TESTDATA_DIR/"word_count/reduce_exit_1.py", + input_dir=TESTDATA_DIR/"word_count/input", + output_dir=Path(tmpdir), + ) + def test_missing_shebang(tmpdir): """Reduce exe with a bad shebag should produce an error message.""" diff --git a/tests/testdata/word_count/reduce_exit_1.py b/tests/testdata/word_count/reduce_exit_1.py new file mode 100755 index 0000000..4561d53 --- /dev/null +++ b/tests/testdata/word_count/reduce_exit_1.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +"""Invalid reduce executable exits 1.""" + +import sys + +sys.exit(1)