def result_factory(first, second): control = Observation('Control') control.set_start_time() control.record(first) control.set_end_time() candidate = Observation('Candidate') candidate.set_start_time() candidate.record(second) candidate.set_end_time() return Result(experiments.Experiment(), control, [candidate])
def test_repr_with_exception(): obs = Observation("an observation") obs.set_exception(ValueError("something is wrong")) assert repr( obs ) == """Observation(name='an observation', value=Unrecorded, exception=ValueError('something is wrong',))"""
def test_repr(): obs = Observation("an observation") a_somewhat_complex_value = {'foo': 'bar'} obs.record(a_somewhat_complex_value) assert repr( obs) == """Observation(name='an observation', value={'foo': 'bar'})"""
def _run_tested_func(self, func, args, kwargs, name, context, raise_on_exception): ctx = deepcopy(self.get_context()) ctx.update(context) obs = Observation(name, ctx) obs.set_start_time() try: obs.record(func(*args, **kwargs)) except Exception as ex: obs.set_exception(ex) if raise_on_exception: raise finally: obs.set_end_time() return obs
def test_repr_without_value(): obs = Observation("an observation") assert repr(obs) == "Observation(name='an observation', value=Unrecorded)"
def candidate(self, name='Candidate', context=None): _context = deepcopy(self.context) _context.update(context or {}) observation = Observation(name, context=_context) self._observations.append(observation) return Test(observation, False)
def control(self, name='Control', context=None): _context = deepcopy(self.context) _context.update(context or {}) self._control = Observation(name, context=_context) return Test(self._control, True)