Exemple #1
0
 def test_goodKeys_dict(self):
     """Verify a complete set of keys is returned from getCommonKeys"""
     d0 = {1: None, '2': None, (1, 2, 3): "tuple"}
     expected = set(d0.keys())
     actual = getCommonKeys(d0, d0, 'identical dictionary')
     self.assertSetEqual(expected, actual, msg="Passed two dictionaries")
     actual = getCommonKeys(d0, expected, 'dictionary and set')
     self.assertSetEqual(expected, actual, msg="Passed dictionary and set")
Exemple #2
0
 def test_getKeys_missing(self):
     """Verify that missing keys are properly notified."""
     log = []
     d0 = {1, 2, 3}
     emptyS = set()
     desc0 = "xObj0x"
     desc1 = "xObj1x"
     common = getCommonKeys(d0,
                            emptyS,
                            'missing keys',
                            desc0,
                            desc1,
                            herald=log.append)
     self.assertSetEqual(emptyS, common)
     self.assertEqual(len(log), 1, msg="Failed to append warning message")
     warnMsg = log[0]
     self.assertIsInstance(warnMsg, str, msg="Log messages is not string")
     for desc in (desc0, desc1):
         errMsg = "Description {} missing from warning message\n{}"
         self.assertIn(desc, warnMsg, msg=errMsg.format(desc, warnMsg))
    def compareMetadata(self, other, header=False):
        """
        Return True if the metadata (settings) are identical.

        Parameters
        ----------
        other: :class:`ResultsReader`
            Class against which to compare
        {header}

        Returns
        -------
        bool:
            If the metadata are identical

        Raises
        ------
        {compTypeErr}
        """

        self._checkCompareObj(other)
        if header:
            self._compareLogPreMsg(other, quantity='metadata')
        myKeys = set(self.metadata.keys())
        otherKeys = set(other.metadata.keys())
        similar = not any(myKeys.symmetric_difference(otherKeys))
        commonKeys = getCommonKeys(myKeys, otherKeys, 'metadata')
        skips = commonKeys.intersection(self.__METADATA_COMP_SKIPS)
        if any(skips):
            info("The following items will be skipped in the comparison\n\t{}".
                 format(', '.join(sorted(skips))))
        for key in sorted(commonKeys):
            if key in self.__METADATA_COMP_SKIPS:
                continue
            selfV = self.metadata[key]
            otherV = other.metadata[key]
            similar &= logDirectCompare(selfV, otherV, 0., 0., key)

        return similar