32 __all__ = [
"MapperTests"]
37 Generic tests of obs_* package mapper functionality. 39 In the subclasses's setUp(): 40 * Call setUp_mapper() to fill in required parameters. 49 metadata_output_path=None,
51 map_python_std_type=None,
53 map_storage_name=None,
57 test_config_metadata=True,
60 Set up the necessary variables for mapper tests. 66 full path to output repository (can be the same as data_dir input repository) 68 full path to the raw file referenced by dataIds['raw'] 70 dictionary keys that this mapper should contain 72 format list for the results portion of queryMetadata 73 queryMetadata : `tuple` of (`dict`, `tuple`) 74 dataIds and the results of calling them in queryMetadata 75 metadata_output_path : `str` 76 path to metadata output associated with dataIds['raw'] 77 map_python_type : `type` 78 full python type specification returned by the mapper for dataIds['raw'] 79 map_python_std_type : `type` 80 full python type specification returned by the mapper for dataIds['raw'] after standardization 82 C++ type specification returned by the mapper for dataIds['raw'] 83 map_storage_name : `str` 84 butler name for the storage type dataIds['raw'] 86 Name of the raw files returned by the mapper for dataIds['raw'] 88 value returned from mapper.getDefaultLevel 89 raw_levels : `tuple` of (`str`, `set` of `str`) 90 (level, expect) level and expected mapper return for mapper.getKeys('raw', level) 91 test_config_metadata : `bool` 92 Test persisted config and metadata? These tests may not be appropriate for test stand data. 100 'metadata_output_path',
102 'map_python_std_type',
108 'test_config_metadata',
110 MapperData = collections.namedtuple(
"MapperData", fields)
112 path_to_raw=path_to_raw,
114 query_format=query_format,
115 queryMetadata=queryMetadata,
116 metadata_output_path=metadata_output_path,
117 map_python_type=map_python_type,
118 map_python_std_type=map_python_std_type,
119 map_cpp_type=map_cpp_type,
120 map_storage_name=map_storage_name,
121 raw_filename=raw_filename,
122 default_level=default_level,
123 raw_levels=raw_levels,
124 test_config_metadata=test_config_metadata,
129 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
130 dataId = self.dataIds[
'raw']
131 butlerLocation = self.mapper.map(
"processCcd_config_filename", dataId)
132 self.assertEqual(butlerLocation.getPythonType(),
"lsst.pipe.tasks.processCcd.ProcessCcdConfig")
133 self.assertEqual(butlerLocation.getCppType(),
"Config")
134 self.assertEqual(butlerLocation.getStorageName(),
"ConfigStorage")
135 processCcd_path = os.path.join(
"config",
"processCcd.py")
136 self.assertEqual(self.mapper.root, butlerLocation.getStorage().root)
137 self.assertEqual(butlerLocation.getLocations(), [processCcd_path])
138 for k, v
in dataId.items():
139 self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
140 msg=
"Failed for key={}".
format(k))
144 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
145 dataId = self.dataIds[
'raw']
146 butlerLocation = self.mapper.map_processCcd_metadata(dataId)
147 self.assertEqual(butlerLocation.getPythonType(),
"lsst.daf.base.PropertySet")
148 self.assertEqual(butlerLocation.getCppType(),
"PropertySet")
149 self.assertEqual(butlerLocation.getStorageName(),
"YamlStorage")
150 self.assertEqual(butlerLocation.getLocations(), [self.
mapper_data.metadata_output_path])
151 for k, v
in dataId.items():
152 self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
153 msg=
"Failed for key={}".
format(k))
160 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
161 someKeys =
set([
'raw',
'processCcd_config',
'processCcd_metadata'])
162 self.assertTrue(
set(self.mapper.getDatasetTypes()).issuperset(someKeys))
166 result = self.mapper.getKeys(
"raw", level)
167 self.assertEqual(
set(result), expect, msg=
'Failed for level={}'.
format(level))
170 self.assertEqual(self.mapper.getDefaultLevel(), self.
mapper_data.default_level)
172 def _test_map(self, butlerLocation, dataId):
173 self.assertEqual(butlerLocation.getPythonType(), self.
mapper_data.map_python_type)
174 self.assertEqual(butlerLocation.getCppType(), self.
mapper_data.map_cpp_type)
175 self.assertEqual(butlerLocation.getStorageName(), self.
mapper_data.map_storage_name)
176 locationList = butlerLocation.getLocations()
177 self.assertEqual(len(locationList), 1)
178 fileName = os.path.basename(locationList[0])
179 self.assertEqual(fileName, self.
mapper_data.raw_filename)
180 for k, v
in dataId.items():
181 self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
182 msg=
"Failed for key={}".
format(k))
185 dataId = self.dataIds[
'raw']
186 location = self.mapper.map_raw(dataId)
190 self.log.
warn(
"""ButlerComposite datasets are not tested for mapper functions. Though 191 ButlerComposites duck type as ButlerLocations in some ways, they do not 192 share enough methods to be usefully tested by the same function. Note 193 there are tests of the objects in the package in which they are implemented.""")
196 location = self.mapper.map(
"raw", dataId)
202 Test expansion of incomplete information of the available data in this 203 obs package's testdata repo. 205 for query, expect
in self.
mapper_data.queryMetadata:
207 result = self.mapper.queryMetadata(
"raw", self.
mapper_data.query_format, query)
208 self.assertEqual(sorted(result), sorted(expect), msg=
"Failed for query={}".
format(query))
211 self.assertTrue(self.mapper.canStandardize(
"raw"))
212 self.assertFalse(self.mapper.canStandardize(
"camera"))
214 self.assertFalse(self.mapper.canStandardize(
"processCcd_config"))
215 self.assertFalse(self.mapper.canStandardize(
"processCcd_metadata"))
217 def _test_validate(self, dataId):
218 self.assertEqual(self.mapper.
validate(dataId), dataId)
def test_can_standardize(self)
def _test_validate(self, dataId)
daf::base::PropertySet * set
def test_get_dataset_types(self)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
def _test_map(self, butlerLocation, dataId)
def setUp_mapper(self, output=None, path_to_raw=None, keys=None, query_format=None, queryMetadata=None, metadata_output_path=None, map_python_type=None, map_python_std_type=None, map_cpp_type=None, map_storage_name=None, raw_filename=None, default_level=None, raw_levels=None, test_config_metadata=True)
def test_get_default_level(self)
def test_get_keys_raw(self)
def test_query_metadata(self)
def test_map_metadata_data(self)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
def test_map_config_data(self)