Skip to content

Commit

Permalink
Merge branch 'tickets/DM-26015'
Browse files Browse the repository at this point in the history
  • Loading branch information
natelust committed Jul 20, 2020
2 parents 169fecc + cdea846 commit 9c77118
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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

0 comments on commit 9c77118

Please sign in to comment.