Hide keyboard shortcuts

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# 

23 

24import os 

25import shutil 

26import tempfile 

27import unittest 

28 

29import lsst.utils.tests 

30from lsst.ap.verify.dataset import Dataset 

31from lsst.ap.verify.testUtils import DataTestCase 

32 

33 

34class DatasetTestSuite(DataTestCase): 

35 

36 @classmethod 

37 def setUpClass(cls): 

38 super().setUpClass() 

39 

40 cls.obsPackage = 'obs_test' 

41 cls.camera = 'test' 

42 

43 def setUp(self): 

44 self._testbed = Dataset(DatasetTestSuite.datasetKey) 

45 

46 def testDatasets(self): 

47 """Verify that a Dataset knows its supported datasets. 

48 """ 

49 datasets = Dataset.getSupportedDatasets() 

50 self.assertIn(DatasetTestSuite.datasetKey, datasets) # assumed by other tests 

51 

52 def testBadDataset(self): 

53 """Verify that Dataset construction fails gracefully on unsupported datasets. 

54 """ 

55 with self.assertRaises(ValueError): 

56 Dataset("TotallyBogusDataset") 

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

66 

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 

73 def testOutput(self): 

74 """Verify that a Dataset can create an output repository as desired. 

75 """ 

76 testDir = tempfile.mkdtemp() 

77 outputDir = os.path.join(testDir, 'goodOut') 

78 calibRepoDir = outputDir 

79 

80 try: 

81 self._testbed.makeCompatibleRepo(outputDir, calibRepoDir) 

82 self.assertTrue(os.path.exists(outputDir), 'Output directory must exist.') 

83 self.assertTrue(os.listdir(outputDir), 'Output directory must not be empty.') 

84 self.assertTrue(os.path.exists(os.path.join(outputDir, '_mapper')) or 

85 os.path.exists(os.path.join(outputDir, 'repositoryCfg.yaml')), 

86 'Output directory must have a _mapper or repositoryCfg.yaml file.') 

87 finally: 

88 if os.path.exists(testDir): 

89 shutil.rmtree(testDir, ignore_errors=True) 

90 

91 def testExistingOutput(self): 

92 """Verify that a Dataset can handle pre-existing output directories, 

93 including directories made by external code. 

94 """ 

95 testDir = tempfile.mkdtemp() 

96 outputDir = os.path.join(testDir, 'badOut') 

97 calibRepoDir = outputDir 

98 

99 try: 

100 os.makedirs(outputDir) 

101 output = os.path.join(outputDir, 'foo.txt') 

102 with open(output, 'w') as dummy: 

103 dummy.write('This is a test!') 

104 

105 self._testbed.makeCompatibleRepo(outputDir, calibRepoDir) 

106 self.assertTrue(os.path.exists(outputDir), 'Output directory must exist.') 

107 self.assertTrue(os.listdir(outputDir), 'Output directory must not be empty.') 

108 self.assertTrue(os.path.exists(os.path.join(outputDir, '_mapper')) or 

109 os.path.exists(os.path.join(outputDir, 'repositoryCfg.yaml')), 

110 'Output directory must have a _mapper or repositoryCfg.yaml file.') 

111 finally: 

112 if os.path.exists(testDir): 

113 shutil.rmtree(testDir, ignore_errors=True) 

114 

115 

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

117 pass 

118 

119 

120def setup_module(module): 

121 lsst.utils.tests.init() 

122 

123 

124if __name__ == "__main__": 124 ↛ 125line 124 didn't jump to line 125, because the condition on line 124 was never true

125 lsst.utils.tests.init() 

126 unittest.main()