Coverage for tests/test_butlerYaml.py: 38%

63 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-08-23 02:30 -0700

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 shutil 

26import tempfile 

27import lsst.utils.tests 

28 

29import lsst.daf.persistence as dafPersist 

30import lsst.daf.base as dafBase 

31 

32 

33class MinMapper(dafPersist.Mapper): 

34 

35 def __init__(self, root, parentRegistry, repositoryCfg): 

36 self.root = root 

37 

38 def map_x(self, dataId, write): 

39 path = "foo%(ccd)d.yaml" % dataId 

40 return dafPersist.ButlerLocation( 

41 "lsst.daf.base.PropertySet", "PropertySet", "YamlStorage", 

42 [path], dataId, self, dafPersist.Storage.makeFromURI(self.root)) 

43 

44 

45class ButlerYamlTestCase(unittest.TestCase): 

46 """A test case for the data butler using YamlStorage""" 

47 

48 localTypeName = "@myPreferredType" 

49 localTypeNameIsAliasOf = "x" 

50 

51 def setUp(self): 

52 self.tempRoot = tempfile.mkdtemp() 

53 self.butler = dafPersist.Butler(root=self.tempRoot, mapper=MinMapper) 

54 self.butler.defineAlias(self.localTypeName, self.localTypeNameIsAliasOf) 

55 

56 def tearDown(self): 

57 del self.butler 

58 shutil.rmtree(self.tempRoot, ignore_errors=True) 

59 

60 def testPropertySet(self): 

61 pset = dafBase.PropertySet() 

62 pset.set("foo", 3) 

63 pset.set("bar", dafBase.DateTime.now()) 

64 pset.set("baz", ['a', 'b', 'c']) 

65 pset.set("e", 2.71828) 

66 pset.set("f.a", [1, 2, 3]) 

67 pset.set("f.b", 201805241715) 

68 pset.setBool("bool0", False) 

69 pset.setBool("bool1", True) 

70 pset.setShort("short1", 32767) 

71 pset.setShort("short2", -32768) 

72 pset.setFloat("float1", 9.8765) 

73 pset.setFloat("float2", -1.234) 

74 self.butler.put(pset, self.localTypeName, ccd=3) 

75 y = self.butler.get(self.localTypeName, ccd=3, immediate=True) 

76 self.assertEqual(y, pset) 

77 

78 def testPropertyList(self): 

79 plist = dafBase.PropertyList() 

80 plist.set("foo", 3) 

81 plist.set("bar", dafBase.DateTime.now()) 

82 plist.set("baz", ['a', 'b', 'c']) 

83 plist.set("e", 2.71828) 

84 plist.set("f.a", [1, 2, 3]) 

85 plist.set("f.b", 201805241715) 

86 plist.setBool("bool0", False) 

87 plist.setBool("bool1", True) 

88 plist.setShort("short1", 32767) 

89 plist.setShort("short2", -32768) 

90 plist.setFloat("float1", 9.8765) 

91 plist.setFloat("float2", -1.234) 

92 self.butler.put(plist, self.localTypeName, ccd=3) 

93 y = self.butler.get(self.localTypeName, ccd=3, immediate=True) 

94 self.assertEqual(y, plist) 

95 

96 

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

98 pass 

99 

100 

101def setup_module(module): 

102 lsst.utils.tests.init() 

103 

104 

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

106 lsst.utils.tests.init() 

107 unittest.main()