Coverage for tests/test_weather.py: 31%

45 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-08-30 02:37 -0700

1# 

2# LSST Data Management System 

3# Copyright 2016 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22""" 

23Tests for lsst.afw.image.Weather 

24""" 

25import unittest 

26 

27import numpy as np 

28 

29import lsst.utils.tests 

30import lsst.pex.exceptions 

31from lsst.afw.coord import Weather 

32 

33 

34class WeatherTestCase(unittest.TestCase): 

35 """Test lsst.afw.coord.Weather, a simple struct-like class""" 

36 

37 def testBasics(self): 

38 prevWeather = None 

39 for temp, pressure in ((1.1, 2.2), (100.1, 200.2)): # arbitrary values 

40 # 0 and greater, including supersaturation 

41 for humidity in (0.0, 10.1, 100.0, 120.5): 

42 weather = Weather(temp, pressure, humidity) 

43 self.assertEqual(weather.getAirTemperature(), temp) 

44 self.assertEqual(weather.getAirPressure(), pressure) 

45 self.assertEqual(weather.getHumidity(), humidity) 

46 

47 # test copy constructor 

48 weatherCopy = Weather(weather) 

49 self.assertEqual(weatherCopy.getAirTemperature(), temp) 

50 self.assertEqual(weatherCopy.getAirPressure(), pressure) 

51 self.assertEqual(weatherCopy.getHumidity(), humidity) 

52 

53 # test == (using a copy, to make sure the test is not based on 

54 # identity) and != 

55 self.assertEqual(weather, weatherCopy) 

56 if prevWeather is not None: 

57 self.assertNotEqual(weather, prevWeather) 

58 prevWeather = weather 

59 

60 def testBadHumidity(self): 

61 """Check bad humidity handling (humidity is the only value whose range is checked)""" 

62 for humidity in (-1, -0.0001): 

63 with self.assertRaises(lsst.pex.exceptions.InvalidParameterError): 

64 Weather(1.1, 2.2, humidity) 

65 

66 def testEquals(self): 

67 weather1 = Weather(1.1, 100.1, 10.1) 

68 weather2 = Weather(2.2, 200.2, 0.0) 

69 weather3 = Weather(np.nan, np.nan, np.nan) 

70 

71 # objects with "same" values should be equal 

72 self.assertEqual(Weather(1.1, 100.1, 10.1), Weather(1.1, 100.1, 10.1)) 

73 self.assertEqual(Weather(np.nan, np.nan, np.nan), Weather(np.nan, np.nan, np.nan)) 

74 self.assertNotEqual(weather1, weather2) 

75 self.assertNotEqual(weather3, weather2) 

76 

77 # equality must be reflexive 

78 self.assertEqual(weather1, weather1) 

79 self.assertEqual(weather2, weather2) 

80 self.assertEqual(weather3, weather3) 

81 

82 

83def setup_module(module): 

84 lsst.utils.tests.init() 

85 

86 

87class MemoryTester(lsst.utils.tests.MemoryTestCase): 

88 pass 

89 

90 

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

92 lsst.utils.tests.init() 

93 unittest.main()