def _test_hit_memory(self): gc.collect() hitcore_memory = Hitcore.dump_memory() for address, number_of_allocations in hitcore_memory.items(): if number_of_allocations != 0: print("Hitcore not deleted at address", address, \ "with", number_of_allocations, "remaining references") self.assertEqual(sum(hitcore_memory.values()), 0)
def test_get_item(self): mem_dump_in = Hitcore.dump_memory() bc1 = Bunchcore() hc1 = Hitcore() self.assertEqual(sys.getrefcount(hc1), 2) bc1.set_item(hc1, 0) self.assertEqual(sys.getrefcount(hc1), 2) hc2 = bc1.get_item(0) self.assertEqual(sys.getrefcount(hc2), 2) self.assertEqual(hc1, hc2) hc3 = bc1.get_item(-1) self.assertEqual(hc3, hc1) hc11 = Hitcore() bc1.set_item(hc11, 1) hc12 = bc1.get_item(1) self.assertEqual(hc12, hc11) self.assertNotEqual(hc12, hc1) hc13 = bc1.get_item(-2) self.assertEqual(hc13, hc11) bc1.set_item(hc11, 4) hc22 = bc1.get_item(4) self.assertEqual(hc22, hc11) hc23 = bc1.get_item(-5) self.assertEqual(hc23, hc11) hc24 = bc1.get_item(3) # no value stored, pad with None self.assertEqual(hc24, None) try: bc1.get_item("not an int") raise RuntimeError("Expected an exception") except TypeError: pass del (bc1) self.assertEqual(sys.getrefcount(hc1), 2)