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

Added tests for auditing restore w/ and w/o PPR, and for cal w/o PPR

parent f9251eb4
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
......@@ -16,6 +16,7 @@
# along with Workspaces. If not, see <https://www.gnu.org/licenses/>.
#
"""Config file for Pytest, where directory-wide fixtures are defined"""
from copy import copy
from pathlib import Path
import pytest
......@@ -51,14 +52,39 @@ def cal_settings(rootDirectory, processingDirectory, parent_path) -> dict:
@pytest.fixture
def img_settings(rootDirectory, processingDirectory, parent_path) -> dict:
def img_settings(parent_path) -> dict:
"""Use different rootDirectory and processingDirectory to match contents of
input_files/image-metadata.json, input_files/cube-metadata.json, and input_files/cmsimage-PPR.xml.
"""
return {
"useCasa": False,
"homeForReprocessing": "/home/casa/packages/pipeline/current",
"rootDirectory": rootDirectory,
"processingDirectory": processingDirectory,
"rootDirectory": "/lustre/aoc/cluster/pipeline/docker/workspaces/spool",
"processingDirectory": "tmpo1ca1pp_",
"metadata": "test/input_files/image-metadata.json",
"ppr": "test/input_files/cmsimage-PPR.xml",
"product_type": "standard-img",
"parent_path": parent_path,
}
@pytest.fixture
def restore_settings_sans_ppr(rootDirectory, processingDirectory, parent_path) -> dict:
return {
"useCasa": False,
"homeForReprocessing": "/home/casa/packages/pipeline/current",
"rootDirectory": rootDirectory,
"processingDirectory": processingDirectory,
"metadata": "test/input_files/restore.json",
"ppr": None,
"product_type": "restore",
"parent_path": parent_path,
"piperestorescript_path": Path("path/to/casa_piperestorescript.py"),
}
@pytest.fixture
def restore_settings_with_ppr(restore_settings_sans_ppr) -> dict:
restore_settings_with_ppr_dict = copy(restore_settings_sans_ppr)
restore_settings_with_ppr_dict["ppr"] = "test/input_files/restore-PPR.xml"
return restore_settings_with_ppr_dict
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<ns2:SciPipeRequest xmlns:ns2="Common/pipelinescience/SciPipeRequest">
<ProjectSummary>
<ProposalCode>VLA/23B-215</ProposalCode>
<ProposalTitle>CONICS-VLA: CO(1-0) for the Cosmic Noon ISM Conditions Survey</ProposalTitle>
<PIName>Leindert Boogaard</PIName>
<Observatory>NRAO</Observatory>
<Telescope>EVLA</Telescope>
<ProcessingSite>Socorro</ProcessingSite>
<Operator>vlapipe</Operator>
<Mode>SCIENCE</Mode>
<Version>NGRH-ALMA-10_8</Version>
<CreationTime>2024-05-20T23:02:43</CreationTime>
</ProjectSummary>
<ProjectStructure>TBD</ProjectStructure>
<ProcessingRequests>
<RootDirectory>/tmp/workspaces_tmp</RootDirectory>
<ProcessingRequest>
<ProcessingIntents/>
<ProcessingProcedure>
<ProcessingCommand>
<Command>hifv_restoredata</Command>
<ParameterSet/>
</ProcessingCommand>
<ProcessingCommand>
<Command>hifv_statwt</Command>
<ParameterSet/>
</ProcessingCommand>
</ProcessingProcedure>
<DataSet>
<RelativePath>tmpiox5trbp</RelativePath>
<SdmIdentifier>brain_001.58099.678886747686</SdmIdentifier>
<DataType>asdm</DataType>
</DataSet>
</ProcessingRequest>
</ProcessingRequests>
</ns2:SciPipeRequest>
......@@ -2,6 +2,7 @@
"fileSetIds": ["brain_000.58099.67095825232", "calibration.tar"],
"workflowName": "restore_cms",
"systemId": "2",
"creationTime": "2021-05-06T17:34:36",
"productLocator": "uid://evla/execblock/ec082e65-452d-4fec-ad88-f5b4af1f9e36",
"calProductLocator": "uid://evla/calibration/ec082e65-452d-4fec-ad88-f5b4af1f9e36",
"projectMetadata": {
......
......@@ -40,6 +40,13 @@ test_cal_metadata = AbstractTextFile(
filename="test/input_files/test.json", content=Path("test/input_files/test.json").read_text()
)
test_restore_metadata = AbstractTextFile(
"test/input_files/restore.json", content=Path("test/input_files/restore.json").read_text()
)
test_restore_ppr = AbstractTextFile(
"test/input_files/restore-PPR.xml", content=Path("test/input_files/restore-PPR.xml").read_text()
)
test_img_ppr = AbstractTextFile(
filename="test/input_files/cmsimage-PPR.xml",
content=Path("test/input_files/cmsimage-PPR.xml").read_text(),
......@@ -190,14 +197,44 @@ class TestAuditFiles:
assert mock_open.call_count == 1 # would this have written out as expected if not mocked?
assert ppr.content == correct_content
def test_audit(self, cal_settings, img_settings):
def test_audit_cal(self, cal_settings):
with patch("casa_envoy.auditor.AuditFiles.correct_for_condor") as condor:
result = AuditFiles(test_ppr, [test_cal_metadata], cal_settings).audit()
assert result is True
result2 = AuditFiles(test_ppr, [test_cal_metadata], img_settings).audit()
def test_audit_cal_bad_no_ppr(self, cal_settings):
with patch("casa_envoy.auditor.AuditFiles.correct_for_condor") as condor:
result = AuditFiles(None, [test_cal_metadata], cal_settings).audit()
assert result is False
def test_audit_cal_bad_wrong_product_type(self, cal_settings):
with patch("casa_envoy.auditor.AuditFiles.correct_for_condor") as condor:
cal_settings["product_type"] = "standard-img"
result2 = AuditFiles(test_ppr, [test_cal_metadata], cal_settings).audit()
assert result2 is False
def test_audit_restore_no_ppr(self, restore_settings_sans_ppr):
with patch("casa_envoy.auditor.AuditFiles.correct_for_condor") as condor:
result = AuditFiles(None, [test_restore_metadata], restore_settings_sans_ppr).audit()
assert result is True
def test_audit_restore_no_ppr_bad_no_piperestorescript(self, restore_settings_sans_ppr):
del restore_settings_sans_ppr["piperestorescript_path"]
with patch("casa_envoy.auditor.AuditFiles.correct_for_condor") as condor:
result2 = AuditFiles(None, [test_restore_metadata], restore_settings_sans_ppr).audit()
assert result2 is False
def test_audit_restore_with_ppr_and_piperestorescript(self, restore_settings_sans_ppr):
with patch("casa_envoy.auditor.AuditFiles.correct_for_condor") as condor:
result2 = AuditFiles(test_restore_ppr, [test_restore_metadata], restore_settings_sans_ppr).audit()
assert result2 is True
def test_audit_restore_with_ppr_no_pipescript(self, restore_settings_sans_ppr):
del restore_settings_sans_ppr["piperestorescript_path"]
with patch("casa_envoy.auditor.AuditFiles.correct_for_condor") as condor:
result2 = AuditFiles(test_restore_ppr, [test_restore_metadata], restore_settings_sans_ppr).audit()
assert result2 is True
class TestAuditDirectories:
"""
......
......@@ -33,17 +33,6 @@ from casa_envoy.configure import (
)
from casa_envoy.schema import AbstractTextFile
piperestorescript_parameters = {
"useCasa": False,
"homeForReprocessing": "/home/casa/packages/pipeline/current",
"rootDirectory": "/tmp/workspaces_tmp/",
"processingDirectory": "tmpiox5trbp",
"metadata": "test/input_files/restore.json",
"ppr": "test/input_files/PPR.xml",
"product_type": "restore",
"parent_path": Path("I/am/a/path"),
"piperestorescript_path": Path("path/to/casapiperestorescript.py"),
}
parallel_parameters = {
"useCasa": False,
"homeForReprocessing": "/home/casa/packages/pipeline/current",
......@@ -107,9 +96,9 @@ class TestPiperestorescriptRunner:
@patch("os.chdir")
@patch("subprocess.Popen")
def test_piperestorescript_call_casa(self, mock_subprocess, mock_chdir):
assert "piperestorescript_path" in piperestorescript_parameters
runner = PiperestorescriptRunner(parameters=piperestorescript_parameters)
def test_piperestorescript_call_casa(self, mock_subprocess, mock_chdir, restore_settings_sans_ppr):
assert "piperestorescript_path" in restore_settings_sans_ppr
runner = PiperestorescriptRunner(parameters=restore_settings_sans_ppr)
runner.call_casa()
assert mock_subprocess.called_with(runner.build_command) @ patch("os.chdir")
......
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