MockStorageClass#
- class lsst.pipe.base.tests.mocks.MockStorageClass(original: StorageClass, factory: StorageClassFactory | None = None)#
Bases:
StorageClassA reimplementation of
lsst.daf.butler.StorageClassfor mock datasets.Parameters#
- original
StorageClass The original storage class.
- factory
StorageClassFactoryorNone, optional Storage class factory to use. If
Nonethe default factory is used.
Notes#
Each
MockStorageClassinstance corresponds to a real “original” storage class, with components and conversions that are mocks of the original’s components and conversions. Thepytypefor allMockStorageClassinstances isMockDataset.Attributes Summary
Return the components associated with this
StorageClass.Return derived components associated with
StorageClass.Methods Summary
Return all defined components.
can_convert(other)Return
Trueif this storage class can convert python types in the other storage class.coerce_type(incorrect)Coerce the supplied incorrect instance to the python type associated with this
StorageClass.get_or_register_mock(original[, factory])Return a mock storage class for the given original storage class, creating and registering it if necessary.
mock_dataset_refs(original_refs)Replace dataset references with versions that uses a mock storage class and dataset type name.
mock_dataset_type(original_type)Replace a dataset type with a version that uses a mock storage class and name.
unmock_dataset_refs(mock_refs)Replace dataset references with versions that do not use a mock storage class and dataset type name.
unmock_dataset_type(mock_type)Replace a mock dataset type with the original one it was created from.
Attributes Documentation
- components#
- derivedComponents#
Methods Documentation
- allComponents() Mapping[str, MockStorageClass]#
Return all defined components.
This mapping includes all the derived and read/write components for the corresponding storage class.
Returns#
- comp
dictof [str,StorageClass] The component name to storage class mapping.
- comp
- can_convert(other: StorageClass) bool#
Return
Trueif this storage class can convert python types in the other storage class.Parameters#
- other
StorageClass The storage class to check.
Returns#
- can
bool Trueif this storage class has a registered converter for the python type associated with the other storage class. That converter will convert the other python type to the one associated with this storage class.
- other
- coerce_type(incorrect: Any) Any#
Coerce the supplied incorrect instance to the python type associated with this
StorageClass.Parameters#
- incorrect
object An object that might be the incorrect type.
Returns#
- correct
object An object that matches the python type of this
StorageClass. Can be the same object as given. IfNone,Nonewill be returned.
Raises#
- TypeError
Raised if no conversion can be found.
- incorrect
- classmethod get_or_register_mock(original: str, factory: StorageClassFactory | None = None) MockStorageClass#
Return a mock storage class for the given original storage class, creating and registering it if necessary.
Parameters#
- original
str Name of the original storage class to be mocked.
- factory
StorageClassFactory, optional Storage class factory singleton instance.
Returns#
- mock
MockStorageClass New storage class that mocks
original.
- original
- static mock_dataset_refs(original_refs: Iterable[DatasetRef]) list[DatasetRef]#
Replace dataset references with versions that uses a mock storage class and dataset type name.
Parameters#
- original_refs
Iterable[lsst.daf.butler.DatasetRef] Original dataset references to be mocked.
Returns#
- mock_refs
list[lsst.daf.butler.DatasetRef] Mocked version of the dataset references, with dataset type name and storage class changed and everything else unchanged.
- original_refs
- static mock_dataset_type(original_type: DatasetType) DatasetType#
Replace a dataset type with a version that uses a mock storage class and name.
Parameters#
- original_type
lsst.daf.butler.DatasetType Original dataset type to be mocked.
Returns#
- mock_type
lsst.daf.butler.DatasetType A mock version of the dataset type, with name and storage class changed and everything else unchanged.
- original_type
- static unmock_dataset_refs(mock_refs: Iterable[DatasetRef]) list[DatasetRef]#
Replace dataset references with versions that do not use a mock storage class and dataset type name.
Parameters#
- mock_refs
Iterable[lsst.daf.butler.DatasetRef] Dataset references that use a mocked dataset type name and storage class.
Returns#
- original_refs
list[lsst.daf.butler.DatasetRef] The original dataset references.
- mock_refs
- static unmock_dataset_type(mock_type: DatasetType) DatasetType#
Replace a mock dataset type with the original one it was created from.
Parameters#
- mock_type
lsst.daf.butler.DatasetType A dataset type with a mocked name and storage class.
Returns#
- original_type
lsst.daf.butler.DatasetType The original dataset type.
- mock_type
- original