def test_clear(self): """Verifies that clear works as expected""" h = Assoc(_u.new_assoc(), freeit=True) a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False) h[a] = a h.clear() self.assertFalse(a in h)
def test_copy(self): """Tests the copy behavior""" h = Assoc(_u.new_assoc(), freeit=True) a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False) h[a] = a h2 = h.copy() self.assertTrue(a in h2)
def test_associative_array(self): """ This function tests the basic functions of the associative array proto """ h = Assoc(_u.new_assoc(), freeit=True) a = Node.from_ptr(parse_simple_expression("a.car = 3"), freeit=False) b = Node.from_ptr(parse_simple_expression("b.car = 3"), freeit=False) # __contains__ self.assertFalse(a in h) # __setitem__ h[a] = a self.assertTrue(a in h) # __getitem__ self.assertEqual(h[a], a) with self.assertRaises(KeyError): h[b] # __delitem__ del h[a] self.assertFalse(a in h)