Coverage for tests/test_dataset.py : 26%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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 = 'LSST-ImSim'
45 def setUp(self):
46 self._testbed = Dataset(DatasetTestSuite.datasetKey)
48 def testDatasets(self):
49 """Verify that a Dataset knows its supported datasets.
50 """
51 datasets = Dataset.getSupportedDatasets()
52 self.assertIn(DatasetTestSuite.datasetKey, datasets) # assumed by other tests
54 def testBadDataset(self):
55 """Verify that Dataset construction fails gracefully on unsupported datasets.
56 """
57 with self.assertRaises(ValueError):
58 Dataset("TotallyBogusDataset")
60 def testDirectories(self):
61 """Verify that a Dataset reports the desired directory structure.
62 """
63 root = self._testbed.datasetRoot
64 self.assertEqual(self._testbed.rawLocation, os.path.join(root, 'raw'))
65 self.assertEqual(self._testbed.calibLocation, os.path.join(root, 'calib'))
66 self.assertEqual(self._testbed.templateLocation, os.path.join(root, 'templates'))
67 self.assertEqual(self._testbed.refcatsLocation, os.path.join(root, 'refcats'))
69 def testObsPackage(self):
70 """Verify that a Dataset knows its associated obs package and camera.
71 """
72 self.assertEqual(self._testbed.obsPackage, DatasetTestSuite.obsPackage)
73 self.assertEqual(self._testbed.camera, DatasetTestSuite.camera)
74 self.assertEqual(self._testbed.instrument.getName(), DatasetTestSuite.gen3Camera)
76 def testOutput(self):
77 """Verify that a Dataset can create an output repository as desired.
78 """
79 testDir = tempfile.mkdtemp()
80 outputDir = os.path.join(testDir, 'goodOut')
81 calibRepoDir = outputDir
83 try:
84 self._testbed.makeCompatibleRepo(outputDir, calibRepoDir)
85 self.assertTrue(os.path.exists(outputDir), 'Output directory must exist.')
86 self.assertTrue(os.listdir(outputDir), 'Output directory must not be empty.')
87 self.assertTrue(os.path.exists(os.path.join(outputDir, '_mapper')) or
88 os.path.exists(os.path.join(outputDir, 'repositoryCfg.yaml')),
89 'Output directory must have a _mapper or repositoryCfg.yaml file.')
90 finally:
91 if os.path.exists(testDir):
92 shutil.rmtree(testDir, ignore_errors=True)
94 def testExistingOutput(self):
95 """Verify that a Dataset can handle pre-existing output directories,
96 including directories made by external code.
97 """
98 testDir = tempfile.mkdtemp()
99 outputDir = os.path.join(testDir, 'badOut')
100 calibRepoDir = outputDir
102 try:
103 os.makedirs(outputDir)
104 output = os.path.join(outputDir, 'foo.txt')
105 with open(output, 'w') as dummy:
106 dummy.write('This is a test!')
108 self._testbed.makeCompatibleRepo(outputDir, calibRepoDir)
109 self.assertTrue(os.path.exists(outputDir), 'Output directory must exist.')
110 self.assertTrue(os.listdir(outputDir), 'Output directory must not be empty.')
111 self.assertTrue(os.path.exists(os.path.join(outputDir, '_mapper')) or
112 os.path.exists(os.path.join(outputDir, 'repositoryCfg.yaml')),
113 'Output directory must have a _mapper or repositoryCfg.yaml file.')
114 finally:
115 if os.path.exists(testDir):
116 shutil.rmtree(testDir, ignore_errors=True)
118 def _checkOutputGen3(self, repo):
119 """Perform various integrity checks on a repository.
121 Parameters
122 ----------
123 repo : `str`
124 The repository to test. Currently only filesystem repositories
125 are supported.
126 """
127 self.assertTrue(os.path.exists(repo), 'Output directory must exist.')
128 # Call to Butler will fail if repo is corrupted
129 butler = dafButler.Butler(repo)
130 self.assertIn("LSST-ImSim/calib", butler.registry.queryCollections())
132 def testOutputGen3(self):
133 """Verify that a Dataset can create an output repository as desired.
134 """
135 testDir = tempfile.mkdtemp()
136 outputDir = os.path.join(testDir, 'goodOut')
138 try:
139 self._testbed.makeCompatibleRepoGen3(outputDir)
140 self._checkOutputGen3(outputDir)
141 finally:
142 if os.path.exists(testDir):
143 shutil.rmtree(testDir, ignore_errors=True)
145 def testExistingOutputGen3(self):
146 """Verify that a Dataset can handle pre-existing output directories,
147 including directories made by external code.
148 """
149 testDir = tempfile.mkdtemp()
150 outputDir = os.path.join(testDir, 'badOut')
152 try:
153 self._testbed.makeCompatibleRepoGen3(outputDir)
154 self._checkOutputGen3(outputDir)
155 self._testbed.makeCompatibleRepoGen3(outputDir)
156 self._checkOutputGen3(outputDir)
157 finally:
158 if os.path.exists(testDir):
159 shutil.rmtree(testDir, ignore_errors=True)
162class MemoryTester(lsst.utils.tests.MemoryTestCase):
163 pass
166def setup_module(module):
167 lsst.utils.tests.init()
170if __name__ == "__main__": 170 ↛ 171line 170 didn't jump to line 171, because the condition on line 170 was never true
171 lsst.utils.tests.init()
172 unittest.main()