Coverage for tests/test_policy.py : 40%

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 unittest
23import tempfile
24import lsst.utils.tests
26import lsst.daf.persistence as dafPersist
27import lsst.daf.persistence.test as dpTest
28import os
29import shutil
30import yaml
32ROOT = os.path.abspath(os.path.dirname(__file__))
35class TestPolicyInRepo(unittest.TestCase):
36 def setUp(self):
37 self.testData = tempfile.mkdtemp(dir=ROOT, prefix='TestPolicyInRepo-')
39 def tearDown(self):
40 if os.path.exists(self.testData):
41 shutil.rmtree(self.testData)
43 def test(self):
44 """Verify that when specifying a repo policy that the policy gets written & loaded correctly.
45 """
47 objA = dpTest.TestObject("abc")
48 dpTest.TestObject("def")
50 firstRepoPath = os.path.join(self.testData, 'repo1')
51 os.path.join(self.testData, 'repo2')
53 policy = dafPersist.Policy({'camera': 'lsst.afw.cameraGeom.Camera',
54 'datasets': {
55 'basicObject1': {
56 'python': 'lsst.daf.persistence.test.TestObject',
57 'template': 'basic/id%(id)s.pickle',
58 'storage': 'PickleStorage'},
59 }
60 })
62 firstRepoPath = os.path.join(self.testData, 'repo1')
63 repoArgs = dafPersist.RepositoryArgs(root=firstRepoPath,
64 mapper='lsst.obs.base.test.CompositeMapper',
65 policy=policy)
66 butler = dafPersist.Butler(outputs=repoArgs)
68 with open(os.path.join(firstRepoPath, 'repositoryCfg.yaml')) as f:
69 cfg = yaml.load(f, Loader=yaml.FullLoader)
70 self.assertEqual(cfg.policy, policy)
71 butler.put(objA, 'basicObject1', {'id': 1})
73 del butler
74 del repoArgs
76 # Test that a newly-initialized butler can find the policy in the repositoryCfg.
77 repoArgs = dafPersist.RepositoryArgs(root=firstRepoPath)
78 butler = dafPersist.Butler(inputs=repoArgs)
79 reloadedObjA = butler.get('basicObject1', {'id': 1})
80 self.assertEqual(reloadedObjA, objA)
83class MemoryTester(lsst.utils.tests.MemoryTestCase):
84 pass
87def setup_module(module):
88 lsst.utils.tests.init()
91if __name__ == "__main__": 91 ↛ 92line 91 didn't jump to line 92, because the condition on line 91 was never true
92 lsst.utils.tests.init()
93 unittest.main()