Changeset 142
- Timestamp:
- 04/08/08 15:58:31 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/Twisted-Goodies/trunk/twisted_goodies/pybywire/params.py
r120 r142 74 74 keyword, or set directly before use. 75 75 76 @cvar paramNames: A sequence of names for my parameter. Parameter vectors77 must be supplied to L{setParam Vector} in that order.76 @cvar paramNames: A sequence of names for my parameter. Parameter sequences 77 must be supplied to L{setParamSequence} in that order. 78 78 79 79 """ … … 121 121 else: 122 122 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 124 125 if hasattr(isDifferent, 'any'): 125 126 isDifferent = isDifferent.any() … … 144 145 setattr(self, name, value) 145 146 146 def param Vector(self):147 def paramSequence(self): 147 148 """ 148 149 Returns my entire current set of parameters as a sequence. … … 150 151 return [getattr(self, name) for name in self.paramNames] 151 152 152 def setParam Vector(self, paramVector):153 def setParamSequence(self, paramSequence): 153 154 """ 154 Sets the entire set of parameters from the supplied I{param Vector} of155 Sets the entire set of parameters from the supplied I{paramSequence} of 155 156 values. 156 157 """ 157 if len(param Vector) != len(self.paramNames):158 if len(paramSequence) != len(self.paramNames): 158 159 raise ValueError("You must supply the exact number of parameters") 159 160 for k, name in enumerate(self.paramNames): 160 value = param Vector[k]161 value = paramSequence[k] 161 162 setattr(self, name, value) 162 163 projects/Twisted-Goodies/trunk/twisted_goodies/pybywire/test/test_params.py
r114 r142 30 30 31 31 32 class Thingy(params.Parameterized): 32 class 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 40 class Thingy(params.Parameterized, Mixin): 33 41 keyAttrs = {'a':None, 'b':2.0} 34 42 paramNames = ('c', 'd') … … 92 100 self.failUnlessElementsEqual(state.values(), expectedState.values()) 93 101 102 def test_mixinMethod(self): 103 self.failUnlessEqual(self.ct.mixinMethod(10), 1030) 104 94 105 95 106 class Test_Parameterized_Remote(mock.TestCase): … … 175 186 d.addCallback(self._checkCopy, ct, 'a') 176 187 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
