def test_wait(self): b = ProcessBus() self.log(b) def f(desired_state): time.sleep(0.2) b.transition(desired_state) for desired_state_, states_to_wait_for in [ ('RUN', ['RUN']), ('IDLE', ['IDLE']), ('RUN', ['START', 'RUN']), ('EXITED', ['EXITED']) ]: threading.Thread(target=f, args=(desired_state_,)).start() b.wait(states_to_wait_for) # The wait method MUST wait for the given state(s). if b.state not in states_to_wait_for: self.fail('State %r not in %r' % (b.state, states_to_wait_for))
def test_wait(self): b = ProcessBus() self.log(b) def f(desired_state): time.sleep(0.2) b.transition(desired_state) for desired_state_, states_to_wait_for in [('RUN', ['RUN']), ('IDLE', ['IDLE']), ('RUN', ['START', 'RUN']), ('EXITED', ['EXITED'])]: threading.Thread(target=f, args=(desired_state_, )).start() b.wait(states_to_wait_for) actual_state = b.state # The wait method MUST wait for the given state(s). assert actual_state in states_to_wait_for, ( 'State {actual_state!r} not in {expected_states!r}.\n' 'Log entries: {logs!r}'.format( actual_state=actual_state, expected_states=states_to_wait_for, logs=self._log_entries, ))