Coverage for tests/test_simpleGenericMap.py : 21%
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 afw. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (https://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 <https://www.gnu.org/licenses/>.
def makeMap(mapType, values): """Initialize a map type using __setattr__ instead of a bulk constructor. """ result = mapType() for key, value in values.items(): result[key] = value return result
def setUpClass(cls): super().setUpClass() cls.targets = {(str, SimpleGenericMapS)} cls.examples = { "SimpleGenericMapS(testData)": (str, SimpleGenericMapS, cls.getTestData(str)), "SimpleGenericMapS(testKeys : 0)": (str, SimpleGenericMapS, {key: 0 for key in cls.getTestData(str).keys()}), "SimpleGenericMapS()": (str, SimpleGenericMapS, {}), }
pass
self.assertTrue(issubclass(SimpleGenericMapS, MutableMapping)) for (_, target) in self.targets: self.assertIsInstance(target(), MutableMapping)
for (keyType, target) in self.targets: self.checkInitKwargs(target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: self.checkInitPairs(keyType, target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: # Init from dict self.checkInitMapping(keyType, target, self.getTestData(keyType), msg=str(target)) # Init from GenericMap self.checkInitMapping(keyType, target, self.makeMap(target, self.getTestData(keyType)), msg=str(target))
for (keyType, target) in self.targets: keys = self.getTestData(keyType).keys() for value in self.getTestData(keyType).values(): self.checkFromKeys(keyType, target, keys, value, msg=" class=%s, value=%r" % (target, value)) self.checkFromKeysDefault(keyType, target, keys, msg=" class=%s, no value" % (target))
for label, (keyType, mappingType, contents) in self.examples.items(): mapping1 = self.makeMap(mappingType, contents) mapping2 = mapping1.copy() self.assertEqual(mapping1, mapping2, msg="%s" % label) mapping1[keyType(42)] = "A random value!" self.assertNotEqual(mapping1, mapping2, msg="%s" % label)
for label1, (_, mappingType1, contents1) in self.examples.items(): mapping1 = self.makeMap(mappingType1, contents1) for label2, (_, mappingType2, contents2) in self.examples.items(): mapping2 = self.makeMap(mappingType2, contents2) if contents1 == contents2: self.assertIsNot(mapping1, mapping2, msg="%s vs %s" % (label1, label2)) self.assertEqual(mapping1, mapping2, msg="%s vs %s" % (label1, label2)) self.assertEqual(mapping1, contents2, msg="%s vs dict(%s)" % (label1, label2)) self.assertEqual(contents1, mapping2, msg="dict(%s) vs %s" % (label1, label2)) else: self.assertNotEqual(mapping1, mapping2, msg="%s vs %s" % (label1, label2)) self.assertNotEqual(mapping1, contents2, msg="%s vs dict(%s)" % (label1, label2)) self.assertNotEqual(contents1, mapping2, msg="dict(%s) vs %s" % (label1, label2))
for label, (_, mappingType, contents) in self.examples.items(): mapping = self.makeMap(mappingType, contents) if contents: self.assertTrue(mapping, msg=label) else: self.assertFalse(mapping, msg=label)
for label, (keyType, mappingType, contents) in self.examples.items(): mapping = self.makeMap(mappingType, contents) self.checkContains(keyType, mapping, contents, msg=label)
for label, (keyType, mappingType, contents) in self.examples.items(): mapping = self.makeMap(mappingType, contents) self.checkContents(keyType, mapping, contents, msg=label)
for label, (keyType, mappingType, contents) in self.examples.items(): mapping = self.makeMap(mappingType, contents) self.checkGet(keyType, mapping, contents, msg=label)
for label, (_, mappingType, contents) in self.examples.items(): mapping = self.makeMap(mappingType, contents) self.checkIteration(mapping, contents, msg=label)
for label, (_, mappingType, contents) in self.examples.items(): self.checkMutableViews(mappingType, contents, msg=label)
for (keyType, target) in self.targets: self.checkInsertItem(keyType, target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: self.checkSetdefault(keyType, target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: # Update from dict self.checkUpdateMapping(keyType, target, self.getTestData(keyType), msg=str(target)) # Update from GenericMap self.checkUpdateMapping(keyType, target, self.makeMap(target, self.getTestData(keyType)), msg=str(target))
for (keyType, target) in self.targets: self.checkUpdatePairs(keyType, target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: self.checkUpdateKwargs(target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: self.checkReplaceItem(keyType, target(), msg=str(target))
for (keyType, target) in self.targets: self.checkRemoveItem(keyType, target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: self.checkPop(keyType, target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: self.checkPopitem(target, self.getTestData(keyType), msg=str(target))
for (keyType, target) in self.targets: self.checkClear(target, self.getTestData(keyType), msg=str(target))
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |