def Evaluate(self, state): """Evaluates the condition using the values in *state*. * *state* is a :py:class:`~pyslet.qtiv2.variables.TestSessionState` instance.""" if self.Expression is None: raise core.ProcessingError( "preCondition or branchRule with missing condition") value = self.Expression.Evaluate(state) variables.CheckBaseTypes(value.baseType, variables.BaseType.boolean) variables.CheckCardinalities(value.Cardinality(), variables.Cardinality.single) return value and value.value
def Run(self, state): """Run this test and, if True, any resulting rules. Returns *True* if the condition evaluated to *True*.""" if self.Expression is None: raise core.ProcessingError("templateIf with missing condition") value = self.Expression.Evaluate(state) variables.CheckBaseTypes(value.baseType, variables.BaseType.boolean) variables.CheckCardinalities(value.Cardinality(), variables.Cardinality.single) if value and value.value: for r in self.TemplateRule: r.Run(state) return True else: return False