Coverage for tests/test_findParentMapper.py : 47%

Hot-keys 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
1# This file is part of obs_base.
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/>.
22import os
23import shutil
24import unittest
25import tempfile
27import lsst.utils.tests
28import lsst.daf.persistence as dafPersist
30ROOT = os.path.abspath(os.path.dirname(__file__))
33class TestFindParentMapperV1Butler(unittest.TestCase):
34 """Test that in an 'old' Butler repository the mapper can be found in a parent repo via the _parent
35 symlink.
36 """
38 def setUp(self):
39 self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='TestFindParentMapperV1Butler-')
40 self.parentRepoDir = os.path.join(self.testDir, 'parentRepo')
41 os.makedirs(self.parentRepoDir)
43 # note: do not put a _mapper file in the parent here, it will be added later when needed.
45 self.childRepoDir = os.path.join(self.testDir, 'childRepo')
46 os.makedirs(self.childRepoDir)
47 os.symlink(self.parentRepoDir, os.path.join(self.childRepoDir, '_parent'))
49 def tearDown(self):
50 if os.path.exists(self.testDir):
51 shutil.rmtree(self.testDir)
53 def test(self):
54 # put the mapper file in the parent repo, and see if the child repo can find it via the _parent
55 # symlink.
56 with open(os.path.join(self.parentRepoDir, '_mapper'), 'w') as f:
57 f.write('lsst.obs.base.test.CompositeMapper')
59 # this should not raise an error, no error indicates that the mapper can not be found.
60 dafPersist.Butler(root=self.childRepoDir)
62 def testNoMapper(self):
63 # Since in this case the _mapper file does not exist in the parent repo, this should raise an error
64 # indicating that the mapper can not be found.
65 with self.assertRaises(RuntimeError):
66 dafPersist.Butler(self.childRepoDir, policyDir=self.testDir)
69class MemoryTester(lsst.utils.tests.MemoryTestCase):
70 pass
73def setup_module(module):
74 lsst.utils.tests.init()
77if __name__ == "__main__": 77 ↛ 78line 77 didn't jump to line 78, because the condition on line 77 was never true
78 lsst.utils.tests.init()
79 unittest.main()