Coverage for tests/test_blobset.py: 17%

45 statements  

« prev     ^ index     » next       coverage.py v7.2.3, created at 2023-04-27 02:59 -0700

1# This file is part of verify. 

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 unittest 

23 

24import astropy.units as u 

25 

26from lsst.verify import Blob, Datum 

27from lsst.verify.blobset import BlobSet 

28 

29 

30class BlobSetTestCase(unittest.TestCase): 

31 """Test BlobSet general usage.""" 

32 

33 def setUp(self): 

34 mag1 = Datum( 

35 quantity=5 * u.mag, 

36 label='mag1', 

37 description='Magnitude') 

38 mag2 = Datum( 

39 quantity=10 * u.mag, 

40 label='mag2', 

41 description='Magnitude') 

42 self.blob1 = Blob('blob1', mag1=mag1, mag2=mag2) 

43 

44 sep1 = Datum( 

45 quantity=5 * u.arcsec, 

46 label='sep1', 

47 description='Separation') 

48 sep2 = Datum( 

49 quantity=10 * u.arcsec, 

50 label='sep2', 

51 description='Separation') 

52 self.blob2 = Blob('blob2', sep1=sep1, sep2=sep2) 

53 

54 def test_blob_set(self): 

55 blob_set = BlobSet([self.blob1]) 

56 

57 self.assertIn('blob1', blob_set) 

58 self.assertIn(self.blob1.identifier, blob_set) 

59 self.assertEqual(len(blob_set), 1) 

60 self.assertIs(blob_set['blob1'], self.blob1) 

61 

62 # add blob with inconsistent identifier 

63 with self.assertRaises(KeyError): 

64 blob_set['blob'] = self.blob2 

65 

66 # add with identifier 

67 blob_set[self.blob2.identifier] = self.blob2 

68 self.assertIn('blob2', blob_set) 

69 self.assertIn(self.blob2.identifier, blob_set) 

70 self.assertEqual(len(blob_set), 2) 

71 self.assertIs(blob_set['blob2'], self.blob2) 

72 

73 # delete blob2 

74 del blob_set['blob2'] 

75 self.assertNotIn('blob2', blob_set) 

76 self.assertNotIn(self.blob2.identifier, blob_set) 

77 self.assertEqual(len(blob_set), 1) 

78 

79 # insert blob2 

80 blob_set.insert(self.blob2) 

81 self.assertIn('blob2', blob_set) 

82 self.assertIn(self.blob2.identifier, blob_set) 

83 self.assertEqual(len(blob_set), 2) 

84 self.assertIs(blob_set['blob2'], self.blob2) 

85 

86 # iteration 

87 blobs = [b for k, b in blob_set.items()] 

88 self.assertEqual(len(blobs), 2) 

89 for blob in blobs: 

90 self.assertIsInstance(blob, Blob) 

91 blobs_direct = list(blob_set.values()) 

92 self.assertEqual(blobs, blobs_direct) 

93 

94 # serialize 

95 json_doc = blob_set.json 

96 

97 # deserialize 

98 new_blob_set = BlobSet.deserialize(blobs=json_doc) 

99 self.assertEqual(new_blob_set, blob_set) 

100 

101 

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

103 unittest.main()