Coverage for tests/test_sqlDatabaseDict.py : 24%

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
# This file is part of daf_butler. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Tests for SqlDatabaseDict. """
"""Test for SqlDatabaseDict. """
registryConfig = RegistryConfig() registryConfig["db"] = "sqlite:///:memory:" self.registry = Registry.fromConfig(registryConfig, create=True) self.types = {"x": int, "y": str, "z": float} self.key = "x"
self.assertEqual(len(d), 0) self.assertFalse(d) d[0] = data[0] self.assertEqual(len(d), 1) self.assertTrue(d) self.assertIn(0, d) self.assertEqual(d[0], data[0]) d[1] = data[1] self.assertEqual(len(d), 2) self.assertTrue(d) self.assertIn(1, d) self.assertEqual(d[1], data[1]) self.assertCountEqual(d.keys(), data.keys()) self.assertCountEqual(d.values(), data.values()) self.assertCountEqual(d.items(), data.items()) del d[0] self.assertNotIn(0, d) self.assertEqual(len(d), 1) with self.assertRaises(KeyError): del d[0] with self.assertRaises(KeyError): d[0] # Test that we can update an existing key d[1] = data[0] self.assertEqual(len(d), 1) self.assertEqual(d[1], data[0])
"""Test that the key is not permitted to be part of the value.""" value = namedtuple("TestValue", ["x", "y", "z"]) with self.assertRaises(ValueError): self.registry.makeDatabaseDict(table="TestTable", key=self.key, types=self.types, value=value)
"""Test when the value does not include the key.""" value = namedtuple("TestValue", ["y", "z"]) data = { 0: value(y="zero", z=0.0), 1: value(y="one", z=0.1), } d = self.registry.makeDatabaseDict(table="TestTable", key=self.key, types=self.types, value=value) self.checkDatabaseDict(d, data)
"""Test that we cannot insert value tuples with the wrong types.""" value = namedtuple("TestValue", ["y", "z"]) data = { 0: value(y=0, z="zero"), } d = self.registry.makeDatabaseDict(table="TestTable", key=self.key, types=self.types, value=value) with self.assertRaises(TypeError): d[0] = data[0]
"""Test that we cannot insert with the wrong key type.""" value = namedtuple("TestValue", ["y", "z"]) data = { 0: value(y="zero", z=0.0), } d = self.registry.makeDatabaseDict(table="TestTable", key=self.key, types=self.types, value=value) d["zero"] = data[0]
"""Test when there are fields in the table that not in the value or the key.
These should be completely ignored by the DatabaseDict after the table is created (which implies that they must be nullable if ``__setitem__`` is expected to work.""" value = namedtuple("TestValue", ["y"]) data = { 0: value(y="zero"), 1: value(y="one"), } d = self.registry.makeDatabaseDict(table="TestTable", key=self.key, types=self.types, value=value) self.checkDatabaseDict(d, data)
"""Test that we don't permit the value tuple to have ._fields entries that are not in the types argument itself (since we need to know their types). """ value = namedtuple("TestValue", ["y", "a"]) with self.assertRaises(TypeError): self.registry.makeDatabaseDict(table="TestTable", key=self.key, types=self.types, value=value)
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |