Get a detailed comparison function for the types of the two args. Returns: A callable accepting (first, second, msg=None) that will raise a failure exception if first != second with a useful human readable error message for those types.
(self, first, second)
| 885 | return _AssertLogsContext(self, logger, level, no_logs=True) |
| 886 | |
| 887 | def _getAssertEqualityFunc(self, first, second): |
| 888 | """Get a detailed comparison function for the types of the two args. |
| 889 | |
| 890 | Returns: A callable accepting (first, second, msg=None) that will |
| 891 | raise a failure exception if first != second with a useful human |
| 892 | readable error message for those types. |
| 893 | """ |
| 894 | # |
| 895 | # NOTE(gregory.p.smith): I considered isinstance(first, type(second)) |
| 896 | # and vice versa. I opted for the conservative approach in case |
| 897 | # subclasses are not intended to be compared in detail to their super |
| 898 | # class instances using a type equality func. This means testing |
| 899 | # subtypes won't automagically use the detailed comparison. Callers |
| 900 | # should use their type specific assertSpamEqual method to compare |
| 901 | # subclasses if the detailed comparison is desired and appropriate. |
| 902 | # See the discussion in http://bugs.python.org/issue2578. |
| 903 | # |
| 904 | if type(first) is type(second): |
| 905 | asserter = self._type_equality_funcs.get(type(first)) |
| 906 | if asserter is not None: |
| 907 | if isinstance(asserter, str): |
| 908 | asserter = getattr(self, asserter) |
| 909 | return asserter |
| 910 | |
| 911 | return self._baseAssertEqual |
| 912 | |
| 913 | def _baseAssertEqual(self, first, second, msg=None): |
| 914 | """The default assertEqual implementation, not type specific.""" |