Coverage for tests/test_dataset.py : 23%

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 testOutputGen3(self):
119 """Verify that a Dataset can create an output repository as desired.
120 """
121 testDir = tempfile.mkdtemp()
122 outputDir = os.path.join(testDir, 'goodOut')
124 try:
125 self._testbed.makeCompatibleRepoGen3(outputDir)
126 self.assertTrue(os.path.exists(outputDir), 'Output directory must exist.')
127 self.assertTrue(os.listdir(outputDir), 'Output directory must not be empty.')
128 self.assertTrue(os.path.exists(os.path.join(outputDir, 'butler.yaml')),
129 'Output directory must have a butler.yaml file.')
130 butler = dafButler.Butler(outputDir)
131 self.assertIn("LSST-ImSim/calib", butler.registry.queryCollections())
132 finally:
133 if os.path.exists(testDir):
134 shutil.rmtree(testDir, ignore_errors=True)
136 def testExistingOutputGen3(self):
137 """Verify that a Dataset can handle pre-existing output directories,
138 including directories made by external code.
139 """
140 testDir = tempfile.mkdtemp()
141 outputDir = os.path.join(testDir, 'badOut')
143 try:
144 os.makedirs(outputDir)
145 output = os.path.join(outputDir, 'foo.txt')
146 with open(output, 'w') as dummy:
147 dummy.write('This is a test!')
149 self._testbed.makeCompatibleRepoGen3(outputDir)
150 self.assertTrue(os.path.exists(outputDir), 'Output directory must exist.')
151 self.assertTrue(os.listdir(outputDir), 'Output directory must not be empty.')
152 self.assertTrue(os.path.exists(os.path.join(outputDir, 'butler.yaml')),
153 'Output directory must have a butler.yaml file.')
154 butler = dafButler.Butler(outputDir)
155 self.assertIn("LSST-ImSim/calib", butler.registry.queryCollections())
156 finally:
157 if os.path.exists(testDir):
158 shutil.rmtree(testDir, ignore_errors=True)
161class MemoryTester(lsst.utils.tests.MemoryTestCase):
162 pass
165def setup_module(module):
166 lsst.utils.tests.init()
169if __name__ == "__main__": 169 ↛ 170line 169 didn't jump to line 170, because the condition on line 169 was never true
170 lsst.utils.tests.init()
171 unittest.main()