Hide keyboard shortcuts

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# This file is part of daf_butler. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://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 <http://www.gnu.org/licenses/>. 

21 

22import os 

23import unittest 

24 

25from lsst.daf.butler import CompositesConfig, CompositesMap, StorageClass, DatasetType, DimensionUniverse 

26 

27TESTDIR = os.path.dirname(__file__) 

28 

29 

30class TestCompositesConfig(unittest.TestCase): 

31 

32 @classmethod 

33 def setUpClass(cls): 

34 cls.configFile = os.path.join(TESTDIR, "config", "basic", "composites.yaml") 

35 

36 def testBadConfig(self): 

37 """Config with bad values in it""" 

38 with self.assertRaises(ValueError): 

39 CompositesConfig(os.path.join(TESTDIR, "config", "basic", "composites-bad.yaml")) 

40 

41 def testConfig(self): 

42 c = CompositesConfig(self.configFile) 

43 self.assertIn("default", c) 

44 # Check merging has worked 

45 rootKey = "disassembled" 

46 self.assertIn(f".{rootKey}.dummyTrue", c) 

47 self.assertIn(f".{rootKey}.StructuredComposite", c) 

48 

49 # Check that all entries are booleans (this is meant to be enforced 

50 # internally) 

51 for k in c[rootKey]: 

52 self.assertIsInstance(c[f".{rootKey}.{k}"], bool, f"Testing {rootKey}.{k}") 

53 

54 def testMap(self): 

55 universe = DimensionUniverse() 

56 c = CompositesMap(self.configFile, universe=universe) 

57 

58 # Check that a str is not supported 

59 with self.assertRaises(ValueError): 

60 c.shouldBeDisassembled("fred") 

61 

62 # These will fail (not a composite) 

63 sc = StorageClass("StructuredDataJson") 

64 d = DatasetType("dummyTrue", universe.empty, sc) 

65 self.assertFalse(sc.isComposite()) 

66 self.assertFalse(d.isComposite()) 

67 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}") 

68 self.assertFalse(c.shouldBeDisassembled(sc), f"Test with StorageClass: {sc}") 

69 

70 # Repeat but this time use a composite storage class 

71 sccomp = StorageClass("Dummy") 

72 sc = StorageClass("StructuredDataJson", components={"dummy": sccomp}) 

73 d = DatasetType("dummyTrue", universe.empty, sc) 

74 self.assertTrue(sc.isComposite()) 

75 self.assertTrue(d.isComposite()) 

76 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}") 

77 self.assertFalse(c.shouldBeDisassembled(sc), f"Test with StorageClass: {sc}") 

78 

79 # Override with False 

80 d = DatasetType("dummyFalse", universe.empty, sc) 

81 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}") 

82 

83 # DatasetType that has no explicit entry 

84 d = DatasetType("dummyFred", universe.empty, sc) 

85 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}") 

86 

87 # StorageClass that will be disassembled 

88 sc = StorageClass("StructuredComposite", components={"dummy": sccomp}) 

89 d = DatasetType("dummyFred", universe.empty, sc) 

90 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}") 

91 

92 

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

94 unittest.main()