Coverage for tests/test_utils.py: 41%

26 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-26 02:50 -0700

1# 

2# LSST Data Management System 

3# Copyright 2008, 2009, 2010 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 

23 

24import unittest 

25 

26import astropy 

27import lsst.daf.butler as dafButler 

28import lsst.pipe.base as pipeBase 

29import lsst.sphgeom as sphgeom 

30import lsst.utils.tests 

31import pydantic 

32 

33 

34class RegionTimeInfoTestCase(unittest.TestCase): 

35 """Unit tests for lsst.pipe.base.utils.RegionTimeInfo. 

36 

37 Since RegionTimeInfo is a passive container that exists only for 

38 serialization convenience, the tests only cover serialization and assume 

39 e.g. input validation is handled by the component types. 

40 """ 

41 

42 def setUp(self): 

43 self.region = sphgeom.Circle( 

44 sphgeom.UnitVector3d(sphgeom.Angle.fromDegrees(34.5), sphgeom.Angle.fromDegrees(-42.0)), 

45 sphgeom.Angle.fromDegrees(1.0), 

46 ) 

47 self.times = dafButler.Timespan( 

48 begin=astropy.time.Time("2013-06-17 13:34:45.775000", scale="tai", format="iso"), 

49 end=astropy.time.Time("2013-06-17 13:35:17.947000", scale="tai", format="iso"), 

50 ) 

51 

52 def test_init(self): 

53 # Both parameters are mandatory 

54 with self.assertRaises(ValueError): 

55 pipeBase.utils.RegionTimeInfo() 

56 with self.assertRaises(ValueError): 

57 pipeBase.utils.RegionTimeInfo(region=self.region) 

58 with self.assertRaises(ValueError): 

59 pipeBase.utils.RegionTimeInfo(timespan=self.times) 

60 

61 def test_serialization(self): 

62 original = pipeBase.utils.RegionTimeInfo(region=self.region, timespan=self.times) 

63 adapter = pydantic.TypeAdapter(pipeBase.utils.RegionTimeInfo) 

64 

65 roundtripped = adapter.validate_json(adapter.dump_json(original)) 

66 self.assertEqual(roundtripped, original) 

67 

68 

69class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

70 """Run file leak tests.""" 

71 

72 

73def setup_module(module): 

74 """Configure pytest.""" 

75 lsst.utils.tests.init() 

76 

77 

78if __name__ == "__main__": 

79 lsst.utils.tests.init() 

80 unittest.main()