-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-30148: PipelineTasks use wrong label as name #123
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
Copyright 2016 University of Illinois Champaign-Urbana | ||
Copyright 2016-2018 The Board of Trustees of the Leland Stanford Junior University, through SLAC National Accelerator Laboratory | ||
Copyright 2018 The Trustees of Princeton University | ||
Copyright 2016 University of Illinois Board of Trustees | ||
Copyright 2016-2021 The Board of Trustees of the Leland Stanford Junior University, through SLAC National Accelerator Laboratory | ||
Copyright 2018-2021 The Trustees of Princeton University | ||
Copyright 2019-2021 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
Copyright 2021 University of Washington |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# This file is part of ctrl_mpexec. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://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 <https://www.gnu.org/licenses/>. | ||
|
||
import shutil | ||
import tempfile | ||
import unittest | ||
|
||
import lsst.afw.table as afwTable | ||
import lsst.daf.butler.tests as butlerTests | ||
import lsst.pex.config as pexConfig | ||
from lsst.pipe.base import PipelineTaskConfig, PipelineTaskConnections | ||
from lsst.pipe.base.configOverrides import ConfigOverrides | ||
from lsst.pipe.base import connectionTypes | ||
|
||
from lsst.ctrl.mpexec import TaskFactory | ||
|
||
|
||
class FakeConnections(PipelineTaskConnections, dimensions=set()): | ||
initInput = connectionTypes.InitInput(name="fakeInitInput", doc="", storageClass="SourceCatalog") | ||
initOutput = connectionTypes.InitOutput(name="fakeInitOutput", doc="", storageClass="SourceCatalog") | ||
input = connectionTypes.Input(name="fakeInput", doc="", storageClass="SourceCatalog", dimensions=set()) | ||
output = connectionTypes.Output(name="fakeOutput", doc="", storageClass="SourceCatalog", dimensions=set()) | ||
|
||
|
||
class FakeConfig(PipelineTaskConfig, pipelineConnections=FakeConnections): | ||
widget = pexConfig.Field(dtype=float, doc="") | ||
|
||
|
||
def mockTaskClass(): | ||
"""A class placeholder that records calls to __call__. | ||
""" | ||
mock = unittest.mock.Mock(__name__="_TaskMock", _DefaultName="FakeTask", ConfigClass=FakeConfig) | ||
return mock | ||
|
||
|
||
class TaskFactoryTestCase(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
|
||
tmp = tempfile.mkdtemp() | ||
cls.addClassCleanup(shutil.rmtree, tmp, ignore_errors=True) | ||
cls.repo = butlerTests.makeTestRepo(tmp) | ||
butlerTests.addDatasetType(cls.repo, "fakeInitInput", set(), "SourceCatalog") | ||
butlerTests.addDatasetType(cls.repo, "fakeInitOutput", set(), "SourceCatalog") | ||
butlerTests.addDatasetType(cls.repo, "fakeInput", set(), "SourceCatalog") | ||
butlerTests.addDatasetType(cls.repo, "fakeOutput", set(), "SourceCatalog") | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
||
self.factory = TaskFactory() | ||
self.constructor = mockTaskClass() | ||
|
||
@staticmethod | ||
def _alteredConfig(): | ||
config = FakeConfig() | ||
config.widget = 42.0 | ||
return config | ||
|
||
@staticmethod | ||
def _overrides(): | ||
overrides = ConfigOverrides() | ||
overrides.addValueOverride("widget", -1.0) | ||
return overrides | ||
|
||
@staticmethod | ||
def _dummyCatalog(): | ||
schema = afwTable.SourceTable.makeMinimalSchema() | ||
return afwTable.SourceCatalog(schema) | ||
|
||
def _tempButler(self): | ||
butler = butlerTests.makeTestCollection(self.repo, uniqueId=self.id()) | ||
catalog = self._dummyCatalog() | ||
butler.put(catalog, "fakeInitInput") | ||
butler.put(catalog, "fakeInitOutput") | ||
butler.put(catalog, "fakeInput") | ||
butler.put(catalog, "fakeOutput") | ||
return butler | ||
|
||
def testOnlyMandatoryArg(self): | ||
self.factory.makeTask(taskClass=self.constructor, label=None, config=None, | ||
overrides=None, butler=None) | ||
self.constructor.assert_called_with(config=FakeConfig(), initInputs=None, name=None) | ||
|
||
def testAllArgs(self): | ||
butler = self._tempButler() | ||
self.factory.makeTask(taskClass=self.constructor, label="no-name", config=self._alteredConfig(), | ||
overrides=self._overrides(), butler=butler) | ||
catalog = butler.get("fakeInitInput") # Copies of _dummyCatalog are identical but not equal | ||
# When config passed in, overrides ignored | ||
self.constructor.assert_called_with(config=self._alteredConfig(), | ||
initInputs={'initInput': catalog}, | ||
name="no-name") | ||
|
||
# Can't test all 14 remaining combinations, but the 6 pairs should be enough coverage | ||
|
||
def testNameConfig(self): | ||
self.factory.makeTask(taskClass=self.constructor, label="no-name", config=self._alteredConfig(), | ||
overrides=None, butler=None) | ||
self.constructor.assert_called_with(config=self._alteredConfig(), initInputs=None, name="no-name") | ||
|
||
def testNameOverrides(self): | ||
self.factory.makeTask(taskClass=self.constructor, label="no-name", config=None, | ||
overrides=self._overrides(), butler=None) | ||
config = FakeConfig() | ||
self._overrides().applyTo(config) | ||
self.constructor.assert_called_with(config=config, initInputs=None, name="no-name") | ||
|
||
def testNameButler(self): | ||
butler = self._tempButler() | ||
self.factory.makeTask(taskClass=self.constructor, label="no-name", config=None, | ||
overrides=None, butler=butler) | ||
catalog = butler.get("fakeInitInput") # Copies of _dummyCatalog are identical but not equal | ||
self.constructor.assert_called_with(config=FakeConfig(), | ||
initInputs={'initInput': catalog}, | ||
name="no-name") | ||
|
||
def testConfigOverrides(self): | ||
self.factory.makeTask(taskClass=self.constructor, label=None, config=self._alteredConfig(), | ||
overrides=self._overrides(), butler=None) | ||
# When config passed in, overrides ignored | ||
self.constructor.assert_called_with(config=self._alteredConfig(), initInputs=None, name=None) | ||
|
||
def testConfigButler(self): | ||
butler = self._tempButler() | ||
self.factory.makeTask(taskClass=self.constructor, label=None, config=self._alteredConfig(), | ||
overrides=None, butler=butler) | ||
catalog = butler.get("fakeInitInput") # Copies of _dummyCatalog are identical but not equal | ||
self.constructor.assert_called_with(config=self._alteredConfig(), | ||
initInputs={'initInput': catalog}, | ||
name=None) | ||
|
||
def testOverridesButler(self): | ||
butler = self._tempButler() | ||
self.factory.makeTask(taskClass=self.constructor, label=None, config=None, | ||
overrides=self._overrides(), butler=butler) | ||
config = FakeConfig() | ||
self._overrides().applyTo(config) | ||
catalog = butler.get("fakeInitInput") # Copies of _dummyCatalog are identical but not equal | ||
self.constructor.assert_called_with(config=config, | ||
initInputs={'initInput': catalog}, | ||
name=None) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring: it's not obvious to me what a "TaskFactory" test would be testing. I think it's testing
TaskFactory.makeTask()
with a variety of combinations of optional arguments?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It tests the functionality of
TaskFactory
(which happens to consist of one method)? I'm not sure what I could say that wouldn't be obvious.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, maybe the fact that
TaskFactory
itself is short on documentation is really my problem? I was looking at the test without knowing anything about TaskFactory: I didn't know it only had one method.