Skip to content
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-26015 Add dimension validation #140

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions python/lsst/pipe/base/connectionTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class DimensionedConnection(BaseConnection):
"""
dimensions: typing.Iterable[str] = ()

def __post_init__(self):
if isinstance(self.dimensions, str):
raise TypeError("Dimensions must be iterable of dimensions, got str,"
"possibly omitted trailing comma")
if not isinstance(self.dimensions, typing.Iterable):
raise TypeError("Dimensions must be iterable of dimensions")

def makeDatasetType(self, universe: DimensionUniverse):
"""Construct a true `DatasetType` instance with normalized dimensions.
Parameters
Expand Down
5 changes: 5 additions & 0 deletions python/lsst/pipe/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def __new__(cls, name, bases, dct, **kwargs):
if 'dimensions' not in kwargs:
raise dimensionsValueError
try:
if isinstance(kwargs['dimensions'], str):
raise TypeError("Dimensions must be iterable of dimensions, got str,"
"possibly omitted trailing comma")
if not isinstance(kwargs['dimensions'], typing.Iterable):
raise TypeError("Dimensions must be iterable of dimensions")
dct['dimensions'] = set(kwargs['dimensions'])
except TypeError as exc:
raise dimensionsValueError from exc
Expand Down
17 changes: 17 additions & 0 deletions tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ def testAdjustQuantum(self):
with self.assertRaises(ValueError):
connections.adjustQuantum(inputRefs)

def testDimensionCheck(self):
with self.assertRaises(TypeError):
class TestConnectionsWithBrokenDimensionsStr(pipeBase.PipelineTask, dimensions=("a")):
pass

with self.assertRaises(TypeError):
class TestConnectionsWithBrokenDimensionsIter(pipeBase.PipelineTask, dimensions=2):
pass

with self.assertRaises(TypeError):
pipeBase.connectionTypes.Output(Doc="mock doc", dimensions=("a"), name="output",
storageClass="mock")

with self.assertRaises(TypeError):
pipeBase.connectionTypes.Output(Doc="mock doc", dimensions=1, name="output",
storageClass="mock")


class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
pass
Expand Down