def test_compare_different_types(self): # object comparison falls back to comparing types if talloc.Object < _test_pytalloc.DObject: obj1 = _test_pytalloc.new() obj2 = _test_pytalloc.DObject(dummy_func) else: obj2 = _test_pytalloc.new() obj1 = _test_pytalloc.DObject(dummy_func) self.assertFalse(obj1 == obj2) self.assertTrue(obj1 != obj2) self.assertTrue(obj1 <= obj2) self.assertTrue(obj1 < obj2) self.assertFalse(obj1 >= obj2) self.assertFalse(obj1 > obj2)
def test_compare_different_types(self): # object comparison falls back to comparing types if sys.version_info >= (3, 0): # In Python 3, types are unorderable -- nothing to test return if talloc.Object < _test_pytalloc.DObject: obj1 = _test_pytalloc.new() obj2 = _test_pytalloc.DObject(dummy_func) else: obj2 = _test_pytalloc.new() obj1 = _test_pytalloc.DObject(dummy_func) self.assertFalse(obj1 == obj2) self.assertTrue(obj1 != obj2) self.assertTrue(obj1 <= obj2) self.assertTrue(obj1 < obj2) self.assertFalse(obj1 >= obj2) self.assertFalse(obj1 > obj2)
def test_destructor(self): # Check correct lifetime of the talloc'd data lst = [] obj = _test_pytalloc.DObject(lambda: lst.append('dead')) self.assertEqual(lst, []) del obj gc.collect() self.assertEqual(lst, ['dead'])
def test_refrence(self): # Check correct lifetime of the talloc'd data with multiple references lst = [] obj = _test_pytalloc.DObject(lambda: lst.append('dead')) ref = _test_pytalloc.reference(obj) del obj gc.collect() self.assertEqual(lst, []) del ref gc.collect() self.assertEqual(lst, ['dead'])