Coverage for tests/test_getPlotDatasetTypeNames.py: 36%

52 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-15 03:47 -0700

1# This file is part of analysis_tools. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21from __future__ import annotations 

22 

23import os 

24from unittest import TestCase, main 

25 

26import lsst.utils.tests 

27from lsst.analysis.tools.atools import SkyObjectHistPlot 

28from lsst.analysis.tools.interfaces import AnalysisBaseConfig 

29from lsst.analysis.tools.tasks.objectTableTractAnalysis import ObjectTableTractAnalysisConfig 

30from lsst.analysis.tools.tasks.reconstructor import getPlotDatasetTypeNames 

31from lsst.daf.butler import Butler, DatasetType 

32from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir 

33from lsst.pex.config import Config 

34 

35TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

36 

37 

38class TestGetPlotDatasetTypeNames(TestCase): 

39 """Test plot dataset type names are correctly queried by the butler.""" 

40 

41 def setUp(self): 

42 self.root = makeTestTempDir(TESTDIR) 

43 Butler.makeRepo(self.root) 

44 self.butler = Butler(self.root, run="test_run") 

45 # No dimensions in dataset type so we don't have to worry about 

46 # inserting dimension data or defining data IDs. 

47 self.datasetTypePlot = DatasetType( 

48 "plot1Label_config", 

49 dimensions=(), 

50 storageClass="Config", 

51 universe=self.butler.dimensions, 

52 ) 

53 self.butler.registry.registerDatasetType(self.datasetTypePlot) 

54 self.datasetTypePlot = DatasetType( 

55 "plot2Label_config", 

56 dimensions=(), 

57 storageClass="Config", 

58 universe=self.butler.dimensions, 

59 ) 

60 self.butler.registry.registerDatasetType(self.datasetTypePlot) 

61 self.datasetTypeBase = DatasetType( 

62 "baseLabel_config", 

63 dimensions=(), 

64 storageClass="Config", 

65 universe=self.butler.dimensions, 

66 ) 

67 self.butler.registry.registerDatasetType(self.datasetTypeBase) 

68 self.datasetTypeOther = DatasetType( 

69 "otherLabel_config", 

70 dimensions=(), 

71 storageClass="Config", 

72 universe=self.butler.dimensions, 

73 ) 

74 self.butler.registry.registerDatasetType(self.datasetTypeOther) 

75 

76 def tearDown(self): 

77 removeTestTempDir(self.root) 

78 

79 def testGetPlotNames(self): 

80 """Test that we can get plot dataset type names from a given collection 

81 in a butler. Two queries are made: one across the entire collection, 

82 and one for only dataset type names prefixed with a certain label. 

83 """ 

84 plot1Config = ObjectTableTractAnalysisConfig() 

85 plot1Config.plots.skyObjectHistPlot1 = SkyObjectHistPlot() 

86 plot2Config = ObjectTableTractAnalysisConfig() 

87 plot2Config.plots.skyObjectHistPlot2 = SkyObjectHistPlot() 

88 baseConfig = AnalysisBaseConfig() 

89 baseConfig.connections.outputName = "baseName" 

90 otherConfig = Config() 

91 _ = self.butler.put(plot1Config, "plot1Label_config") 

92 _ = self.butler.put(plot2Config, "plot2Label_config") 

93 _ = self.butler.put(baseConfig, "baseLabel_config") 

94 _ = self.butler.put(otherConfig, "otherLabel_config") 

95 plots_all = getPlotDatasetTypeNames(self.butler, "test_run") 

96 plots_label = getPlotDatasetTypeNames(self.butler, "test_run", "plot1Label") 

97 for plot in plots_all: 

98 self.assertIn("skyObjectHistPlot", plot) 

99 for plot in plots_label: 

100 self.assertIn("skyObjectHistPlot1", plot) 

101 

102 

103class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

104 pass 

105 

106 

107def setup_module(module): 

108 lsst.utils.tests.init() 

109 

110 

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

112 lsst.utils.tests.init() 

113 main()