Coverage for tests/test_composites.py : 22%

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/>.
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}.calexp", c)
47 self.assertIn(f".{rootKey}.dummyTrue", c)
48 self.assertIn(f".{rootKey}.StructuredComposite", c)
49 self.assertIn(f".{rootKey}.ExposureF", c)
51 # Check that all entries are booleans (this is meant to be enforced
52 # internally)
53 for k in c[rootKey]:
54 self.assertIsInstance(c[f".{rootKey}.{k}"], bool, f"Testing {rootKey}.{k}")
56 def testMap(self):
57 universe = DimensionUniverse()
58 c = CompositesMap(self.configFile, universe=universe)
60 # Check that a str is not supported
61 with self.assertRaises(ValueError):
62 c.shouldBeDisassembled("fred")
64 # These will fail (not a composite)
65 sc = StorageClass("StructuredDataJson")
66 d = DatasetType("dummyTrue", universe.empty, sc)
67 self.assertFalse(sc.isComposite())
68 self.assertFalse(d.isComposite())
69 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
70 self.assertFalse(c.shouldBeDisassembled(sc), f"Test with StorageClass: {sc}")
72 # Repeat but this time use a composite storage class
73 sccomp = StorageClass("Dummy")
74 sc = StorageClass("StructuredDataJson", components={"dummy": sccomp})
75 d = DatasetType("dummyTrue", universe.empty, sc)
76 self.assertTrue(sc.isComposite())
77 self.assertTrue(d.isComposite())
78 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
79 self.assertFalse(c.shouldBeDisassembled(sc), f"Test with StorageClass: {sc}")
81 # Override with False
82 d = DatasetType("dummyFalse", universe.empty, sc)
83 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
85 # DatasetType that has no explicit entry
86 d = DatasetType("dummyFred", universe.empty, sc)
87 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
89 # StorageClass that will be disassembled
90 sc = StorageClass("StructuredComposite", components={"dummy": sccomp})
91 d = DatasetType("dummyFred", universe.empty, sc)
92 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
95if __name__ == "__main__": 95 ↛ 96line 95 didn't jump to line 96, because the condition on line 95 was never true
96 unittest.main()