Coverage for tests/test_composites.py: 23%
48 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-27 01:57 -0700
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-27 01:57 -0700
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 @classmethod
32 def setUpClass(cls):
33 cls.configFile = os.path.join(TESTDIR, "config", "basic", "composites.yaml")
35 def testBadConfig(self):
36 """Config with bad values in it"""
37 with self.assertRaises(ValueError):
38 CompositesConfig(os.path.join(TESTDIR, "config", "basic", "composites-bad.yaml"))
40 def testConfig(self):
41 c = CompositesConfig(self.configFile)
42 self.assertIn("default", c)
43 # Check merging has worked
44 rootKey = "disassembled"
45 self.assertIn(f".{rootKey}.dummyTrue", c)
46 self.assertIn(f".{rootKey}.StructuredComposite", c)
48 # Check that all entries are booleans (this is meant to be enforced
49 # internally)
50 for k in c[rootKey]:
51 self.assertIsInstance(c[f".{rootKey}.{k}"], bool, f"Testing {rootKey}.{k}")
53 def testMap(self):
54 universe = DimensionUniverse()
55 c = CompositesMap(self.configFile, universe=universe)
57 # Check that a str is not supported
58 with self.assertRaises(ValueError):
59 c.shouldBeDisassembled("fred")
61 # These will fail (not a composite)
62 sc = StorageClass("StructuredDataJson")
63 d = DatasetType("dummyTrue", universe.empty, sc)
64 self.assertFalse(sc.isComposite())
65 self.assertFalse(d.isComposite())
66 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
67 self.assertFalse(c.shouldBeDisassembled(sc), f"Test with StorageClass: {sc}")
69 # Repeat but this time use a composite storage class
70 sccomp = StorageClass("Dummy")
71 sc = StorageClass("StructuredDataJson", components={"dummy": sccomp, "dummy2": sccomp})
72 d = DatasetType("dummyTrue", universe.empty, sc)
73 self.assertTrue(sc.isComposite())
74 self.assertTrue(d.isComposite())
75 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
76 self.assertFalse(c.shouldBeDisassembled(sc), f"Test with StorageClass: {sc}")
78 # Override with False
79 d = DatasetType("dummyFalse", universe.empty, sc)
80 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
82 # DatasetType that has no explicit entry
83 d = DatasetType("dummyFred", universe.empty, sc)
84 self.assertFalse(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
86 # StorageClass that will be disassembled
87 sc = StorageClass("StructuredComposite", components={"dummy": sccomp, "dummy2": sccomp})
88 d = DatasetType("dummyFred", universe.empty, sc)
89 self.assertTrue(c.shouldBeDisassembled(d), f"Test with DatasetType: {d}")
91 # Check that we are not allowed a single component in a composite
92 with self.assertRaises(ValueError):
93 StorageClass("TestSC", components={"dummy": sccomp})
96if __name__ == "__main__": 96 ↛ 97line 96 didn't jump to line 97, because the condition on line 96 was never true
97 unittest.main()