Skip to content

Commit

Permalink
Merge branch 'tickets/DM-45677'
Browse files Browse the repository at this point in the history
  • Loading branch information
kfindeisen committed Sep 3, 2024
2 parents b6e9ca1 + b1cb93b commit 0988827
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 1,253 deletions.
4 changes: 2 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConstruct("ap_verify", disableCc=True)

# Python-only package
scripts.BasicSConstruct("ap_verify", disableCc=True, noCfgFile=True)
676 changes: 0 additions & 676 deletions python/lsst/ap/verify/testPipeline.py

This file was deleted.

99 changes: 0 additions & 99 deletions tests/MockApPipe.yaml

This file was deleted.

45 changes: 8 additions & 37 deletions tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@
from lsst.ap.verify import Dataset, WorkspaceGen3


TESTDIR = os.path.abspath(os.path.dirname(__file__))


def _getDataIds(butler):
return list(butler.registry.queryDataIds({"instrument", "visit", "detector"}, datasets="raw"))


def patchApPipeGen3(method):
"""Shortcut decorator for consistently patching AP code.
"""
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
dbPatcher = unittest.mock.patch("lsst.ap.verify.pipeline_driver._makeApdb")
patchedMethod = dbPatcher(method)
pipePatcher = unittest.mock.patch("lsst.ap.verify.pipeline_driver.subprocess")
patchedMethod = dbPatcher(pipePatcher(method))
return patchedMethod(self, *args, **kwargs)
return wrapper

Expand All @@ -74,24 +68,7 @@ def setUp(self):
defineVisit = DefineVisitsTask(butler=self.workspace.workButler,
config=DefineVisitsTask.ConfigClass())
defineVisit.run(self.workspace.workButler.registry.queryDataIds("exposure", datasets="raw"))
ids = _getDataIds(self.workspace.workButler)
self.apPipeArgs = pipeline_driver.ApPipeParser().parse_args(
["--data-query", f"instrument = '{ids[0]['instrument']}' AND visit = {ids[0]['visit']}",
"--pipeline", os.path.join(TESTDIR, "MockApPipe.yaml")])

def testrunApPipeGen3Steps(self):
"""Test that runApPipeGen3 runs the entire pipeline.
"""
pipeline_driver.runApPipeGen3(self.workspace, self.apPipeArgs)

# Use datasets as a proxy for pipeline completion
id = _getDataIds(self.workspace.analysisButler)[0]
self.assertTrue(self.workspace.analysisButler.exists("calexp", id))
self.assertTrue(self.workspace.analysisButler.exists("src", id))
self.assertTrue(self.workspace.analysisButler.exists("goodSeeingDiff_differenceExp", id))
self.assertTrue(self.workspace.analysisButler.exists("goodSeeingDiff_diaSrc", id))
self.assertTrue(self.workspace.analysisButler.exists("apdb_marker", id))
self.assertTrue(self.workspace.analysisButler.exists("goodSeeingDiff_assocDiaSrc", id))
self.apPipeArgs = pipeline_driver.ApPipeParser().parse_args(["--pipeline", "foo.yaml"])

def _getArgs(self, call_args):
if call_args.args:
Expand All @@ -102,7 +79,7 @@ def _getArgs(self, call_args):
self.fail(f"No APDB args passed to {call_args}!")

@patchApPipeGen3
def testrunApPipeGen3WorkspaceDb(self, mockDb):
def testrunApPipeGen3WorkspaceDb(self, _mockPipe, mockDb):
"""Test that runApPipeGen3 places a database in the workspace location by default.
"""
pipeline_driver.runApPipeGen3(self.workspace, self.apPipeArgs)
Expand All @@ -113,7 +90,7 @@ def testrunApPipeGen3WorkspaceDb(self, mockDb):
self.assertEqual(dbArgs["db_url"], "sqlite:///" + self.workspace.dbLocation)

@patchApPipeGen3
def testrunApPipeGen3WorkspaceCustom(self, mockDb):
def testrunApPipeGen3WorkspaceCustom(self, _mockPipe, mockDb):
"""Test that runApPipeGen3 places a database in the specified location.
"""
self.apPipeArgs.db = "postgresql://[email protected]/custom_db"
Expand All @@ -124,20 +101,14 @@ def testrunApPipeGen3WorkspaceCustom(self, mockDb):
self.assertIn("db_url", dbArgs)
self.assertEqual(dbArgs["db_url"], self.apPipeArgs.db)

def testrunApPipeGen3Reuse(self):
@patchApPipeGen3
def testrunApPipeGen3Reuse(self, mockPipe, _mockDb):
"""Test that runApPipeGen3 does not run the pipeline at all (not even with
--skip-existing) if --skip-pipeline is provided.
"""
skipArgs = pipeline_driver.ApPipeParser().parse_args(["--skip-pipeline"])
pipeline_driver.runApPipeGen3(self.workspace, skipArgs)

# Use datasets as a proxy for pipeline completion.
# Depending on the overall test setup, the dataset may or may not be
# registered if the pipeline didn't run; check both cases.
id = _getDataIds(self.workspace.analysisButler)[0]
calexpQuery = set(self.workspace.analysisButler.registry.queryDatasetTypes("calexp"))
calexpExists = len(calexpQuery) > 0
self.assertFalse(calexpExists and self.workspace.analysisButler.exists("calexp", id))
mockPipe.assert_not_called()


class MemoryTester(lsst.utils.tests.MemoryTestCase):
Expand Down
Loading

0 comments on commit 0988827

Please sign in to comment.