Coverage for tests/test_butlerPickle.py: 51%

41 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-11 02:39 -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 pickle 

25import unittest 

26import shutil 

27import tempfile 

28import lsst.utils.tests 

29 

30import lsst.daf.persistence as dafPersist 

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.pickle" % dataId 

40 return dafPersist.ButlerLocation( 

41 None, None, "PickleStorage", path, {}, 

42 self, dafPersist.Storage.makeFromURI(self.root)) 

43 

44 

45class ButlerPickleTestCase(unittest.TestCase): 

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

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 checkIO(self, butler, bbox, ccd): 

61 butler.put(bbox, self.localTypeName, ccd=ccd) 

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

63 self.assertEqual(bbox, y) 

64 

65 def testIO(self): 

66 bbox = [[3, 4], [5, 6]] 

67 self.checkIO(self.butler, bbox, 3) 

68 

69 def testPickle(self): 

70 pickledButler = pickle.dumps(self.butler) 

71 butler = pickle.loads(pickledButler) 

72 bbox = [[1, 2], [8, 9]] 

73 self.checkIO(butler, bbox, 1) 

74 

75 

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

77 pass 

78 

79 

80def setup_module(module): 

81 lsst.utils.tests.init() 

82 

83 

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

85 lsst.utils.tests.init() 

86 unittest.main()