def test_different_instance_callbacks(self): class A(object): def b(self): pass def __eq__(self, other): return True def __ne__(self, other): return not self.__eq__(other) b = A() c = A() self.assertFalse(reflection.is_same_callback(b.b, c.b)) # NOTE(gmann): python3.8 onwards, comparision of bound methods is # changed and 'strict' arg has no meaning. # Ref bug: https://bugs.launchpad.net/oslo.utils/+bug/1841072 if sys.version_info < (3, 8): self.assertTrue(reflection.is_same_callback(b.b, c.b, strict=False)) else: self.assertFalse( reflection.is_same_callback(b.b, c.b, strict=False)) self.assertTrue(reflection.is_same_callback(b.b, b.b))
def is_equivalent(self, callback, details_filter=None): if not reflection.is_same_callback(self._callback, callback): return False if details_filter is not None: if self._details_filter is None: return False else: return reflection.is_same_callback(self._details_filter, details_filter) else: return self._details_filter is None
def test_different_instance_callbacks(self): class A(object): def b(self): pass def __eq__(self, other): return True b = A() c = A() self.assertFalse(reflection.is_same_callback(b.b, c.b)) self.assertTrue(reflection.is_same_callback(b.b, c.b, strict=False))
def test_different_simple_callbacks(self): def a(): pass def b(): pass self.assertFalse(reflection.is_same_callback(a, b))
def is_equivalent(self, callback, details_filter=None): """Check if the callback is same :param callback: callback used for comparison :param details_filter: callback used for comparison :returns: false if not the same callback, otherwise true :rtype: boolean """ if not reflection.is_same_callback(self._callback, callback): return False if details_filter is not None: if self._details_filter is None: return False else: return reflection.is_same_callback(self._details_filter, details_filter) else: return self._details_filter is None
def test_static_instance_callbacks(self): class A(object): @staticmethod def b(a, b, c): pass a = A() b = A() self.assertTrue(reflection.is_same_callback(a.b, b.b))
def is_equivalent(self, callback, details_filter=None): """Check if the callback provided is the same as the internal one. :param callback: callback used for comparison :param details_filter: callback used for comparison :returns: false if not the same callback, otherwise true :rtype: boolean """ cb = self.callback if cb is None and callback is not None: return False if cb is not None and callback is None: return False if cb is not None and callback is not None \ and not reflection.is_same_callback(cb, callback): return False if details_filter is not None: if self._details_filter is None: return False else: return reflection.is_same_callback(self._details_filter, details_filter) else: return self._details_filter is None