Coverage for tests/test_dataset.py: 30%
Shortcuts 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
Shortcuts 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 = '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'))
63 self.assertEqual(self._testbed.calibLocation, os.path.join(root, 'calib'))
64 self.assertEqual(self._testbed.templateLocation, os.path.join(root, 'templates'))
65 self.assertEqual(self._testbed.refcatsLocation, os.path.join(root, 'refcats'))
67 def testObsPackage(self):
68 """Verify that a Dataset knows its associated obs package and camera.
69 """
70 self.assertEqual(self._testbed.obsPackage, DatasetTestSuite.obsPackage)
71 self.assertEqual(self._testbed.camera, DatasetTestSuite.camera)
72 self.assertEqual(self._testbed.instrument.getName(), DatasetTestSuite.gen3Camera)
74 def testOutput(self):
75 """Verify that a Dataset can create an output repository as desired.
76 """
77 testDir = tempfile.mkdtemp()
78 outputDir = os.path.join(testDir, 'goodOut')
79 calibRepoDir = outputDir
81 try:
82 self._testbed.makeCompatibleRepo(outputDir, calibRepoDir)
83 self.assertTrue(os.path.exists(outputDir), 'Output directory must exist.')
84 self.assertTrue(os.listdir(outputDir), 'Output directory must not be empty.')
85 self.assertTrue(os.path.exists(os.path.join(outputDir, '_mapper')) or
86 os.path.exists(os.path.join(outputDir, 'repositoryCfg.yaml')),
87 'Output directory must have a _mapper or repositoryCfg.yaml file.')
88 finally:
89 if os.path.exists(testDir):
90 shutil.rmtree(testDir, ignore_errors=True)
92 def testExistingOutput(self):
93 """Verify that a Dataset can handle pre-existing output directories,
94 including directories made by external code.
95 """
96 testDir = tempfile.mkdtemp()
97 outputDir = os.path.join(testDir, 'badOut')
98 calibRepoDir = outputDir
100 try:
101 os.makedirs(outputDir)
102 output = os.path.join(outputDir, 'foo.txt')
103 with open(output, 'w') as dummy:
104 dummy.write('This is a test!')
106 self._testbed.makeCompatibleRepo(outputDir, calibRepoDir)
107 self.assertTrue(os.path.exists(outputDir), 'Output directory must exist.')
108 self.assertTrue(os.listdir(outputDir), 'Output directory must not be empty.')
109 self.assertTrue(os.path.exists(os.path.join(outputDir, '_mapper')) or
110 os.path.exists(os.path.join(outputDir, 'repositoryCfg.yaml')),
111 'Output directory must have a _mapper or repositoryCfg.yaml file.')
112 finally:
113 if os.path.exists(testDir):
114 shutil.rmtree(testDir, ignore_errors=True)
116 def _checkOutputGen3(self, repo):
117 """Perform various integrity checks on a repository.
119 Parameters
120 ----------
121 repo : `str`
122 The repository to test. Currently only filesystem repositories
123 are supported.
124 """
125 self.assertTrue(os.path.exists(repo), 'Output directory must exist.')
126 # Call to Butler will fail if repo is corrupted
127 butler = dafButler.Butler(repo)
128 self.assertIn("LSSTCam-imSim/calib", butler.registry.queryCollections())
130 def testOutputGen3(self):
131 """Verify that a Dataset can create an output repository as desired.
132 """
133 testDir = tempfile.mkdtemp()
134 outputDir = os.path.join(testDir, 'goodOut')
136 try:
137 self._testbed.makeCompatibleRepoGen3(outputDir)
138 self._checkOutputGen3(outputDir)
139 finally:
140 if os.path.exists(testDir):
141 shutil.rmtree(testDir, ignore_errors=True)
143 def testExistingOutputGen3(self):
144 """Verify that a Dataset can handle pre-existing output directories,
145 including directories made by external code.
146 """
147 testDir = tempfile.mkdtemp()
148 outputDir = os.path.join(testDir, 'badOut')
150 try:
151 self._testbed.makeCompatibleRepoGen3(outputDir)
152 self._checkOutputGen3(outputDir)
153 self._testbed.makeCompatibleRepoGen3(outputDir)
154 self._checkOutputGen3(outputDir)
155 finally:
156 if os.path.exists(testDir):
157 shutil.rmtree(testDir, ignore_errors=True)
160class MemoryTester(lsst.utils.tests.MemoryTestCase):
161 pass
164def setup_module(module):
165 lsst.utils.tests.init()
168if __name__ == "__main__": 168 ↛ 169line 168 didn't jump to line 169, because the condition on line 168 was never true
169 lsst.utils.tests.init()
170 unittest.main()