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