def test_poll(mocks: Mocks, context: yogi.Context): """Checks the poll() function in the error-free case""" def fn(context, count): assert context == 1234 assert count count.contents.value = 5 return yogi.ErrorCode.OK mocks.MOCK_ContextPoll(fn) assert context.poll() == 5
def run_context_until_branches_are_connected( self, context: yogi.Context, branches: List[yogi.Branch]) -> None: uuids = {} for branch in branches: uuids[branch] = [x.uuid for x in branches if x is not branch] start = time.time() while uuids: context.poll() branch = next(iter(uuids)) for uuid in branch.get_connected_branches(): if uuid in uuids[branch]: uuids[branch].remove(uuid) if not uuids[branch]: del uuids[branch] if time.time() - start > 3: print(uuids) raise TimeoutError("Branches did not connect")
def test_poll_error(mocks: Mocks, context: yogi.Context): """Checks the poll() function in the error case""" mocks.MOCK_ContextPoll(lambda *_: yogi.ErrorCode.WRONG_OBJECT_TYPE) with pytest.raises(yogi.FailureException): context.poll()