I am trying to assert that two dictionaries are almost equal, but I can't seem to do that.
Here is an example:
>>> import nose.tools as nt >>> nt.assert_dict_equal({'a' : 12.4}, {'a' : 5.6 + 6.8}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/unittest/case.py", line 838, in assertDictEqual self.fail(self._formatMessage(msg, standardMsg)) File "/usr/lib/python2.7/unittest/case.py", line 413, in fail raise self.failureException(msg) AssertionError: {'a': 12.4} != {'a': 12.399999999999999} - {'a': 12.4} + {'a': 12.399999999999999} I would like this to pass, like that:
>>> nt.assert_almost_equal(12.4, 5.6 + 6.8) I am hoping that I missing something simple like, nt.assert_almost_dict_equal, or maybe there is parameter that I could pass to nt.assert_dict_equal that specifies how close floating points should be, but I can't find anything.
Of course, I could just loop over the dictionaries and use nt.assert_almost_equal to compare the values individually; however, in my case the dictionary is more complicated, so I was hoping to avoid that.
What is the best way to assert that two dictionaries are almost equal?
assert_almost_equalis only provided for numeric types whose difference can be directly computed.