Coverage for tests/test_findParentMapper.py: 48%
32 statements
« prev ^ index » next coverage.py v6.4, created at 2022-06-02 03:54 -0700
« prev ^ index » next coverage.py v6.4, created at 2022-06-02 03:54 -0700
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 tempfile
25import unittest
27import lsst.daf.persistence as dafPersist
28import lsst.utils.tests
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
35 parent repo via the _parent 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
44 # later when needed.
46 self.childRepoDir = os.path.join(self.testDir, "childRepo")
47 os.makedirs(self.childRepoDir)
48 os.symlink(self.parentRepoDir, os.path.join(self.childRepoDir, "_parent"))
50 def tearDown(self):
51 if os.path.exists(self.testDir):
52 shutil.rmtree(self.testDir)
54 def test(self):
55 # put the mapper file in the parent repo, and see if the child repo can
56 # find it via the _parent symlink.
57 with open(os.path.join(self.parentRepoDir, "_mapper"), "w") as f:
58 f.write("lsst.obs.base.test.CompositeMapper")
60 # this should not raise an error, no error indicates that the mapper
61 # can not be found.
62 dafPersist.Butler(root=self.childRepoDir)
64 def testNoMapper(self):
65 # Since in this case the _mapper file does not exist in the parent
66 # repo, this should raise an error indicating that the mapper can not
67 # be found.
68 with self.assertRaises(RuntimeError):
69 dafPersist.Butler(self.childRepoDir, policyDir=self.testDir)
72class MemoryTester(lsst.utils.tests.MemoryTestCase):
73 pass
76def setup_module(module):
77 lsst.utils.tests.init()
80if __name__ == "__main__": 80 ↛ 81line 80 didn't jump to line 81, because the condition on line 80 was never true
81 lsst.utils.tests.init()
82 unittest.main()