def test_hash(self): ''' Check whether the __hash__ function is equal to HashCode() ''' s = Standard_Transient() id_s = id(s) hash1_s = s.__hash__() self.assertNotEqual(id_s, hash1_s)
def test_hash(self): ''' Check whether the __hash__ function is equal to HashCode() ''' s = Standard_Transient() id_s = id(s) hash1_s = s.__hash__() self.assertNotEqual(id_s, hash1_s)
def test_neq_operator(self): # test Standard h1 = Handle_Standard_Transient() s = Standard_Transient() h2 = s.GetHandle() self.assertFalse(h1 != h1) self.assertTrue(h1 != h2) self.assertTrue(h1 != 10) self.assertFalse(h2 != s) shape_1 = BRepPrimAPI_MakeBox(10, 20, 30).Shape() shape_2 = BRepPrimAPI_MakeBox(10, 20, 30).Shape() self.assertTrue(shape_1 != shape_2) self.assertFalse(shape_1 != shape_1) self.assertTrue(shape_1 != "some_string")
def test_hash_eq_operator(self): ''' test that the == wrapper is ok ''' # test Standard h1 = Handle_Standard_Transient() s = Standard_Transient() h2 = s.GetHandle() self.assertTrue(h1 == h1) self.assertFalse(h1 == h2) self.assertFalse(h1 == 10) self.assertTrue(h2 == s) # test list.index, that uses __eq__ method p1 = gp_Pnt(0., 0., 0.) line = gp_Lin(p1, gp_Dir(1., 0., 0.)) items = [p1, line] res = items.index(line) self.assertEqual(res, 1.)
def testReferenceCounting(self): s1 = Standard_Transient() number_of_references_to_s1 = sys.getrefcount(s1)-1 # Check that ref is incremented s2 = s1 number_of_references_to_s1 = sys.getrefcount(s1)-1 self.assertEqual(number_of_references_to_s1, 2) # Check that ref is decremented after s2 is deleted del s2 number_of_references_to_s1 = sys.getrefcount(s1)-1 self.assertEqual(number_of_references_to_s1, 1)
def testCollector(self): GarbageCollector.garbage.smart_purge() # Check that pythonOCC objects are collected in the correct garbage s = Standard_Transient() h = Handle_Standard_Transient() P = gp_Pnt(1, 2, 3) del s del h del P self.assertEqual(len(GarbageCollector.garbage._handles), 1) self.assertEqual(len(GarbageCollector.garbage._transients), 1) self.assertEqual(len(GarbageCollector.garbage._misc), 1)
def testNullifyHandle(self): s = Standard_Transient() self.assertEqual(s.GetRefCount(), 0) # create an hanle from this transient. RefCount is incremented h = s.GetHandle() self.assertEqual(h.IsNull(), False) self.assertEqual(s.GetRefCount(), 1) # if this handle is nullified, refcount is decremented h.Nullify() self.assertEqual(h.IsNull(), True) self.assertEqual(s.GetRefCount(), 0)
def test_handle_standard_transient_copy(self): def evil_function(t): handle = Handle_Standard_Transient(t) t = Standard_Transient() evil_function(t)