Coverage for tests/test_composites.py: 21%
46 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-14 19:21 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-14 19:21 +0000
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, DatasetType, DimensionUniverse, StorageClass
27TESTDIR = os.path.dirname(__file__)
30class TestCompositesConfig(unittest.TestCase):
31 """Test composites configuration."""
33 @classmethod
34 def setUpClass(cls):
35 cls.configFile = os.path.join(TESTDIR, "config", "basic", "composites.yaml")
37 def testBadConfig(self):
38 """Config with bad values in it"""
39 with self.assertRaises(ValueError):
40 CompositesConfig(os.path.join(TESTDIR, "config", "basic", "composites-bad.yaml"))
42 def testConfig(self):
43 c = CompositesConfig(self.configFile)
44 self.assertIn("default", c)
45 # Check merging has worked
46 rootKey = "disassembled"
47 self.assertIn(f".{rootKey}.dummyTrue", c)
48 self.assertIn(f".{rootKey}.StructuredComposite", c)
50 # Check that all entries are booleans (this is meant to be enforced
51 # internally)
52 for k in c[rootKey]:
53 self.assertIsInstance(c[f".{rootKey}.{k}"], bool, f"Testing {rootKey}.{k}")
55 def testMap(self):
56 universe = DimensionUniverse()
57 c = CompositesMap(self.configFile, universe=universe)
59 # Check that a str is not supported
60 with self.assertRaises(ValueError):
61 c.shouldBeDisassembled("fred")
63 # These will fail (not a composite)
64 sc = StorageClass("StructuredDataJson")
65 d = DatasetType("dummyTrue", universe.empty, sc)
66 self.assertFalse(sc.isComposite())
67 self.assertFalse(d.isComposite())
68 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
69 self.assertFalse(c.shouldBeDisassembled(sc), f"Test with StorageClass: {sc}")
71 # Repeat but this time use a composite storage class
72 sccomp = StorageClass("Dummy")
73 sc = StorageClass("StructuredDataJson", components={"dummy": sccomp, "dummy2": sccomp})
74 d = DatasetType("dummyTrue", universe.empty, sc)
75 self.assertTrue(sc.isComposite())
76 self.assertTrue(d.isComposite())
77 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
78 self.assertFalse(c.shouldBeDisassembled(sc), f"Test with StorageClass: {sc}")
80 # Override with False
81 d = DatasetType("dummyFalse", universe.empty, sc)
82 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
84 # DatasetType that has no explicit entry
85 d = DatasetType("dummyFred", universe.empty, sc)
86 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
88 # StorageClass that will be disassembled
89 sc = StorageClass("StructuredComposite", components={"dummy": sccomp, "dummy2": sccomp})
90 d = DatasetType("dummyFred", universe.empty, sc)
91 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
93 # Check that we are not allowed a single component in a composite
94 with self.assertRaises(ValueError):
95 StorageClass("TestSC", components={"dummy": sccomp})
98if __name__ == "__main__":
99 unittest.main()