From 14a1073adbf1f146f1ba1872ae7aa34881b3a818 Mon Sep 17 00:00:00 2001
From: Sam Kagan <skagan@nrao.edu>
Date: Mon, 20 May 2024 11:10:49 -0600
Subject: [PATCH] Passed tests assuming PPR comes in thru restore args

---
 .../pexable/casa_envoy/casa_envoy/palaver.py  | 35 +++++++++++++------
 .../casa_envoy/test/test_casa_envoy.py        |  4 +--
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/apps/cli/executables/pexable/casa_envoy/casa_envoy/palaver.py b/apps/cli/executables/pexable/casa_envoy/casa_envoy/palaver.py
index 076fd4a74..f72f2ff7e 100644
--- a/apps/cli/executables/pexable/casa_envoy/casa_envoy/palaver.py
+++ b/apps/cli/executables/pexable/casa_envoy/casa_envoy/palaver.py
@@ -56,7 +56,8 @@ def _get_settings(cwd: pathlib.Path, args: list) -> dict:
     processing_dir = str(cwd.name)
 
     metadata = args[0]
-    ppr = args[1]
+    # Restores don't always come with a PPR from the arguments, sometimes they want to use the PPR in the cal.
+    ppr = args[1] if len(args) > 1 else None
 
     return {
         "useCasa": use_casa,
@@ -78,25 +79,38 @@ def _setup_launcher(path: pathlib.Path, args: argparse.Namespace) -> LauncherIF:
     :param args: arguments specifying type of processing requested
     :return: Launcher
     """
+    if not (
+        (args.standard_cal is not None)
+        ^ (args.vlass_cal is not None)
+        ^ (args.standard_img is not None)
+        ^ (args.vlass_img is not None)
+        ^ (args.restore is not None)
+        ^ (args.split is not None)
+    ):
+        raise ValueError(
+            "Expected exactly one of standard_cal, vlass_cal, standard_img, vlass_img, or restore arguments to be provided, found none or multiple"
+        )
     parameters = {}
 
     if args.parallel is not None:
         parameters["requested_parallel"] = args.parallel
 
-    if args.standard_cal is not None or args.vlass_cal is not None:
+    if args.standard_cal is not None or args.vlass_cal is not None or args.restore is not None:
         if args.standard_cal:
             parameters = {**parameters, **_get_settings(path, args.standard_cal)}
-            if args.restore:
-                parameters["product_type"] = ProductType.RESTORE.value
-            else:
-                parameters["product_type"] = ProductType.STD_CAL.value
-
-        if args.vlass_cal:
+            parameters["product_type"] = ProductType.STD_CAL.value
+        elif args.vlass_cal:
             parameters = {
                 **parameters,
                 **_get_settings(path, args.vlass_cal),
                 "product_type": ProductType.VLASS_CAL.value,
             }
+        elif args.restore:
+            parameters = {
+                **parameters,
+                **_get_settings(path, args.restore),
+                "product_type": ProductType.RESTORE.value,
+            }
 
         return CalibrationLauncher(parameters)
     elif args.standard_img is not None or args.vlass_img is not None:
@@ -175,9 +189,10 @@ def arg_parser() -> argparse.ArgumentParser:
     )
     parser.add_argument(
         "--restore",
+        nargs="+",
         required=False,
-        action="store_true",
-        help="run the restore measurement set CASA pipeline, use in conjunction with '-c'",
+        action="store",
+        help="run the restore measurement set CASA pipeline",
     )
     parser.add_argument(
         "--integrated",
diff --git a/apps/cli/executables/pexable/casa_envoy/test/test_casa_envoy.py b/apps/cli/executables/pexable/casa_envoy/test/test_casa_envoy.py
index d88f477ad..50bc4d8f0 100644
--- a/apps/cli/executables/pexable/casa_envoy/test/test_casa_envoy.py
+++ b/apps/cli/executables/pexable/casa_envoy/test/test_casa_envoy.py
@@ -182,9 +182,7 @@ class TestPalaver:
         :param mock_json:
         :return:
         """
-        args.restore = [
-            "test/input_files/restore.json",
-        ]
+        args.restore = ["test/input_files/restore.json", "test/input_files/PPR.xml"]
 
         with patch("argparse.ArgumentParser.parse_args", MagicMock(return_value=args)) as mock_args:
             with patch("casa_envoy.launchers.CalibrationLauncher.launch_casa") as cal_launcher:
-- 
GitLab