Coverage for tests/test_DM-12117.py: 49%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

47 statements  

1# -*- coding: UTF-8 -*- 

2 

3# 

4# LSST Data Management System 

5# Copyright 2016 LSST Corporation. 

6# 

7# This product includes software developed by the 

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

9# 

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

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

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

13# (at your option) any later version. 

14# 

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

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

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

18# GNU General Public License for more details. 

19# 

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

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

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

23# 

24 

25import unittest 

26import lsst.daf.persistence as dp 

27import lsst.utils.tests 

28import os 

29import shutil 

30import tempfile 

31 

32ROOT = os.path.abspath(os.path.dirname(__file__)) 

33 

34 

35def setup_module(module): 

36 lsst.utils.tests.init() 

37 

38 

39class MyTestMapper(dp.Mapper): 

40 

41 def __init__(self, root, *args, **kwargs): 

42 self.root = root 

43 self.args = args 

44 self.kwargs = kwargs 

45 

46 

47class TestDM12117(unittest.TestCase): 

48 """Test case for basic Butler operations.""" 

49 

50 def setUp(self): 

51 self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='test_DM-12117-') 

52 

53 def tearDown(self): 

54 if os.path.exists(self.testDir): 

55 shutil.rmtree(self.testDir) 

56 

57 @staticmethod 

58 def repoBYaml(mapperArgs): 

59 return """!RepositoryCfg_v1 

60_mapper: 'lsst.daf.persistence.test.EmptyTestMapper' 

61_mapperArgs: {} 

62_parents: ['../repoA'] 

63_policy: null 

64_root: null 

65dirty: true 

66""".format(mapperArgs) 

67 

68 def _verifyOldButlerParentWithArgs(self, mapperArgs): 

69 """Test that an Old Butler parent repo that is can be loaded by a New 

70 Butler output repo and that the output repo's mapper args are used by 

71 the OldButler repo. 

72 

73 1. create an Old Butler repo 

74 2. create a New Butler repo with passed-in mapper args (which may be 

75 an empty dict) 

76 3. reload that New Butler repo without naming its parent as an input 

77 4. verify that the parent is loaded as an input 

78 5. verify that that the passed-in mapper args are passed to the parent 

79 as well as the root repo. 

80 

81 Parameters 

82 ---------- 

83 mapperArgs : dict or None 

84 Arguments to be passed to 

85 """ 

86 repoAPath = os.path.join(self.testDir, 'repoA') 

87 repoBPath = os.path.join(self.testDir, 'repoB') 

88 os.makedirs(repoAPath) 

89 with open(os.path.join(repoAPath, '_mapper'), 'w') as f: 

90 f.write('lsst.daf.persistence.test.EmptyTestMapper') 

91 os.makedirs(repoBPath) 

92 with open(os.path.join(repoBPath, 'repositoryCfg.yaml'), 'w') as f: 

93 f.write(self.repoBYaml(mapperArgs)) 

94 butler = dp.Butler(repoBPath) 

95 self.assertEqual(butler._repos.inputs()[0].repo._mapper.root, repoBPath) 

96 self.assertEqual(butler._repos.inputs()[1].repo._mapper.root, repoAPath) 

97 self.assertEqual(butler._repos.outputs()[0].repo._mapper.root, repoBPath) 

98 self.assertEqual(butler._repos.inputs()[0].repo._mapper.kwargs, mapperArgs) 

99 self.assertEqual(butler._repos.inputs()[1].repo._mapper.kwargs, mapperArgs) 

100 

101 def testOldButlerParentWithoutMapperArgs(self): 

102 """Test that an Old Butler parent repo that is can be loaded by a New 

103 Butler output repo and that the output repo's mapper args are used by 

104 the OldButler repo. 

105 """ 

106 self._verifyOldButlerParentWithArgs({}) 

107 

108 def testOldButlerParentWithMapperArgs(self): 

109 """Test that an Old Butler parent repo that is can be loaded by a New 

110 Butler output repo and that the output repo's mapper args are used by 

111 the OldButler repo. 

112 """ 

113 self._verifyOldButlerParentWithArgs({'calib': 'foo'}) 

114 

115 

116class MemoryTester(lsst.utils.tests.MemoryTestCase): 

117 pass 

118 

119 

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

121 lsst.utils.tests.init() 

122 unittest.main()