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

20 statements  

« prev     ^ index     » next       coverage.py v7.2.1, created at 2023-03-12 03:57 -0700

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# 

23 

24__all__ = ["Config"] 

25 

26from lsst.daf.persistence import Policy 

27 

28 

29# TODO: remove in DM-29042 

30class Config: 

31 """Confuration manager for ``ap_verify``. 

32 

33 This is a singleton `lsst.daf.persistence.Policy` that may be accessed 

34 from other modules in ``ap_verify`` as needed using `Config.instance`. 

35 Please do not construct objects of this class directly. 

36 

37 Objects of this type are immutable. 

38 """ 

39 

40 def __init__(self): 

41 path = Policy.defaultPolicyFile('ap_verify', 'dataset_config.yaml', 'config') 

42 self._allInfo = Policy(path) 

43 self._validate() 

44 

45 def _validate(self): 

46 """Test that the loaded configuration is correct. 

47 

48 Raises 

49 ------ 

50 RuntimeError 

51 Raised if validation failed 

52 """ 

53 try: 

54 datasetMap = self._allInfo['datasets'] 

55 if not isinstance(datasetMap, Policy): 55 ↛ 56line 55 didn't jump to line 56, because the condition on line 55 was never true

56 raise TypeError('`datasets` is not a dictionary') 

57 except (KeyError, TypeError) as e: 

58 raise RuntimeError('Invalid config file.') from e 

59 

60 def __getitem__(self, key): 

61 return self._allInfo[key] 

62 

63 def __contains__(self, key): 

64 return key in self._allInfo 

65 

66 

67Config.instance = Config() 

68"""The sole `Config` object used by the program. 

69"""