Raises an assertion error if two items are equal.
(actual, desired, err_msg='',)
| 151 | |
| 152 | |
| 153 | def fail_if_equal(actual, desired, err_msg='',): |
| 154 | """ |
| 155 | Raises an assertion error if two items are equal. |
| 156 | |
| 157 | """ |
| 158 | if isinstance(desired, dict): |
| 159 | if not isinstance(actual, dict): |
| 160 | raise AssertionError(repr(type(actual))) |
| 161 | fail_if_equal(len(actual), len(desired), err_msg) |
| 162 | for k in desired: |
| 163 | if k not in actual: |
| 164 | raise AssertionError(repr(k)) |
| 165 | fail_if_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}') |
| 166 | return |
| 167 | if isinstance(desired, (list, tuple)) and isinstance(actual, (list, tuple)): |
| 168 | fail_if_equal(len(actual), len(desired), err_msg) |
| 169 | for k in range(len(desired)): |
| 170 | fail_if_equal(actual[k], desired[k], f'item={k!r}\n{err_msg}') |
| 171 | return |
| 172 | if isinstance(actual, np.ndarray) or isinstance(desired, np.ndarray): |
| 173 | return fail_if_array_equal(actual, desired, err_msg) |
| 174 | msg = build_err_msg([actual, desired], err_msg) |
| 175 | if not desired != actual: |
| 176 | raise AssertionError(msg) |
| 177 | |
| 178 | |
| 179 | assert_not_equal = fail_if_equal |
no test coverage detected
searching dependent graphs…