'Assert two dicts are equivalent.
This is a \'deep\' match in the sense that it handles nested
dictionaries appropriately.
NOTE:
If you don\'t care (or don\'t know) a given value, you can specify
the string DONTCARE as the value. This will cause that dict-item
to be skipped.'

def match(self, d2):

    d1keys = set(self.d1.keys())
    d2keys = set(d2.keys())
    if (d1keys != d2keys):
        d1only = sorted((d1keys - d2keys))
        d2only = sorted((d2keys - d1keys))
        return DictKeysMismatch(d1only, d2only)
    for key in d1keys:
        d1value = self.d1[key]
        d2value = d2[key]
        try:
            error = abs((float(d1value) - float(d2value)))
            within_tolerance = (error <= self.tolerance)
        except (ValueError, TypeError):
            within_tolerance = False
        if (hasattr(d1value, 'keys') and hasattr(d2value, 'keys')):
            matcher = DictMatches(d1value)
            did_match = matcher.match(d2value)
            if (did_match is not None):
                return did_match
        elif ('DONTCARE' in (d1value, d2value)):
            continue
        elif (self.approx_equal and within_tolerance):
            continue
        elif (d1value != d2value):
            return DictMismatch(key, d1value, d2value)
