Coverage for tests/test_skyBotEphemerisQuery.py: 39%

46 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-06 03:56 -0700

1# This file is part of ap_association. 

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/>. 

21 

22from unittest.mock import patch 

23import numpy as np 

24import os 

25import pandas as pd 

26import unittest 

27 

28import lsst.ap.association.skyBotEphemerisQuery as ephQ 

29import lsst.daf.base as dafBase 

30import lsst.geom as geom 

31import lsst.afw.image as afwImage 

32import lsst.pipe.base as pipeBase 

33import lsst.utils.tests 

34 

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

36 

37 

38class TestSkyBotEphemerisQuery(unittest.TestCase): 

39 

40 def setUp(self): 

41 super().setUp() 

42 

43 # Explicit date calculation to avoid errors from misuse of time libraries. 

44 mjd = 57071.0 

45 self.utc_jd = mjd + 2_400_000.5 - 35.0 / (24.0 * 60.0 * 60.0) 

46 

47 self.visitId = 42 

48 self.visitInfo = afwImage.VisitInfo( 

49 # Incomplete VisitInfo; Python constructor allows any value to 

50 # be defaulted. 

51 exposureTime=30.0, 

52 darkTime=3.0, 

53 date=dafBase.DateTime(mjd, system=dafBase.DateTime.MJD), 

54 boresightRaDec=geom.SpherePoint(0.0, 0.0, geom.degrees), 

55 ) 

56 

57 def test_skyBotConeSearch(self): 

58 """Test that our parsing of SkyBot return data succeeds and produces 

59 consistent hashed dataIds. 

60 """ 

61 def requestReplace(input1, input2): 

62 """Junk wrapper for replacing the external internal call with an 

63 internel data load. 

64 """ 

65 with open(os.path.join(TESTDIR, 

66 "data", 

67 "testSSObjects.txt"), 

68 "r") as f: 

69 outputText = f.read() 

70 return pipeBase.Struct(text=outputText) 

71 with patch('lsst.ap.association.skyBotEphemerisQuery.requests.request', 

72 new=requestReplace): 

73 ephTask = ephQ.SkyBotEphemerisQueryTask() 

74 testOut = ephTask._skybotConeSearch(self.visitInfo.boresightRaDec, 

75 self.visitInfo.date.get(), 

76 1.7) 

77 testData = pd.read_parquet( 

78 os.path.join(TESTDIR, 

79 "data", 

80 "testSSObjects.parq") 

81 ) 

82 self.assertEqual(len(testData), len(testOut)) 

83 self.assertTrue(np.all(np.equal(testOut["ssObjectId"], testData["ssObjectId"]))) 

84 

85 def test_skybotRun(self): 

86 """Test that the correct upload is requested. 

87 """ 

88 task = ephQ.SkyBotEphemerisQueryTask() 

89 with patch.object(task, '_skybotConeSearch') as mockSearch: 

90 task.run([pipeBase.InMemoryDatasetHandle(self.visitInfo)], self.visitId) 

91 mockSearch.assert_called_once() 

92 self.assertEqual(len(mockSearch.call_args.args), 3) 

93 self.assertEqual(mockSearch.call_args.args[0], self.visitInfo.boresightRaDec) 

94 self.assertAlmostEqual(mockSearch.call_args.args[1], self.utc_jd) 

95 self.assertAlmostEqual(mockSearch.call_args.args[2], task.config.queryRadiusDegrees) 

96 

97 

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

99 pass 

100 

101 

102def setup_module(module): 

103 lsst.utils.tests.init() 

104 

105 

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

107 lsst.utils.tests.init() 

108 unittest.main()