Skip to content

Commit

Permalink
tests fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Mar 3, 2020
1 parent b0300ea commit 2d9efd8
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions python/lsst/obs/base/gen2to3/convert_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,19 @@ class ConvertGen2To3TestCase:
"""Names of the reference catalogs to query for the existence of in the
converted gen3 repo."""

collections = set()
"""Additional collections that should appear in the gen3 repo, beyond the
instrument name and any refcats, if ``refcats`` is non-empty above.
Typically the only additional one necessary would be 'skymaps'."""

def setUp(self):
self.gen3root = tempfile.mkdtemp()
self.gen2Butler = lsst.daf.persistence.Butler(root=self.gen2root, calibRoot=self.gen2calib)
# TODO: remove the path.join and getpackagedir once I'm done developing the bin.src version:
self.cmd = os.path.join(lsst.utils.getPackageDir("obs_base"), "bin.src/convert_gen2_repo_to_gen3.py")
self.collections.add(self.instrumentName)
if len(self.refcats) > 0:
self.collections.add("refcats")

def tearDown(self):
shutil.rmtree(self.gen3root, ignore_errors=True)
Expand Down Expand Up @@ -123,6 +131,7 @@ def check_raw(self, gen3Butler, exposure, detector):
# Check that we got an Exposure, but not what type; there is
# inconsistency between different obs packages.
self.assertIsInstance(gen3Exposure, lsst.afw.image.Exposure)
self.assertEqual(gen3Exposure.getInfo().getDetector().getId(), detector)
self.assertMaskedImagesEqual(gen2Exposure.maskedImage, gen3Exposure.maskedImage)

def check_calibs(self, calibName, calibIds, gen3Butler):
Expand All @@ -142,8 +151,12 @@ def check_calibs(self, calibName, calibIds, gen3Butler):
The Butler to use to get the data.
"""
for dataId in calibIds:
gen3Image = gen3Butler.get(calibName, dataId=dataId)
self.assertIsInstance(gen3Image, lsst.afw.image.ExposureF)
gen3Exposure = gen3Butler.get(calibName, dataId=dataId)
# TODO: how to test that we got the right detector?
# For DECam, this works and is a good check that we used the right Formatter.
# For HSC, the Exposure doesn't have an associated `Detector` object. Which is probably bad?
# self.assertEqual(gen3Exposure.getInfo().getDetector().getId(), dataId['detector'])
self.assertIsInstance(gen3Exposure, lsst.afw.image.ExposureF)

def check_defects(self, gen3Butler, detectors):
"""Test that we can get converted defects from the gen3 repo.
Expand All @@ -158,18 +171,13 @@ def check_refcat(self, gen3Butler):
"""Test that each expected refcat is in the gen3 repo."""
if len(self.refcats) > 0:
for refcat in self.refcats:
# TODO: we should be able to specify `collections='refcats'` here,
# but it appears the refcats aren't getting into any collection?
query = gen3Butler.registry.queryDatasets(refcat, collections=...) # collections='refcats')
query = gen3Butler.registry.queryDatasets(refcat, collections=['refcats'])
self.assertGreater(len(list(query)), 0,
msg=f"refcat={refcat} has no entries in collection 'refcats'.")

def check_collections(self, gen3Butler):
"""Test that the correct set of collections is in the gen3 repo."""
expected = set([self.instrumentName, "skymaps"])
if len(self.refcats) > 0:
expected.add("refcats")
self.assertEqual(expected, gen3Butler.registry.getAllCollections())
self.assertEqual(self.collections, gen3Butler.registry.getAllCollections())

def test_convert(self):
"""Test that raws are converted correctly.
Expand Down

0 comments on commit 2d9efd8

Please sign in to comment.