MCPcopy Index your code
hub / github.com/RustPython/RustPython / assertAlmostEqual

Method assertAlmostEqual

Lib/unittest/case.py:941–984  ·  view source on GitHub ↗

Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta. Not

(self, first, second, places=None, msg=None,
                          delta=None)

Source from the content-addressed store, hash-verified

939 raise self.failureException(msg)
940
941 def assertAlmostEqual(self, first, second, places=None, msg=None,
942 delta=None):
943 """Fail if the two objects are unequal as determined by their
944 difference rounded to the given number of decimal places
945 (default 7) and comparing to zero, or by comparing that the
946 difference between the two objects is more than the given
947 delta.
948
949 Note that decimal places (from zero) are usually not the same
950 as significant digits (measured from the most significant digit).
951
952 If the two objects compare equal then they will automatically
953 compare almost equal.
954 """
955 if first == second:
956 # shortcut
957 return
958 if delta is not None and places is not None:
959 raise TypeError("specify delta or places not both")
960
961 diff = abs(first - second)
962 if delta is not None:
963 if diff <= delta:
964 return
965
966 standardMsg = '%s != %s within %s delta (%s difference)' % (
967 safe_repr(first),
968 safe_repr(second),
969 safe_repr(delta),
970 safe_repr(diff))
971 else:
972 if places is None:
973 places = 7
974
975 if round(diff, places) == 0:
976 return
977
978 standardMsg = '%s != %s within %r places (%s difference)' % (
979 safe_repr(first),
980 safe_repr(second),
981 places,
982 safe_repr(diff))
983 msg = self._formatMessage(msg, standardMsg)
984 raise self.failureException(msg)
985
986 def assertNotAlmostEqual(self, first, second, places=None, msg=None,
987 delta=None):

Callers

nothing calls this directly

Calls 4

_formatMessageMethod · 0.95
safe_reprFunction · 0.85
roundFunction · 0.85
absFunction · 0.50

Tested by

no test coverage detected