Coverage for tests/test_dataset.py: 41%

56 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-08-04 03:41 -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# 

23 

24import os 

25import shutil 

26import tempfile 

27import unittest 

28 

29import lsst.utils.tests 

30import lsst.daf.butler as dafButler 

31from lsst.ap.verify.dataset import Dataset 

32from lsst.ap.verify.testUtils import DataTestCase 

33 

34 

35class DatasetTestSuite(DataTestCase): 

36 

37 @classmethod 

38 def setUpClass(cls): 

39 super().setUpClass() 

40 

41 cls.obsPackage = 'obs_lsst' 

42 cls.camera = 'imsim' 

43 cls.gen3Camera = 'LSSTCam-imSim' 

44 

45 def setUp(self): 

46 self._testbed = Dataset(DatasetTestSuite.testDataset) 

47 

48 def testRepr(self): 

49 # Required to match constructor call 

50 self.assertEqual(repr(self._testbed), "Dataset(" + repr(self.testDataset) + ")") 

51 

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") 

57 

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 

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) 

68 

69 def _checkOutputGen3(self, repo): 

70 """Perform various integrity checks on a repository. 

71 

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()) 

82 

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') 

88 

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) 

95 

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') 

102 

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) 

111 

112 

113class MemoryTester(lsst.utils.tests.MemoryTestCase): 

114 pass 

115 

116 

117def setup_module(module): 

118 lsst.utils.tests.init() 

119 

120 

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()