Coverage for tests/test_nightReporter.py: 33%
61 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-26 03:25 -0700
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-26 03:25 -0700
1# This file is part of summit_extras.
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 <https://www.gnu.org/licenses/>.
22import unittest
23import tempfile
24from unittest import mock
26import lsst.utils.tests
28import matplotlib as mpl
29mpl.use('Agg')
31from lsst.summit.extras.nightReport import NightReporter, loadReport, saveReport # noqa: E402
32import lsst.summit.utils.butlerUtils as butlerUtils # noqa: E402
35class NightReporterTestCase(lsst.utils.tests.TestCase):
37 @classmethod
38 def setUpClass(cls):
39 try:
40 cls.butler = butlerUtils.makeDefaultLatissButler()
41 except FileNotFoundError:
42 raise unittest.SkipTest("Skipping tests that require the LATISS butler repo.")
44 cls.dayObs = 20200314 # has 377 images and data also exists on the TTS & summit
46 # Do the init in setUpClass because this takes about 35s for 20200314
47 cls.reporter = NightReporter(cls.dayObs)
48 # number of images isn't necessarily the same as the number for the
49 # the dayObs in the registry becacuse of the test stands/summit
50 # having partial data, so get the number of images from the length
51 # of the scraped data. Not ideal, but best that can be done due to
52 # only having partial days in the test datasets.
53 cls.nImages = len(cls.reporter.data.keys())
55 def test_saveAndLoad(self):
56 """Test that a NightReporter can save itself, and be loaded back.
57 """
58 writeDir = tempfile.mkdtemp()
59 saveReport(self.reporter, writeDir)
60 loaded = loadReport(writeDir, self.dayObs)
61 self.assertIsInstance(loaded, lsst.summit.extras.nightReport.NightReporter)
62 self.assertGreaterEqual(len(loaded.data), 1)
63 self.assertEqual(loaded.dayObs, self.dayObs)
65 def test_printObsTable(self):
66 """Test that a the printObsTable() method prints out the correct
67 number of lines.
68 """
69 with mock.patch('sys.stdout') as fake_stdout:
70 self.reporter.printObsTable()
72 # newline for each row plus header
73 self.assertEqual(len(fake_stdout.mock_calls), 2*(self.nImages+1))
75 tailNumber = 20
76 nLines = min(self.nImages, tailNumber) # test stands have very few images on some days
77 with mock.patch('sys.stdout') as fake_stdout:
78 self.reporter.printObsTable(tailNumber=tailNumber)
79 self.assertEqual(len(fake_stdout.mock_calls), 2*(nLines+1))
81 def test_plotPerObjectAirMass(self):
82 """Test that a the per-object airmass plots runs.
83 """
84 # We assume matplotlib is making plots, so just check that these
85 # don't crash.
87 # Default plotting:
88 self.reporter.plotPerObjectAirMass()
89 # plot with only one object as a str not a list of str
90 self.reporter.plotPerObjectAirMass(objects=self.reporter.stars[0])
91 # plot with first two objects as a list
92 self.reporter.plotPerObjectAirMass(objects=self.reporter.stars[0:2])
93 # flip y axis option
94 self.reporter.plotPerObjectAirMass(airmassOneAtTop=True)
95 # flip and select stars
96 self.reporter.plotPerObjectAirMass(objects=self.reporter.stars[0], airmassOneAtTop=True) # both
98 def test_makePolarPlotForObjects(self):
99 """Test that a the polar coverage plotting code runs.
100 """
101 # We assume matplotlib is making plots, so just check that these
102 # don't crash.
104 # test the default case
105 self.reporter.makePolarPlotForObjects()
106 # plot with only one object as a str not a list of str
107 self.reporter.makePolarPlotForObjects(objects=self.reporter.stars[0])
108 # plot with first two objects as a list
109 self.reporter.makePolarPlotForObjects(objects=self.reporter.stars[0:2])
110 # test turning lines off
111 self.reporter.makePolarPlotForObjects(objects=self.reporter.stars[0:2], withLines=False)
113 def test_calcShutterOpenEfficiency(self):
114 efficiency = self.reporter.calcShutterOpenEfficiency()
115 self.assertGreater(efficiency, 0)
116 self.assertLessEqual(efficiency, 1)
118 def test_internals(self):
119 starsFromGetter = self.reporter.getObservedObjects()
120 self.assertIsInstance(starsFromGetter, list)
121 self.assertSetEqual(set(starsFromGetter), set(self.reporter.stars))
123 # check the internal color map has the right number of items
124 self.assertEqual(len(self.reporter.cMap), len(starsFromGetter))
127class TestMemory(lsst.utils.tests.MemoryTestCase):
128 pass
131def setup_module(module):
132 lsst.utils.tests.init()
135if __name__ == "__main__": 135 ↛ 136line 135 didn't jump to line 136, because the condition on line 135 was never true
136 lsst.utils.tests.init()
137 unittest.main()