Skip to content
Snippets Groups Projects
Commit 82e3be02 authored by Sam Kagan's avatar Sam Kagan
Browse files

Added failing tests for updated restore CLI and multiple-code-path error

parent c3b2c716
No related branches found
No related tags found
2 merge requests!1706merge 2.8.4 to main,!1657Got EVLA CMS restores working via casa_envoy, using casa_restorepipescript.py when it exists
......@@ -19,9 +19,11 @@
Tests for casa_envoy.palaver
"""
import argparse
import itertools
from unittest.mock import MagicMock, patch
import casa_envoy.palaver as palaver
import pytest
from casa_envoy.launchers import CalibrationLauncher, ImagingLauncher
from pycapo import CapoConfig
......@@ -35,18 +37,21 @@ expected_settings = {
"ppr": "test/input_files/PPR.xml",
"product_type": "standard-cal",
}
args = argparse.Namespace()
@pytest.fixture
def args() -> argparse.Namespace:
return palaver.arg_parser().parse_args([])
class TestPalaver:
def test_get_settings(self):
def test_get_settings(self, args):
"""
verifies correct determination of needed settings
:return:
"""
args.standard_cal = ["test/input_files/test.json", "test/input_files/PPR.xml"]
args.restore = False
with patch(
"casa_envoy.palaver.CapoConfig",
......@@ -56,16 +61,14 @@ class TestPalaver:
"pathlib.Path.cwd",
MagicMock(return_value="/lustre/aoc/cluster/pipeline/docker/workspaces/spool/tmpo1ca1pp_"),
) as cwd:
settings = palaver._get_settings(cwd, args.standard_cal)
settings = palaver._get_settings(cwd, ["test/input_files/test.json", "test/input_files/PPR.xml"])
assert settings["useCasa"] == expected_settings["useCasa"]
assert settings["homeForReprocessing"] == expected_settings["homeForReprocessing"]
assert settings["metadata"] == expected_settings["metadata"]
assert settings["ppr"] == expected_settings["ppr"]
args.standard_cal = None
@patch("json.loads")
def test_setup_launcher(self, mock_json):
def test_setup_launcher(self, mock_json, args):
"""
Verifies that the correct type of launcher is created
......@@ -75,11 +78,7 @@ class TestPalaver:
"pathlib.Path.cwd",
MagicMock(return_value="/lustre/aoc/cluster/pipeline/docker/workspaces/spool/tmpo1ca1pp_"),
) as cwd:
args.parallel = None
args.standard_cal = ["test/input_files/test.json", "test/input_files/PPR.xml"]
args.vlass_cal = None
args.restore = False
launcher = palaver._setup_launcher(cwd, args)
assert isinstance(launcher, CalibrationLauncher)
args.standard_cal = None
......@@ -88,11 +87,38 @@ class TestPalaver:
"test/input_files/image-metadata.json",
"test/input_files/cmsimage-PPR.xml",
]
args.vlass_img = None
args.integrated = False
launcher = palaver._setup_launcher(cwd, args)
assert isinstance(launcher, ImagingLauncher)
args.standard_img = None
@patch("json.loads")
def test_setup_launcher_multiple_code_paths_specified(self, mock_json):
"""
Verifies that multiple code-paths can't all be specified at once
:return:
"""
std_cal_args = ["--standard-cal", "test/input_files/test.json", "test/input_files/PPR.xml"]
vlass_cal_args = ["--vlass-cal", "file", "other-file"]
restore_args = ["--restore", "test/input_files/restore.json"]
std_img_args = [
"--standard-img",
"test/input_files/cmsimage-PPR.xml",
"test/input_files/image-metadata.json",
]
vlass_img_args = ["--vlass-img", "file", "other-file"]
with patch(
"pathlib.Path.cwd",
MagicMock(return_value="/lustre/aoc/cluster/pipeline/docker/workspaces/spool/tmpo1ca1pp_"),
) as cwd:
for one_codepath_args, two_codepath_args in itertools.combinations(
[std_cal_args, vlass_cal_args, restore_args, std_img_args, vlass_img_args], 2
):
raw_args = one_codepath_args + two_codepath_args
parser = palaver.arg_parser()
real_args = parser.parse_args(raw_args)
with pytest.raises(ValueError, match="Expected exactly one"):
palaver._setup_launcher(cwd, real_args)
def test_parser(self):
"""
......@@ -106,7 +132,7 @@ class TestPalaver:
@patch("json.loads")
@patch("os.chdir")
@patch("os.getcwd")
def test_main_cal(self, mock_cwd, mock_chdir, mock_json):
def test_main_cal(self, mock_cwd, mock_chdir, mock_json, args):
"""
verifies use of correct launcher for calibrations
......@@ -116,21 +142,16 @@ class TestPalaver:
:return:
"""
args.standard_cal = ["test/input_files/test.json", "test/input_files/PPR.xml"]
args.integrated = False
args.vlass_cal = None
args.parallel = None
with patch("argparse.ArgumentParser.parse_args", MagicMock(return_value=args)) as mock_args:
with patch("casa_envoy.launchers.CalibrationLauncher.launch_casa") as cal_launcher:
palaver.main()
assert cal_launcher.call_count == 1
args.standard_cal = None
@patch("json.loads")
@patch("os.chdir")
@patch("os.getcwd")
def test_main_img(self, mock_cwd, mock_chdir, mock_json):
def test_main_img(self, mock_cwd, mock_chdir, mock_json, args):
"""
verifies use of correct launcher for images
......@@ -143,12 +164,29 @@ class TestPalaver:
"test/input_files/image-metadata.json",
"test/input_files/cmsimage-PPR.xml",
]
args.vlass_img = None
args.parallel = None
with patch("argparse.ArgumentParser.parse_args", MagicMock(return_value=args)) as mock_args:
with patch("casa_envoy.launchers.ImagingLauncher.launch_casa") as img_launcher:
palaver.main()
assert img_launcher.call_count == 1
args.standard_img = None
@patch("json.loads")
@patch("os.chdir")
@patch("os.getcwd")
def test_main_restore(self, mock_cwd, mock_chdir, mock_json, args):
"""
verifies use of correct launcher for restores
:param mock_cwd:
:param mock_chdir:
:param mock_json:
:return:
"""
args.restore = [
"test/input_files/restore.json",
]
with patch("argparse.ArgumentParser.parse_args", MagicMock(return_value=args)) as mock_args:
with patch("casa_envoy.launchers.CalibrationLauncher.launch_casa") as cal_launcher:
palaver.main()
assert cal_launcher.call_count == 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment