Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions makedocker
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ then
echo "In the first case, the name of the study is the same as the name of the .graphml"
echo "In either case, source files come from the same path as the .graphml"
echo "The equivalent mkconcore.py is displayed"
exit
exit 1
fi
graphml=$1
if [ -e $graphml ]
Expand All @@ -20,7 +20,7 @@ else
sourcedir=$(dirname "$graphml")
else
echo "$graphml does not exist"
exit
exit 1
fi
fi
if [ $# = 1 ]
Expand All @@ -33,6 +33,7 @@ if [ -e $studydir ]
then
echo "cannot make $studydir because one already exists with that name"
echo "either do ./destroy $studydir, or choose a unique name as 2nd arg"
exit 1
else
echo "python3 mkconcore.py $graphml $sourcedir $studydir docker"
python3 mkconcore.py $graphml $sourcedir $studydir docker
Expand Down
6 changes: 3 additions & 3 deletions makestudy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ "$#" -eq 0 ]; then
echo "In the first case, the name of the study is the same as the name of the .graphml"
echo "In either case, source files come from the same path as the .graphml"
echo "The equivalent mkconcore.py is displayed"
exit
exit 1
fi

graphml="$1"
Expand All @@ -20,7 +20,7 @@ else
sourcedir="$(dirname "$graphml")"
else
echo "$graphml does not exist"
exit
exit 1
fi
fi

Expand All @@ -34,7 +34,7 @@ fi
if [ -e "$studydir" ]; then
echo "Cannot make $studydir because one already exists with that name"
echo "Either do ./destroy $studydir, or choose a unique name as 2nd arg"
exit
exit 1
else
if command -v osascript >/dev/null; then
echo "python3 mkconcore.py \"$graphml\" \"$sourcedir\" \"$studydir\" macos"
Expand Down
50 changes: 50 additions & 0 deletions tests/test_makestudy_exit_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""makestudy and makedocker must exit non-zero when they fail.

The FRI server (fri/server/main.py) runs them with subprocess.check_output and
only reports an error on a non-zero exit code, so exiting 0 after a failure
made the editor report "Directory successfully created".
"""

import subprocess
import sys
from pathlib import Path

import pytest

REPO = Path(__file__).resolve().parents[1]
SCRIPTS = ["makestudy", "makedocker"]

pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="makestudy and makedocker are bash scripts"
)


def _run(script, *args):
return subprocess.run(
["bash", str(REPO / script), *args],
cwd=REPO,
capture_output=True,
text=True,
)


@pytest.mark.parametrize("script", SCRIPTS)
def test_no_arguments_exits_nonzero(script):
result = _run(script)
assert result.returncode != 0
assert "Make a concore study" in result.stdout


@pytest.mark.parametrize("script", SCRIPTS)
def test_missing_graphml_exits_nonzero(script):
result = _run(script, "demo/does_not_exist")
assert result.returncode != 0
assert "does not exist" in result.stdout


@pytest.mark.parametrize("script", SCRIPTS)
def test_existing_study_dir_exits_nonzero(script, tmp_path):
result = _run(script, "demo/sample.graphml", str(tmp_path))
assert result.returncode != 0
assert "already exists" in result.stdout
assert list(tmp_path.iterdir()) == []