Coverage for tests/test_dataset.py: 38%
56 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-18 03:30 -0700
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-18 03:30 -0700
1#
2# This file is part of ap_verify.
3#
4# Developed for the LSST Data Management System.
5# This product includes software developed by the LSST Project
6# (http://www.lsst.org).
7# See the COPYRIGHT file at the top-level directory of this distribution
8# for details of code ownership.
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
24import os
25import shutil
26import tempfile
27import unittest
29import lsst.utils.tests
30import lsst.daf.butler as dafButler
31from lsst.ap.verify.dataset import Dataset
32from lsst.ap.verify.testUtils import DataTestCase
35class DatasetTestSuite(DataTestCase):
37 @classmethod
38 def setUpClass(cls):
39 super().setUpClass()
41 cls.obsPackage = 'obs_lsst'
42 cls.camera = 'imsim'
43 cls.gen3Camera = 'LSSTCam-imSim'
45 def setUp(self):
46 self._testbed = Dataset(DatasetTestSuite.testDataset)
48 def testRepr(self):
49 # Required to match constructor call
50 self.assertEqual(repr(self._testbed), "Dataset(" + repr(self.testDataset) + ")")
52 def testBadDataset(self):
53 """Verify that Dataset construction fails gracefully on nonexistent datasets.
54 """
55 with self.assertRaises(ValueError):
56 Dataset("ap_verify_totally_bogus")
58 def testDirectories(self):
59 """Verify that a Dataset reports the desired directory structure.
60 """
61 root = self._testbed.datasetRoot
62 self.assertEqual(self._testbed.rawLocation, os.path.join(root, 'raw'))
64 def testObsPackage(self):
65 """Verify that a Dataset knows its associated obs package and camera.
66 """
67 self.assertEqual(self._testbed.instrument.getName(), DatasetTestSuite.gen3Camera)
69 def _checkOutputGen3(self, repo):
70 """Perform various integrity checks on a repository.
72 Parameters
73 ----------
74 repo : `str`
75 The repository to test. Currently only filesystem repositories
76 are supported.
77 """
78 self.assertTrue(os.path.exists(repo), 'Output directory must exist.')
79 # Call to Butler will fail if repo is corrupted
80 butler = dafButler.Butler(repo)
81 self.assertIn("LSSTCam-imSim/calib", butler.registry.queryCollections())
83 def testOutputGen3(self):
84 """Verify that a Dataset can create an output repository as desired.
85 """
86 testDir = tempfile.mkdtemp()
87 outputDir = os.path.join(testDir, 'goodOut')
89 try:
90 self._testbed.makeCompatibleRepoGen3(outputDir)
91 self._checkOutputGen3(outputDir)
92 finally:
93 if os.path.exists(testDir):
94 shutil.rmtree(testDir, ignore_errors=True)
96 def testExistingOutputGen3(self):
97 """Verify that a Dataset can handle pre-existing output directories,
98 including directories made by external code.
99 """
100 testDir = tempfile.mkdtemp()
101 outputDir = os.path.join(testDir, 'badOut')
103 try:
104 self._testbed.makeCompatibleRepoGen3(outputDir)
105 self._checkOutputGen3(outputDir)
106 self._testbed.makeCompatibleRepoGen3(outputDir)
107 self._checkOutputGen3(outputDir)
108 finally:
109 if os.path.exists(testDir):
110 shutil.rmtree(testDir, ignore_errors=True)
113class MemoryTester(lsst.utils.tests.MemoryTestCase):
114 pass
117def setup_module(module):
118 lsst.utils.tests.init()
121if __name__ == "__main__": 121 ↛ 122line 121 didn't jump to line 122, because the condition on line 121 was never true
122 lsst.utils.tests.init()
123 unittest.main()