Example #1
0
    def testSet(self):
        """Test adding values via struct.name=val
        """
        s = taskBase.Struct()
        for name, val in self.valDict.items():
            setattr(s, name, val)

        self.assertEqual(self.valDict, s.getDict())
Example #2
0
    def testInit(self):
        """Test Struct.__init__
        """
        s = taskBase.Struct(**self.valDict)
        self.assertEqual(self.valDict, s.getDict())

        for name, val in self.valDict.items():
            self.assertEqual(getattr(s, name), val)
Example #3
0
    def testMergeItems(self):
        """Test mergeItems
        """
        s = taskBase.Struct(**self.valDict)
        newS = taskBase.Struct()
        newS.mergeItems(s)
        # with no names listed, should merge nothing
        self.assertEqual(len(newS), 0)
        self.assertNotEqual(s, newS)

        newS.mergeItems(s, "foo", "bar")
        self.assertEqual(len(newS), 2)
        self.assertNotEqual(s, newS)

        newS.mergeItems(s, "baz", "alist")
        self.assertEqual(len(newS), 4)

        for name, val in newS.getDict().items():
            self.assertEqual(val, self.valDict[name])
            with self.assertRaises(RuntimeError):
                newS.mergeItems(s, name)
Example #4
0
    def testCopy(self):
        """Test copy, which returns a shallow copy
        """
        s = taskBase.Struct(**self.valDict)
        sc = s.copy()
        self.assertEqual(s.getDict(), sc.getDict())

        # shallow copy, so changing a list should propagate (not necessarily a
        # feature)
        sc.alist[0] = 97
        self.assertEqual(s, sc)

        sc.foo += 1
        self.assertNotEqual(s, sc)
Example #5
0
 def run(self, val):
     with self.timer("context"):
         addRet = self.add.run(val)
         multRet = self.mult.run(addRet.val)
         self.metadata.add("addmult", multRet.val)
         return taskBase.Struct(val=multRet.val, )
Example #6
0
 def run(self, val):
     self.metadata.add("mult", self.config.multiplicand)
     return taskBase.Struct(val=val * self.config.multiplicand, )
Example #7
0
 def run(self, val):
     self.metadata.add("add", self.config.addend)
     return taskBase.Struct(val=val + self.config.addend, )
Example #8
0
 def run(self, val):
     addend = self.config.addend
     return taskBase.Struct(val=val + (2 * addend))
Example #9
0
 def testInitException(self):
     """Test that struct key names cannot start with double underscores.
     """
     with self.assertRaises(RuntimeError):
         taskBase.Struct(__foo=13)