Skip to content

Commit

Permalink
Increase API coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
noah-weingarden committed Nov 22, 2023
1 parent 6fffb63 commit 6f84f80
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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."""
Expand Down
6 changes: 6 additions & 0 deletions tests/testdata/word_count/reduce_exit_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python3
"""Invalid reduce executable exits 1."""

import sys

sys.exit(1)

0 comments on commit 6f84f80

Please sign in to comment.