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
69 full path to the raw file referenced by dataIds['raw']
71 dictionary keys that this mapper should contain
73 format list for the results portion of queryMetadata
74 queryMetadata : `tuple` of (`dict`, `tuple`)
75 dataIds and the results of calling them in queryMetadata
76 metadata_output_path : `str`
77 path to metadata output associated with dataIds['raw']
78 map_python_type : `type`
79 full python type specification returned by the mapper for
81 map_python_std_type : `type`
82 full python type specification returned by the mapper for
83 dataIds['raw'] after standardization
85 C++ type specification returned by the mapper for dataIds['raw']
86 map_storage_name : `str`
87 butler name for the storage type dataIds['raw']
89 Name of the raw files returned by the mapper for dataIds['raw']
91 value returned from mapper.getDefaultLevel
92 raw_levels : `tuple` of (`str`, `set` of `str`)
93 (level, expect) level and expected mapper return for
94 mapper.getKeys('raw', level)
95 test_config_metadata : `bool`
96 Test persisted config and metadata? These tests may not be
97 appropriate for test stand data. Defaults to True.
104 'metadata_output_path',
106 'map_python_std_type',
112 'test_config_metadata',
114 MapperData = collections.namedtuple(
"MapperData", fields)
116 path_to_raw=path_to_raw,
118 query_format=query_format,
119 queryMetadata=queryMetadata,
120 metadata_output_path=metadata_output_path,
121 map_python_type=map_python_type,
122 map_python_std_type=map_python_std_type,
123 map_cpp_type=map_cpp_type,
124 map_storage_name=map_storage_name,
125 raw_filename=raw_filename,
126 default_level=default_level,
127 raw_levels=raw_levels,
128 test_config_metadata=test_config_metadata,
132 if not self.
mapper_datamapper_data.test_config_metadata:
133 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
134 dataId = self.dataIds[
'raw']
135 butlerLocation = self.mapper.map(
"processCcd_config_filename", dataId)
136 self.assertEqual(butlerLocation.getPythonType(),
"lsst.pipe.tasks.processCcd.ProcessCcdConfig")
137 self.assertEqual(butlerLocation.getCppType(),
"Config")
138 self.assertEqual(butlerLocation.getStorageName(),
"ConfigStorage")
139 processCcd_path = os.path.join(
"config",
"processCcd.py")
140 self.assertEqual(self.mapper.root, butlerLocation.getStorage().root)
141 self.assertEqual(butlerLocation.getLocations(), [processCcd_path])
142 for k, v
in dataId.items():
143 self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
144 msg=
"Failed for key={}".
format(k))
147 if not self.
mapper_datamapper_data.test_config_metadata:
148 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
149 dataId = self.dataIds[
'raw']
150 butlerLocation = self.mapper.map_processCcd_metadata(dataId)
151 self.assertEqual(butlerLocation.getPythonType(),
"lsst.daf.base.PropertySet")
152 self.assertEqual(butlerLocation.getCppType(),
"PropertySet")
153 self.assertEqual(butlerLocation.getStorageName(),
"YamlStorage")
154 self.assertEqual(butlerLocation.getLocations(), [self.
mapper_datamapper_data.metadata_output_path])
155 for k, v
in dataId.items():
156 self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
157 msg=
"Failed for key={}".
format(k))
163 if not self.
mapper_datamapper_data.test_config_metadata:
164 self.skipTest(
'Skipping %s as requested' % (inspect.currentframe().f_code.co_name))
165 someKeys =
set([
'raw',
'processCcd_config',
'processCcd_metadata'])
166 self.assertTrue(
set(self.mapper.getDatasetTypes()).issuperset(someKeys))
169 for level, expect
in self.
mapper_datamapper_data.raw_levels:
170 result = self.mapper.getKeys(
"raw", level)
171 self.assertEqual(
set(result), expect, msg=
'Failed for level={}'.
format(level))
174 self.assertEqual(self.mapper.getDefaultLevel(), self.
mapper_datamapper_data.default_level)
176 def _test_map(self, butlerLocation, dataId):
177 self.assertEqual(butlerLocation.getPythonType(), self.
mapper_datamapper_data.map_python_type)
178 self.assertEqual(butlerLocation.getCppType(), self.
mapper_datamapper_data.map_cpp_type)
179 self.assertEqual(butlerLocation.getStorageName(), self.
mapper_datamapper_data.map_storage_name)
180 locationList = butlerLocation.getLocations()
181 self.assertEqual(len(locationList), 1)
182 fileName = os.path.basename(locationList[0])
183 self.assertEqual(fileName, self.
mapper_datamapper_data.raw_filename)
184 for k, v
in dataId.items():
185 self.assertEqual(butlerLocation.getAdditionalData().getScalar(k), v,
186 msg=
"Failed for key={}".
format(k))
189 dataId = self.dataIds[
'raw']
190 location = self.mapper.map_raw(dataId)
192 self.
_test_map_test_map(location, dataId)
194 self.log.
warn(
"""ButlerComposite datasets are not tested for mapper functions. Though
195 ButlerComposites duck type as ButlerLocations in some ways, they do not
196 share enough methods to be usefully tested by the same function. Note
197 there are tests of the objects in the package in which they are implemented.""")
200 location = self.mapper.map(
"raw", dataId)
202 self.
_test_map_test_map(location, dataId)
206 Test expansion of incomplete information of the available data in this
207 obs package's testdata repo.
209 for query, expect
in self.
mapper_datamapper_data.queryMetadata:
212 result = self.mapper.queryMetadata(
"raw", self.
mapper_datamapper_data.query_format, query)
213 self.assertEqual(sorted(result), sorted(expect), msg=
"Failed for query={}".
format(query))
216 self.assertTrue(self.mapper.canStandardize(
"raw"))
217 self.assertFalse(self.mapper.canStandardize(
"camera"))
218 if not self.
mapper_datamapper_data.test_config_metadata:
219 self.assertFalse(self.mapper.canStandardize(
"processCcd_config"))
220 self.assertFalse(self.mapper.canStandardize(
"processCcd_metadata"))
222 def _test_validate(self, dataId):
223 self.assertEqual(self.mapper.
validate(dataId), dataId)
228 self.
_test_validate_test_validate({
'visit': 3,
'filter':
'g',
'tract': 4})
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_map_config_data(self)
def test_get_dataset_types(self)
def test_can_standardize(self)
def test_get_default_level(self)
def _test_validate(self, dataId)
def _test_map(self, butlerLocation, dataId)
def test_map_metadata_data(self)
def test_query_metadata(self)
def test_get_keys_raw(self)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
daf::base::PropertySet * set