def q_add(self, specs, callback=None, cargs={}): """Add a process group to the container""" for spec in specs: if spec.get("id", "*") != "*": raise DataCreationError("cannot specify an id") spec["id"] = self.id_gen.next() return DataDict.q_add(self, specs, callback, cargs)
class TestDataDict (object): def setup (self): self.datadict = DataDict() self.datadict.item_cls = Data self.datadict.key = "tag" def test_q_add (self): one = {'tag':"one"} two = {'tag':"two"} self.datadict.q_add([one, two]) assert len(self.datadict) == 2 assert self.datadict['one'].tag == "one" assert self.datadict['two'].tag == "two" try: self.datadict.q_add([one]) except KeyError: pass else: assert not "Allowed multiple entries for same key." def test_q_get (self): one = {'tag':"one"} two = {'tag':"two"} three = {'tag':"three"} self.datadict.q_add([one, two, three]) items = self.datadict.q_get([{'tag':"three"}]) assert len(items) == 1 assert items[0] is self.datadict["three"] assert items[0].tag == "three" def test_q_del (self): one = {'tag':"one"} two = {'tag':"two"} three = {'tag':"three"} self.datadict.q_add([one, two, three]) deleted = self.datadict.q_del([{'tag':"two"}]) assert len(deleted) == 1 assert deleted[0].tag == "two" assert len(self.datadict) == 2 assert self.datadict["one"].tag == "one" try: self.datadict["two"] except KeyError: pass else: assert not "Failed to remove item from list." assert self.datadict["three"].tag == "three"
class TestDataDict(object): def setup(self): self.datadict = DataDict() self.datadict.item_cls = Data self.datadict.key = "tag" def test_q_add(self): one = {'tag': "one"} two = {'tag': "two"} self.datadict.q_add([one, two]) assert len(self.datadict) == 2 assert self.datadict['one'].tag == "one" assert self.datadict['two'].tag == "two" try: self.datadict.q_add([one]) except KeyError: pass else: assert not "Allowed multiple entries for same key." def test_q_get(self): one = {'tag': "one"} two = {'tag': "two"} three = {'tag': "three"} self.datadict.q_add([one, two, three]) items = self.datadict.q_get([{'tag': "three"}]) assert len(items) == 1 assert items[0] is self.datadict["three"] assert items[0].tag == "three" def test_q_del(self): one = {'tag': "one"} two = {'tag': "two"} three = {'tag': "three"} self.datadict.q_add([one, two, three]) deleted = self.datadict.q_del([{'tag': "two"}]) assert len(deleted) == 1 assert deleted[0].tag == "two" assert len(self.datadict) == 2 assert self.datadict["one"].tag == "one" try: self.datadict["two"] except KeyError: pass else: assert not "Failed to remove item from list." assert self.datadict["three"].tag == "three"
def q_add (self, specs, callback=None, cargs={}): for spec in specs: if spec.get("id", "*") != "*": raise DataCreationError("cannot specify an id") spec['id'] = self.id_gen.next() return DataDict.q_add(self, specs)
def q_add (self, specs, callback=None, cargs={}): for spec in specs: if "id" not in spec or spec['id'] == "*": spec['id'] = self.id_gen.next() return DataDict.q_add(self, specs)
def q_add(self, specs, callback=None, cargs={}): for spec in specs: if spec.get("id", "*") != "*": raise DataCreationError("cannot specify an id") spec['id'] = self.id_gen.next() return DataDict.q_add(self, specs)