LSST Applications  22.0.1,22.0.1+01bcf6a671,22.0.1+046ee49490,22.0.1+05c7de27da,22.0.1+0c6914dbf6,22.0.1+1220d50b50,22.0.1+12fd109e95,22.0.1+1a1dd69893,22.0.1+1c910dc348,22.0.1+1ef34551f5,22.0.1+30170c3d08,22.0.1+39153823fd,22.0.1+611137eacc,22.0.1+771eb1e3e8,22.0.1+94e66cc9ed,22.0.1+9a075d06e2,22.0.1+a5ff6e246e,22.0.1+a7db719c1a,22.0.1+ba0d97e778,22.0.1+bfe1ee9056,22.0.1+c4e1e0358a,22.0.1+cc34b8281e,22.0.1+d640e2c0fa,22.0.1+d72a2e677a,22.0.1+d9a6b571bd,22.0.1+e485e9761b,22.0.1+ebe8d3385e
LSST Data Management Base Package
Functions
lsst.pipe.base.testUtils Namespace Reference

Functions

def makeQuantum (task, butler, dataId, ioDataIds)
 
def runTestQuantum (task, butler, quantum, mockRun=True)
 
def assertValidOutput (task, result)
 
def assertValidInitOutput (task)
 
def getInitInputs (butler, config)
 

Function Documentation

◆ assertValidInitOutput()

def lsst.pipe.base.testUtils.assertValidInitOutput (   task)
Test that a constructed task conforms to its own init-connections.

Parameters
----------
task : `lsst.pipe.base.PipelineTask`
    The task whose connections need validation.

Raises
------
AssertionError:
    Raised if ``task`` does not have the state expected from ``task's``
    connections.

Definition at line 315 of file testUtils.py.

315 def assertValidInitOutput(task):
316  """Test that a constructed task conforms to its own init-connections.
317 
318  Parameters
319  ----------
320  task : `lsst.pipe.base.PipelineTask`
321  The task whose connections need validation.
322 
323  Raises
324  ------
325  AssertionError:
326  Raised if ``task`` does not have the state expected from ``task's``
327  connections.
328  """
329  connections = task.config.ConnectionsClass(config=task.config)
330 
331  for name in connections.initOutputs:
332  connection = connections.__getattribute__(name)
333  _assertAttributeMatchesConnection(task, name, connection)
334 
335 
def assertValidInitOutput(task)
Definition: testUtils.py:315

◆ assertValidOutput()

def lsst.pipe.base.testUtils.assertValidOutput (   task,
  result 
)
Test that the output of a call to ``run`` conforms to its own
connections.

Parameters
----------
task : `lsst.pipe.base.PipelineTask`
    The task whose connections need validation. This is a fully-configured
    task object to support features such as optional outputs.
result : `lsst.pipe.base.Struct`
    A result object produced by calling ``task.run``.

Raises
------
AssertionError:
    Raised if ``result`` does not match what's expected from ``task's``
    connections.

Definition at line 290 of file testUtils.py.

290 def assertValidOutput(task, result):
291  """Test that the output of a call to ``run`` conforms to its own
292  connections.
293 
294  Parameters
295  ----------
296  task : `lsst.pipe.base.PipelineTask`
297  The task whose connections need validation. This is a fully-configured
298  task object to support features such as optional outputs.
299  result : `lsst.pipe.base.Struct`
300  A result object produced by calling ``task.run``.
301 
302  Raises
303  ------
304  AssertionError:
305  Raised if ``result`` does not match what's expected from ``task's``
306  connections.
307  """
308  connections = task.config.ConnectionsClass(config=task.config)
309 
310  for name in connections.outputs:
311  connection = connections.__getattribute__(name)
312  _assertAttributeMatchesConnection(result, name, connection)
313 
314 
def assertValidOutput(task, result)
Definition: testUtils.py:290

◆ getInitInputs()

def lsst.pipe.base.testUtils.getInitInputs (   butler,
  config 
)
Return the initInputs object that would have been passed to a
`~lsst.pipe.base.PipelineTask` constructor.

Parameters
----------
butler : `lsst.daf.butler.Butler`
    The repository to search for input datasets. Must have
    pre-configured collections.
config : `lsst.pipe.base.PipelineTaskConfig`
    The config for the task to be constructed.

Returns
-------
initInputs : `dict` [`str`]
    A dictionary of objects in the format of the ``initInputs`` parameter
    to `lsst.pipe.base.PipelineTask`.

Definition at line 336 of file testUtils.py.

336 def getInitInputs(butler, config):
337  """Return the initInputs object that would have been passed to a
338  `~lsst.pipe.base.PipelineTask` constructor.
339 
340  Parameters
341  ----------
342  butler : `lsst.daf.butler.Butler`
343  The repository to search for input datasets. Must have
344  pre-configured collections.
345  config : `lsst.pipe.base.PipelineTaskConfig`
346  The config for the task to be constructed.
347 
348  Returns
349  -------
350  initInputs : `dict` [`str`]
351  A dictionary of objects in the format of the ``initInputs`` parameter
352  to `lsst.pipe.base.PipelineTask`.
353  """
354  connections = config.connections.ConnectionsClass(config=config)
355  initInputs = {}
356  for name in connections.initInputs:
357  attribute = getattr(connections, name)
358  # Get full dataset type to check for consistency problems
359  dsType = DatasetType(attribute.name, butler.registry.dimensions.extract(set()),
360  attribute.storageClass)
361  # All initInputs have empty data IDs
362  initInputs[name] = butler.get(dsType)
363 
364  return initInputs
daf::base::PropertySet * set
Definition: fits.cc:912
def getInitInputs(butler, config)
Definition: testUtils.py:336

◆ makeQuantum()

def lsst.pipe.base.testUtils.makeQuantum (   task,
  butler,
  dataId,
  ioDataIds 
)
Create a Quantum for a particular data ID(s).

Parameters
----------
task : `lsst.pipe.base.PipelineTask`
    The task whose processing the quantum represents.
butler : `lsst.daf.butler.Butler`
    The collection the quantum refers to.
dataId: any data ID type
    The data ID of the quantum. Must have the same dimensions as
    ``task``'s connections class.
ioDataIds : `collections.abc.Mapping` [`str`]
    A mapping keyed by input/output names. Values must be data IDs for
    single connections and sequences of data IDs for multiple connections.

Returns
-------
quantum : `lsst.daf.butler.Quantum`
    A quantum for ``task``, when called with ``dataIds``.

Definition at line 40 of file testUtils.py.

40 def makeQuantum(task, butler, dataId, ioDataIds):
41  """Create a Quantum for a particular data ID(s).
42 
43  Parameters
44  ----------
45  task : `lsst.pipe.base.PipelineTask`
46  The task whose processing the quantum represents.
47  butler : `lsst.daf.butler.Butler`
48  The collection the quantum refers to.
49  dataId: any data ID type
50  The data ID of the quantum. Must have the same dimensions as
51  ``task``'s connections class.
52  ioDataIds : `collections.abc.Mapping` [`str`]
53  A mapping keyed by input/output names. Values must be data IDs for
54  single connections and sequences of data IDs for multiple connections.
55 
56  Returns
57  -------
58  quantum : `lsst.daf.butler.Quantum`
59  A quantum for ``task``, when called with ``dataIds``.
60  """
61  connections = task.config.ConnectionsClass(config=task.config)
62 
63  try:
64  inputs = defaultdict(list)
65  outputs = defaultdict(list)
66  for name in itertools.chain(connections.inputs, connections.prerequisiteInputs):
67  connection = connections.__getattribute__(name)
68  _checkDataIdMultiplicity(name, ioDataIds[name], connection.multiple)
69  ids = _normalizeDataIds(ioDataIds[name])
70  for id in ids:
71  ref = _refFromConnection(butler, connection, id)
72  inputs[ref.datasetType].append(ref)
73  for name in connections.outputs:
74  connection = connections.__getattribute__(name)
75  _checkDataIdMultiplicity(name, ioDataIds[name], connection.multiple)
76  ids = _normalizeDataIds(ioDataIds[name])
77  for id in ids:
78  ref = _refFromConnection(butler, connection, id)
79  outputs[ref.datasetType].append(ref)
80  quantum = Quantum(taskClass=type(task),
81  dataId=dataId,
82  inputs=inputs,
83  outputs=outputs)
84  return quantum
85  except KeyError as e:
86  raise ValueError("Mismatch in input data.") from e
87 
88 
table::Key< int > type
Definition: Detector.cc:163
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
def makeQuantum(task, butler, dataId, ioDataIds)
Definition: testUtils.py:40

◆ runTestQuantum()

def lsst.pipe.base.testUtils.runTestQuantum (   task,
  butler,
  quantum,
  mockRun = True 
)
Run a PipelineTask on a Quantum.

Parameters
----------
task : `lsst.pipe.base.PipelineTask`
    The task to run on the quantum.
butler : `lsst.daf.butler.Butler`
    The collection to run on.
quantum : `lsst.daf.butler.Quantum`
    The quantum to run.
mockRun : `bool`
    Whether or not to replace ``task``'s ``run`` method. The default of
    `True` is recommended unless ``run`` needs to do real work (e.g.,
    because the test needs real output datasets).

Returns
-------
run : `unittest.mock.Mock` or `None`
    If ``mockRun`` is set, the mock that replaced ``run``. This object can
    be queried for the arguments ``runQuantum`` passed to ``run``.

Definition at line 214 of file testUtils.py.

214 def runTestQuantum(task, butler, quantum, mockRun=True):
215  """Run a PipelineTask on a Quantum.
216 
217  Parameters
218  ----------
219  task : `lsst.pipe.base.PipelineTask`
220  The task to run on the quantum.
221  butler : `lsst.daf.butler.Butler`
222  The collection to run on.
223  quantum : `lsst.daf.butler.Quantum`
224  The quantum to run.
225  mockRun : `bool`
226  Whether or not to replace ``task``'s ``run`` method. The default of
227  `True` is recommended unless ``run`` needs to do real work (e.g.,
228  because the test needs real output datasets).
229 
230  Returns
231  -------
232  run : `unittest.mock.Mock` or `None`
233  If ``mockRun`` is set, the mock that replaced ``run``. This object can
234  be queried for the arguments ``runQuantum`` passed to ``run``.
235  """
236  _resolveTestQuantumInputs(butler, quantum)
237  butlerQc = ButlerQuantumContext(butler, quantum)
238  connections = task.config.ConnectionsClass(config=task.config)
239  inputRefs, outputRefs = connections.buildDatasetRefs(quantum)
240  if mockRun:
241  with unittest.mock.patch.object(task, "run") as mock, \
242  unittest.mock.patch("lsst.pipe.base.ButlerQuantumContext.put"):
243  task.runQuantum(butlerQc, inputRefs, outputRefs)
244  return mock
245  else:
246  task.runQuantum(butlerQc, inputRefs, outputRefs)
247  return None
248 
249 
def runTestQuantum(task, butler, quantum, mockRun=True)
Definition: testUtils.py:214