def testGC(self): GarbageCollector.garbage.smart_purge() h = Handle_Standard_Transient() h2 = h # adds a reference del h # this object is not collected since there is another reference to it self.assertEqual(len(GarbageCollector.garbage._handles), 0) del h2 # now, the handle should be collected self.assertEqual(len(GarbageCollector.garbage._handles), 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 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 evil_function(t): handle = Handle_Standard_Transient(t)