def test_replacement_1(self): n1 = Node().store() n2 = Node().store() n1.set_extra("pippo", [1, 2, u'a']) n1.set_extra("pippobis", [5, 6, u'c']) n2.set_extra("pippo2", [3, 4, u'b']) self.assertEqual(n1.get_extras(), {'pippo': [1, 2, u'a'], 'pippobis': [5, 6, u'c'], '_aiida_hash': n1.get_hash()}) self.assertEquals(n2.get_extras(), {'pippo2': [3, 4, 'b'], '_aiida_hash': n2.get_hash()}) new_attrs = {"newval1": "v", "newval2": [1, {"c": "d", "e": 2}]} n1.reset_extras(new_attrs) self.assertEquals(n1.get_extras(), new_attrs) self.assertEquals(n2.get_extras(), {'pippo2': [3, 4, 'b'], '_aiida_hash': n2.get_hash()}) n1.del_extra('newval2') del new_attrs['newval2'] self.assertEquals(n1.get_extras(), new_attrs) # Also check that other nodes were not damaged self.assertEquals(n2.get_extras(), {'pippo2': [3, 4, 'b'], '_aiida_hash': n2.get_hash()})
def test_delete_extras(self): """ Checks the ability of deleting extras, also when they are dictionaries or lists. """ a = Node().store() extras_to_set = { 'bool': self.boolval, 'integer': self.intval, 'float': self.floatval, 'string': self.stringval, 'dict': self.dictval, 'list': self.listval, 'further': 267, } for k, v in extras_to_set.iteritems(): a.set_extra(k, v) self.assertEquals({k: v for k, v in a.iterextras()}, extras_to_set) # I pregenerate it, it cannot change during iteration list_keys = list(extras_to_set.keys()) for k in list_keys: # I delete one by one the keys and check if the operation is # performed correctly a.del_extra(k) del extras_to_set[k] self.assertEquals({k: v for k, v in a.iterextras()}, extras_to_set)