Changeset 142

Show
Ignore:
Timestamp:
04/08/08 15:58:31 (8 months ago)
Author:
edsuom
Message:

Updated some names to indicate that parameter sequences are used, not Numpy vectors of numeric-only parameters; tested multiple inheritance from Paremeterized

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/Twisted-Goodies/trunk/twisted_goodies/pybywire/params.py

    r120 r142  
    7474      keyword, or set directly before use. 
    7575 
    76     @cvar paramNames: A sequence of names for my parameter. Parameter vector
    77       must be supplied to L{setParamVector} in that order. 
     76    @cvar paramNames: A sequence of names for my parameter. Parameter sequence
     77      must be supplied to L{setParamSequence} in that order. 
    7878 
    7979    """ 
     
    121121            else: 
    122122                isDifferent = (getattr(self, name) != value) 
    123                 # Account for the possibility that one value is a Numpy array 
     123                # Account for the possibility that the value may be a Numpy 
     124                # array 
    124125                if hasattr(isDifferent, 'any'): 
    125126                    isDifferent = isDifferent.any() 
     
    144145            setattr(self, name, value) 
    145146 
    146     def paramVector(self): 
     147    def paramSequence(self): 
    147148        """ 
    148149        Returns my entire current set of parameters as a sequence. 
     
    150151        return [getattr(self, name) for name in self.paramNames] 
    151152 
    152     def setParamVector(self, paramVector): 
     153    def setParamSequence(self, paramSequence): 
    153154        """ 
    154         Sets the entire set of parameters from the supplied I{paramVector} of 
     155        Sets the entire set of parameters from the supplied I{paramSequence} of 
    155156        values. 
    156157        """ 
    157         if len(paramVector) != len(self.paramNames): 
     158        if len(paramSequence) != len(self.paramNames): 
    158159            raise ValueError("You must supply the exact number of parameters") 
    159160        for k, name in enumerate(self.paramNames): 
    160             value = paramVector[k] 
     161            value = paramSequence[k] 
    161162            setattr(self, name, value) 
    162163 
  • projects/Twisted-Goodies/trunk/twisted_goodies/pybywire/test/test_params.py

    r114 r142  
    3030 
    3131 
    32 class Thingy(params.Parameterized): 
     32class Mixin(object): 
     33    """ 
     34    I am just here to show that a subclass of L{params.Parameterized} can also 
     35    mix me in as well. 
     36    """ 
     37    def mixinMethod(self, x): 
     38        return 103*x 
     39 
     40class Thingy(params.Parameterized, Mixin): 
    3341    keyAttrs = {'a':None, 'b':2.0} 
    3442    paramNames = ('c', 'd') 
     
    92100        self.failUnlessElementsEqual(state.values(), expectedState.values()) 
    93101 
     102    def test_mixinMethod(self): 
     103        self.failUnlessEqual(self.ct.mixinMethod(10), 1030) 
     104 
    94105 
    95106class Test_Parameterized_Remote(mock.TestCase): 
     
    175186        d.addCallback(self._checkCopy, ct, 'a') 
    176187        return d 
     188 
     189    def test_mixinMethod(self): 
     190        def runBoth(ctRemote): 
     191            for ctObj in (ctRemote, ct): 
     192                self.failUnlessEqual(ctObj.mixinMethod(10), 1030) 
     193             
     194        ct = Thingy(a=1.0, b=2.0, c=3.0, d=4.0) 
     195        d = self.getReferenceToRoot(self.CopyableReturner(ct)) 
     196        d.addCallback(lambda _: self.ref.callRemote("giveMeCopy", ct)) 
     197        d.addErrback(self._oops) 
     198        d.addCallback(runBoth) 
     199        return d 
     200 
     201