Coverage for tests/test_composites.py: 23%
Shortcuts 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
Shortcuts 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/>.
22import os
23import unittest
25from lsst.daf.butler import CompositesConfig, CompositesMap, StorageClass, DatasetType, DimensionUniverse
27TESTDIR = os.path.dirname(__file__)
30class TestCompositesConfig(unittest.TestCase):
32 @classmethod
33 def setUpClass(cls):
34 cls.configFile = os.path.join(TESTDIR, "config", "basic", "composites.yaml")
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"))
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)
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}")
54 def testMap(self):
55 universe = DimensionUniverse()
56 c = CompositesMap(self.configFile, universe=universe)
58 # Check that a str is not supported
59 with self.assertRaises(ValueError):
60 c.shouldBeDisassembled("fred")
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}")
70 # Repeat but this time use a composite storage class
71 sccomp = StorageClass("Dummy")
72 sc = StorageClass("StructuredDataJson", components={"dummy": sccomp, "dummy2": 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}")
79 # Override with False
80 d = DatasetType("dummyFalse", universe.empty, sc)
81 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
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}")
87 # StorageClass that will be disassembled
88 sc = StorageClass("StructuredComposite", components={"dummy": sccomp, "dummy2": sccomp})
89 d = DatasetType("dummyFred", universe.empty, sc)
90 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
92 # Check that we are not allowed a single component in a composite
93 with self.assertRaises(ValueError):
94 StorageClass("TestSC", components={"dummy": sccomp})
97if __name__ == "__main__": 97 ↛ 98line 97 didn't jump to line 98, because the condition on line 97 was never true
98 unittest.main()