Coverage for python/lsst/ap/verify/config.py : 71%

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#
2# This file is part of ap_verify.
3#
4# Developed for the LSST Data Management System.
5# This product includes software developed by the LSST Project
6# (http://www.lsst.org).
7# See the COPYRIGHT file at the top-level directory of this distribution
8# for details of code ownership.
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 GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
24from lsst.daf.persistence import Policy
27# TODO: remove in DM-29042
28class Config:
29 """Confuration manager for ``ap_verify``.
31 This is a singleton `lsst.daf.persistence.Policy` that may be accessed
32 from other modules in ``ap_verify`` as needed using `Config.instance`.
33 Please do not construct objects of this class directly.
35 Objects of this type are immutable.
36 """
38 def __init__(self):
39 path = Policy.defaultPolicyFile('ap_verify', 'dataset_config.yaml', 'config')
40 self._allInfo = Policy(path)
41 self._validate()
43 def _validate(self):
44 """Test that the loaded configuration is correct.
46 Raises
47 ------
48 RuntimeError
49 Raised if validation failed
50 """
51 try:
52 datasetMap = self._allInfo['datasets']
53 if not isinstance(datasetMap, Policy): 53 ↛ 54line 53 didn't jump to line 54, because the condition on line 53 was never true
54 raise TypeError('`datasets` is not a dictionary')
55 except (KeyError, TypeError) as e:
56 raise RuntimeError('Invalid config file.') from e
58 def __getitem__(self, key):
59 return self._allInfo[key]
61 def __contains__(self, key):
62 return key in self._allInfo
65Config.instance = Config()
66"""The sole `Config` object used by the program.
67"""