Coverage for tests/test_policy.py: 40%
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
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
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
45 written & loaded correctly.
46 """
48 objA = dpTest.TestObject("abc")
49 dpTest.TestObject("def")
51 firstRepoPath = os.path.join(self.testData, 'repo1')
52 os.path.join(self.testData, 'repo2')
54 policy = dafPersist.Policy({'camera': 'lsst.afw.cameraGeom.Camera',
55 'datasets': {
56 'basicObject1': {
57 'python': 'lsst.daf.persistence.test.TestObject',
58 'template': 'basic/id%(id)s.pickle',
59 'storage': 'PickleStorage'},
60 }
61 })
63 firstRepoPath = os.path.join(self.testData, 'repo1')
64 repoArgs = dafPersist.RepositoryArgs(root=firstRepoPath,
65 mapper='lsst.obs.base.test.CompositeMapper',
66 policy=policy)
67 butler = dafPersist.Butler(outputs=repoArgs)
69 with open(os.path.join(firstRepoPath, 'repositoryCfg.yaml')) as f:
70 cfg = yaml.load(f, Loader=yaml.UnsafeLoader)
71 self.assertEqual(cfg.policy, policy)
72 butler.put(objA, 'basicObject1', {'id': 1})
74 del butler
75 del repoArgs
77 # Test that a newly-initialized butler can find the policy in the
78 # repositoryCfg.
79 repoArgs = dafPersist.RepositoryArgs(root=firstRepoPath)
80 butler = dafPersist.Butler(inputs=repoArgs)
81 reloadedObjA = butler.get('basicObject1', {'id': 1})
82 self.assertEqual(reloadedObjA, objA)
85class MemoryTester(lsst.utils.tests.MemoryTestCase):
86 pass
89def setup_module(module):
90 lsst.utils.tests.init()
93if __name__ == "__main__": 93 ↛ 94line 93 didn't jump to line 94, because the condition on line 93 was never true
94 lsst.utils.tests.init()
95 unittest.main()