예제 #1
0
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])
예제 #2
0
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',))"""
예제 #3
0
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'})"""
예제 #4
0
    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
예제 #5
0
def test_repr_without_value():
    obs = Observation("an observation")
    assert repr(obs) == "Observation(name='an observation', value=Unrecorded)"
예제 #6
0
 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)
예제 #7
0
 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)