Coverage for tests/test_priorFileLocation.py: 74%

39 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-17 09:24 +0000

1# This file is part of meas_modelfit. 

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/>. 

21# 

22import os 

23import unittest 

24 

25import lsst.utils.tests 

26import lsst.meas.modelfit 

27 

28 

29class PriorFileLocationTestCase(lsst.utils.tests.TestCase): 

30 """Test that FILE priors are found both when the MEAS_MODELFIT_DIR 

31 environment variable is set (EUPS-provided) and when it is not set, in 

32 which case the data directory is located relative to the meas_modelfit 

33 shared library itself. 

34 """ 

35 

36 def setUp(self): 

37 # Remember the current value so we can restore it in tearDown. 

38 self.savedDir = os.environ.get("MEAS_MODELFIT_DIR") 

39 # Determine a valid package directory to point the environment 

40 # variable at for the "env var set" case. Prefer the value already in 

41 # the environment; otherwise ask EUPS/utils for it. 

42 if self.savedDir is not None: 42 ↛ 45line 42 didn't jump to line 45 because the condition on line 42 was always true

43 self.packageDir = self.savedDir 

44 else: 

45 try: 

46 self.packageDir = lsst.utils.getPackageDir("meas_modelfit") 

47 except LookupError: 

48 self.packageDir = None 

49 

50 def tearDown(self): 

51 if self.savedDir is not None: 51 ↛ 54line 51 didn't jump to line 54 because the condition on line 51 was always true

52 os.environ["MEAS_MODELFIT_DIR"] = self.savedDir 

53 else: 

54 os.environ.pop("MEAS_MODELFIT_DIR", None) 

55 

56 def _makeControl(self): 

57 ctrl = lsst.meas.modelfit.CModelStageControl() 

58 ctrl.priorSource = "FILE" 

59 ctrl.priorName = "s13-v2-disk-08" 

60 return ctrl 

61 

62 def testFindsPriorWithEnvVar(self): 

63 """The prior is found via the MEAS_MODELFIT_DIR environment variable.""" 

64 if self.packageDir is None: 64 ↛ 65line 64 didn't jump to line 65 because the condition on line 64 was never true

65 self.skipTest("Cannot determine meas_modelfit package directory") 

66 os.environ["MEAS_MODELFIT_DIR"] = self.packageDir 

67 prior = self._makeControl().getPrior() 

68 self.assertIsNotNone(prior) 

69 

70 def testFindsPriorWithoutEnvVar(self): 

71 """The prior is found relative to the shared library when the 

72 environment variable is not set. 

73 """ 

74 os.environ.pop("MEAS_MODELFIT_DIR", None) 

75 prior = self._makeControl().getPrior() 

76 self.assertIsNotNone(prior) 

77 

78 

79class TestMemory(lsst.utils.tests.MemoryTestCase): 

80 pass 

81 

82 

83def setup_module(module): 

84 lsst.utils.tests.init() 

85 

86 

87if __name__ == "__main__": 87 ↛ 88line 87 didn't jump to line 88 because the condition on line 87 was never true

88 lsst.utils.tests.init() 

89 unittest.main()