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

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#
24"""Common code for ap_verify unit tests.
25"""
27import unittest
29import lsst.utils.tests
31import lsst.pex.exceptions as pexExcept
32from lsst.ap.verify.config import Config
35class DataTestCase(lsst.utils.tests.TestCase):
36 """Unit test class for tests that need to use the Dataset framework.
38 Unit tests based on this class will search for a designated dataset
39 (`testDataset`), and skip all tests if the dataset is not available.
41 Subclasses must call `DataTestCase.setUpClass()` if they override
42 ``setUpClass`` themselves.
43 """
45 testDataset = 'ap_verify_testdata'
46 """The EUPS package name of the dataset to use for testing (`str`).
47 """
48 obsPackage = 'obs_lsst'
49 """The obs package associated with ``testDataset`` (`str`).
51 Set to `None` if ``testDataset`` loads its own dependencies (not
52 recommended for test datasets).
53 """
54 datasetKey = 'test'
55 """The ap_verify dataset name that would be used on the command line (`str`).
56 """
58 @classmethod
59 def setUpClass(cls):
60 try:
61 lsst.utils.getPackageDir(cls.testDataset)
62 except pexExcept.NotFoundError:
63 raise unittest.SkipTest(f'{cls.testDataset} not set up')
64 if cls.obsPackage:
65 try:
66 lsst.utils.getPackageDir(cls.obsPackage)
67 except LookupError:
68 raise unittest.SkipTest(f'{cls.obsPackage} not set up; needed for {cls.testDataset}')
70 # Hack the config for testing purposes
71 # Note that Config.instance is supposed to be immutable, so, depending on initialization order,
72 # this modification may cause other tests to see inconsistent config values
73 Config.instance._allInfo['datasets.' + cls.datasetKey] = cls.testDataset