Coverage for tests/test_mapper.py: 34%

60 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-05 02:50 -0800

1# 

2# LSST Data Management System 

3# Copyright 2008, 2009, 2010 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

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

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

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

11# (at your option) any later version. 

12# 

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

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

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

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22 

23 

24import unittest 

25import lsst.utils.tests 

26import os 

27 

28import lsst.daf.persistence as dafPersist 

29 

30 

31class MinMapper(dafPersist.Mapper): 

32 

33 def __init__(self): 

34 pass 

35 

36 def map_x(self, dataId, write): 

37 path = "foo%(ccd)d.pickle" % dataId 

38 if not write: 

39 path = "parent/" + path 

40 return dafPersist.ButlerLocation( 

41 "lsst.afw.image.BBox", "lsst::afw::image::BBox", "PickleStorage", 

42 path, {}, self, dafPersist.Storage.makeFromURI(os.getcwd())) 

43 

44 def map_badSourceHist(self, dataId, write): 

45 path = "badSourceHist%(ccd)d.pickle" % dataId 

46 return dafPersist.ButlerLocation( 

47 "lsst.afw.image.BBox", "lsst::afw::image::BBox", "PickleStorage", 

48 path, {}, self, dafPersist.Storage.makeFromURI(os.getcwd())) 

49 

50 def query_x(self, format, dataId): 

51 return [1, 2, 3] 

52 

53 def std_x(self, item, dataId): 

54 return float(item) 

55 

56 

57class MapperTestCase(unittest.TestCase): 

58 """A test case for the mapper used by the data butler.""" 

59 

60 def setUp(self): 

61 self.mapper = MinMapper() 

62 

63 def testGetDatasetTypes(self): 

64 self.assertEqual(set(self.mapper.getDatasetTypes()), 

65 set(["x", "badSourceHist"])) 

66 

67 def testMap(self): 

68 loc = self.mapper.map("x", {"ccd": 27}) 

69 self.assertEqual(loc.getPythonType(), "lsst.afw.image.BBox") 

70 self.assertEqual(loc.getCppType(), "lsst::afw::image::BBox") 

71 self.assertEqual(loc.getStorageName(), "PickleStorage") 

72 self.assertEqual(loc.getLocations(), ["parent/foo27.pickle"]) 

73 self.assertEqual(loc.getAdditionalData().toString(), "") 

74 

75 def testMapWrite(self): 

76 loc = self.mapper.map("x", {"ccd": 27}, write=True) 

77 self.assertEqual(loc.getPythonType(), "lsst.afw.image.BBox") 

78 self.assertEqual(loc.getCppType(), "lsst::afw::image::BBox") 

79 self.assertEqual(loc.getStorageName(), "PickleStorage") 

80 self.assertEqual(loc.getLocations(), ["foo27.pickle"]) 

81 self.assertEqual(loc.getAdditionalData().toString(), "") 

82 

83 def testQueryMetadata(self): 

84 self.assertEqual(self.mapper.queryMetadata("x", None, None), 

85 [1, 2, 3]) 

86 

87 def testStandardize(self): 

88 self.assertEqual(self.mapper.canStandardize("x"), True) 

89 self.assertEqual(self.mapper.canStandardize("badSourceHist"), False) 

90 self.assertEqual(self.mapper.canStandardize("notPresent"), False) 

91 result = self.mapper.standardize("x", 3, None) 

92 self.assertIsInstance(result, float) 

93 self.assertEqual(result, 3.0) 

94 result = self.mapper.standardize("x", 3.14, None) 

95 self.assertIsInstance(result, float) 

96 self.assertEqual(result, 3.14) 

97 result = self.mapper.standardize("x", "3.14", None) 

98 self.assertIsInstance(result, float) 

99 self.assertEqual(result, 3.14) 

100 

101 

102class TestMemory(lsst.utils.tests.MemoryTestCase): 

103 pass 

104 

105 

106def setup_module(module): 

107 lsst.utils.tests.init() 

108 

109 

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

111 lsst.utils.tests.init() 

112 unittest.main()