Coverage for tests/test_driver.py : 39%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# # This file is part of ap_verify. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. #
return [{"visit": 42, "ccd": 0}]
"""Shortcut decorator for consistently patching ApPipeTask. """ def wrapper(self, *args, **kwargs): parsedCmd = argparse.Namespace() parsedCmd.id = DataIdContainer() parsedCmd.id.idList = _getDataIds() parReturn = Struct( argumentParser=None, parsedCmd=parsedCmd, taskRunner=None, resultList=[None]) patcher = unittest.mock.patch("lsst.ap.pipe.ApPipeTask", **{"parseAndRun.return_value": parReturn}, _DefaultName=ApPipeTask._DefaultName, ConfigClass=ApPipeTask.ConfigClass) patchedMethod = patcher(method) return patchedMethod(self, *args, **kwargs)
self._testDir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self._testDir, ignore_errors=True)
# Fake Butler to avoid Workspace initialization overhead self.setUpMockPatch("lsst.daf.persistence.Butler", autospec=True)
self.workspace = Workspace(self._testDir) self.apPipeArgs = pipeline_driver.ApPipeParser().parse_args( ["--id", "visit=%d" % _getDataIds()[0]["visit"]])
def dummyMetadata(): result = PropertySet() result.add("lsst.ap.pipe.ccdProcessor.cycleCount", 42) return result
"""Create and register a patcher for a test suite.
The patching process is guaranteed to avoid resource leaks or side effects lasting beyond the test case that calls this method.
Parameters ---------- target : `str` The target to patch. Must obey all restrictions listed for the ``target`` parameter of `unittest.mock.patch`. kwargs : any Any keyword arguments that are allowed for `unittest.mock.patch`, particularly optional attributes for a `unittest.mock.Mock`.
Returns ------- mock : `unittest.mock.MagicMock` Object representing the same type of entity as ``target``. For example, if ``target`` is the name of a class, this method shall return a replacement class (rather than a replacement object of that class). """ patcher = unittest.mock.patch(target, **kwargs) mock = patcher.start() self.addCleanup(patcher.stop) return mock
# Mock up ApPipeTask to avoid doing any processing. def testRunApPipeSteps(self, mockClass): """Test that runApPipe runs the entire pipeline. """ pipeline_driver.runApPipe(self.workspace, self.apPipeArgs)
mockClass.parseAndRun.assert_called_once()
def testRunApPipeDataIdReporting(self, mockClass): """Test that runApPipe reports the data IDs that were processed. """ ids = pipeline_driver.runApPipe(self.workspace, self.apPipeArgs)
self.assertEqual(ids.idList, _getDataIds())
if parseAndRunArgs[0]: return parseAndRunArgs[0][0] elif "args" in parseAndRunArgs[1]: return parseAndRunArgs[1]["args"] else: self.fail("No command-line args passed to parseAndRun!")
def testRunApPipeCustomConfig(self, mockClass): """Test that runApPipe can pass custom configs from a workspace to ApPipeTask. """ mockParse = mockClass.parseAndRun pipeline_driver.runApPipe(self.workspace, self.apPipeArgs) mockParse.assert_called_once() cmdLineArgs = self._getCmdLineArgs(mockParse.call_args) self.assertIn(os.path.join(self.workspace.configDir, "apPipe.py"), cmdLineArgs)
def testRunApPipeWorkspaceDb(self, mockClass): """Test that runApPipe places a database in the workspace location by default. """ mockParse = mockClass.parseAndRun pipeline_driver.runApPipe(self.workspace, self.apPipeArgs) mockParse.assert_called_once() cmdLineArgs = self._getCmdLineArgs(mockParse.call_args) self.assertIn("ppdb.db_url=sqlite:///" + self.workspace.dbLocation, cmdLineArgs)
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |