Coverage for tests/test_skyBotEphemerisQuery.py: 41%
51 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-18 02:47 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-18 02:47 -0800
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/>.
22from unittest.mock import patch
23import numpy as np
24import os
25import pandas as pd
26import unittest
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
33from lsst.utils import getPackageDir
34import lsst.utils.tests
37class MockDeferredDatasetHandle:
38 """A container that allows passing objects to methods that expect a
39 DeferredDatasetHandle.
40 """
42 def __init__(self, object):
43 self._internal = object
45 def get(self, *args, **kwargs):
46 return self._internal
49class TestSkyBotEphemerisQuery(unittest.TestCase):
51 def setUp(self):
52 super().setUp()
54 # Explicit date calculation to avoid errors from misuse of time libraries.
55 mjd = 57071.0
56 self.utc_jd = mjd + 2_400_000.5 - 35.0 / (24.0 * 60.0 * 60.0)
58 self.visitId = 42
59 self.visitInfo = afwImage.VisitInfo(
60 # Incomplete VisitInfo; Python constructor allows any value to
61 # be defaulted.
62 exposureTime=30.0,
63 darkTime=3.0,
64 date=dafBase.DateTime(mjd, system=dafBase.DateTime.MJD),
65 boresightRaDec=geom.SpherePoint(0.0, 0.0, geom.degrees),
66 )
68 def test_skyBotConeSearch(self):
69 """Test that our parsing of SkyBot return data succeeds and produces
70 consistent hashed dataIds.
71 """
72 def requestReplace(input1, input2):
73 """Junk wrapper for replacing the external internal call with an
74 internel data load.
75 """
76 with open(os.path.join(getPackageDir("ap_association"),
77 "tests",
78 "data",
79 "testSSObjects.txt"),
80 "r") as f:
81 outputText = f.read()
82 return pipeBase.Struct(text=outputText)
83 with patch('lsst.ap.association.skyBotEphemerisQuery.requests.request',
84 new=requestReplace):
85 ephTask = ephQ.SkyBotEphemerisQueryTask()
86 testOut = ephTask._skybotConeSearch(self.visitInfo.boresightRaDec,
87 self.visitInfo.date.get(),
88 1.7)
89 testData = pd.read_parquet(
90 os.path.join(getPackageDir("ap_association"),
91 "tests",
92 "data",
93 "testSSObjects.parq")
94 )
95 self.assertEqual(len(testData), len(testOut))
96 self.assertTrue(np.all(np.equal(testOut["ssObjectId"], testData["ssObjectId"])))
98 def test_skybotRun(self):
99 """Test that the correct upload is requested.
100 """
101 task = ephQ.SkyBotEphemerisQueryTask()
102 with patch.object(task, '_skybotConeSearch') as mockSearch:
103 task.run([MockDeferredDatasetHandle(self.visitInfo)], self.visitId)
104 mockSearch.assert_called_once()
105 self.assertEqual(len(mockSearch.call_args.args), 3)
106 self.assertEqual(mockSearch.call_args.args[0], self.visitInfo.boresightRaDec)
107 self.assertAlmostEqual(mockSearch.call_args.args[1], self.utc_jd)
108 self.assertAlmostEqual(mockSearch.call_args.args[2], task.config.queryRadiusDegrees)
111class MemoryTester(lsst.utils.tests.MemoryTestCase):
112 pass
115def setup_module(module):
116 lsst.utils.tests.init()
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never true
120 lsst.utils.tests.init()
121 unittest.main()