Coverage for python/lsst/ap/verify/testUtils.py: 48%

21 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"""Common code for ap_verify unit tests. 

25""" 

26 

27__all__ = ["DataTestCase"] 

28 

29import unittest 

30 

31import lsst.utils.tests 

32 

33from lsst.ap.verify.config import Config 

34 

35 

36class DataTestCase(lsst.utils.tests.TestCase): 

37 """Unit test class for tests that need to use the Dataset framework. 

38 

39 Unit tests based on this class will search for a designated dataset 

40 (`testDataset`), and skip all tests if the dataset is not available. 

41 

42 Subclasses must call `DataTestCase.setUpClass()` if they override 

43 ``setUpClass`` themselves. 

44 """ 

45 

46 testDataset = 'ap_verify_testdata' 

47 """The EUPS package name of the dataset to use for testing (`str`). 

48 """ 

49 obsPackage = 'obs_lsst' 

50 """The obs package associated with ``testDataset`` (`str`). 

51 

52 Set to `None` if ``testDataset`` loads its own dependencies (not 

53 recommended for test datasets). 

54 """ 

55 datasetKey = 'test' 

56 """The ap_verify dataset name that would be used on the command line (`str`). 

57 """ 

58 # TODO: remove datasetKey in DM-29042 

59 

60 @classmethod 

61 def setUpClass(cls): 

62 try: 

63 lsst.utils.getPackageDir(cls.testDataset) 

64 except LookupError: 

65 raise unittest.SkipTest(f'{cls.testDataset} not set up') 

66 if cls.obsPackage: 

67 try: 

68 lsst.utils.getPackageDir(cls.obsPackage) 

69 except LookupError: 

70 raise unittest.SkipTest(f'{cls.obsPackage} not set up; needed for {cls.testDataset}') 

71 

72 # Hack the config for testing purposes 

73 # Note that Config.instance is supposed to be immutable, so, depending on initialization order, 

74 # this modification may cause other tests to see inconsistent config values 

75 # TODO: remove in DM-29042 

76 Config.instance._allInfo['datasets.' + cls.datasetKey] = cls.testDataset