Example #1
0
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"
Example #2
0
 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)
Example #3
0
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"
Example #4
0
 def setup(self):
     self.datadict = DataDict()
     self.datadict.item_cls = Data
     self.datadict.key = "tag"
Example #5
0
 def __init__(self):
     DataDict.__init__(self)
     self.id_gen = IncrID()
Example #6
0
 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)
Example #7
0
 def setup (self):
     self.datadict = DataDict()
     self.datadict.item_cls = Data
     self.datadict.key = "tag"
Example #8
0
 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)
Example #9
0
 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)