Coverage for tests/test_sasquatchDatastore.py: 49%

33 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-30 14:27 +0000

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 <https://www.gnu.org/licenses/>. 

21 

22import os 

23import unittest 

24from unittest.mock import patch 

25 

26import astropy.units as u 

27import lsst.daf.butler.tests as butlerTests 

28from lsst.analysis.tools.interfaces import MetricMeasurementBundle 

29from lsst.analysis.tools.interfaces.datastore import SasquatchDispatcher 

30from lsst.daf.butler import CollectionType, Config 

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

32from lsst.verify import Measurement 

33 

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

35CONFIG_FILE = os.path.join(TESTDIR, "config", "butler-sasquatch.yaml") 

36 

37 

38class SasquatchDatastoreTest(unittest.TestCase): 

39 def setUp(self): 

40 self.root = makeTestTempDir(TESTDIR) 

41 

42 config = Config() 

43 config["datastore", "cls"] = "lsst.analysis.tools.interfaces.datastore.SasquatchDatastore" 

44 config["datastore", "restProxyUrl"] = "https://example.com/sasquatch-rest-proxy" 

45 

46 dataIds = { 

47 "instrument": ["DummyCam"], 

48 "physical_filter": ["d-r"], 

49 "visit": [42, 43, 44], 

50 "detector": [1, 2, 3], 

51 } 

52 self.butler = butlerTests.makeTestRepo(self.root, dataIds, config=config) 

53 

54 butlerTests.addDatasetType( 

55 self.butler, "Metrics", {"instrument", "visit", "detector"}, "MetricMeasurementBundle" 

56 ) 

57 self.butler.registry.registerCollection("run1", CollectionType.RUN) 

58 

59 def tearDown(self): 

60 removeTestTempDir(self.root) 

61 

62 def test_put(self): 

63 """Simple test for put method.""" 

64 m = Measurement("nopackage.fancyMetric", 42.2 * u.s) 

65 bundle = MetricMeasurementBundle({"m": [m]}) 

66 

67 # Patch dispatcher method to check parameters. 

68 with patch.object(SasquatchDispatcher, "dispatchRef") as mock_method: 

69 self.butler.put(bundle, "Metrics", run="run1", instrument="DummyCam", visit=42, detector=2) 

70 

71 mock_method.assert_called() 

72 self.assertIs(mock_method.call_args[0][0], bundle) 

73 

74 

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

76 unittest.main()