Fail if the two objects are equal 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 less than the given delta. Note that decima
(self, first, second, places=None, msg=None,
delta=None)
| 979 | raise self.failureException(msg) |
| 980 | |
| 981 | def assertNotAlmostEqual(self, first, second, places=None, msg=None, |
| 982 | delta=None): |
| 983 | """Fail if the two objects are equal as determined by their |
| 984 | difference rounded to the given number of decimal places |
| 985 | (default 7) and comparing to zero, or by comparing that the |
| 986 | difference between the two objects is less than the given delta. |
| 987 | |
| 988 | Note that decimal places (from zero) are usually not the same |
| 989 | as significant digits (measured from the most significant digit). |
| 990 | |
| 991 | Objects that are equal automatically fail. |
| 992 | """ |
| 993 | if delta is not None and places is not None: |
| 994 | raise TypeError("specify delta or places not both") |
| 995 | diff = abs(first - second) |
| 996 | if delta is not None: |
| 997 | if not (first == second) and diff > delta: |
| 998 | return |
| 999 | standardMsg = '%s == %s within %s delta (%s difference)' % ( |
| 1000 | safe_repr(first), |
| 1001 | safe_repr(second), |
| 1002 | safe_repr(delta), |
| 1003 | safe_repr(diff)) |
| 1004 | else: |
| 1005 | if places is None: |
| 1006 | places = 7 |
| 1007 | if not (first == second) and round(diff, places) != 0: |
| 1008 | return |
| 1009 | standardMsg = '%s == %s within %r places' % (safe_repr(first), |
| 1010 | safe_repr(second), |
| 1011 | places) |
| 1012 | |
| 1013 | msg = self._formatMessage(msg, standardMsg) |
| 1014 | raise self.failureException(msg) |
| 1015 | |
| 1016 | def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None): |
| 1017 | """An equality assertion for ordered sequences (like lists and tuples). |