Skip to content

Commit

Permalink
Reinstate defect ingestion test.
Browse files Browse the repository at this point in the history
The test was previously impossible because obs_test did not allow defect
ingestion, but _RepoStub doesn't know that.
  • Loading branch information
kfindeisen committed Jun 8, 2018
1 parent 3441df1 commit c070ee4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/lsst/ap/verify/ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _doIngestDefects(self, repo, calibRepo, defectTarball):
# TODO: clean up implementation after DM-5467 resolved
defectDir = os.path.join(calibRepo, "defects")
with tarfile.open(defectTarball, "r") as opened:
if opened.getNames():
if opened.getnames():
pathlib.Path(defectDir).mkdir(parents=True, exist_ok=True)
opened.extractall(defectDir)
else:
Expand Down
Binary file added tests/ingestion/defects.tar.gz
Binary file not shown.
18 changes: 16 additions & 2 deletions tests/test_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#

import os
import shutil
import glob
import tempfile
import argparse
import unittest
from collections import defaultdict
Expand Down Expand Up @@ -241,15 +243,18 @@ def setUpClass(cls):
]

def setUp(self):
# Unused by _ArgumentParserStub, but mandatory argument to _doIngest*
self._repo = self._calibRepo = 'foo'
# Mandatory argument to _doIngest*, used by _doIngestDefects to unpack tar
self._repo = self._calibRepo = tempfile.mkdtemp()

self._task = ingestion.DatasetIngestTask(config=IngestionTestSuite.config)
self._butler = _RepoStub()
self._task.dataIngester.repo = self._butler
self._task.calibIngester.repo = self._butler
self._task.defectIngester.repo = self._butler

def tearDown(self):
shutil.rmtree(self._repo, ignore_errors=True)

def testDataIngest(self):
"""Test that ingesting a science image adds it to a repository.
"""
Expand Down Expand Up @@ -280,6 +285,15 @@ def testCalibIngest(self):
# queryMetadata does not work on calibs
self.assertFalse(self._butler.datasetExists('flat', filter='z'))

def testDefectIngest(self):
"""Test that ingesting defects adds them to a repository.
"""
tarFile = os.path.join(IngestionTestSuite.testApVerifyData, 'defects.tar.gz')

self._task._doIngestDefects(self._repo, self._calibRepo, tarFile)

self.assertTrue(self._butler.datasetExists('defect'))

def testNoFileIngest(self):
"""Test that attempts to ingest nothing raise an exception.
"""
Expand Down

0 comments on commit c070ee4

Please sign in to comment.