def test_lazy_nested_clear_access(): reqs = (LazyRequest(r.SerializeToString(), Envelope()) for r in _generate(random_docs(10))) for r in reqs: assert not r.is_used # write access r.train r.index.ClearField('docs') # now it is read assert r.is_used
def test_lazy_append_access(): reqs = (LazyRequest(r.SerializeToString(), Envelope()) for r in _generate(random_docs(10))) for r in reqs: assert not r.is_used # write access r.train r.docs.append(jina_pb2.Document()) # now it is read assert r.is_used
def test_lazy_change_message_type(): reqs = (LazyRequest(r.SerializeToString(), Envelope()) for r in _generate(random_docs(10))) for r in reqs: assert not r.is_used # write access r.train r.control.command = jina_pb2.Request.ControlRequest.IDLE # now it is read assert r.is_used assert len(r.index.docs) == 0
def test_lazy_nest_access(): reqs = (LazyRequest(r.SerializeToString(), Envelope()) for r in _generate(random_docs(10))) for r in reqs: assert not r.is_used # write access r.train r.docs[0].id = '1' # now it is read assert r.is_used assert r.index.docs[0].id == '1'
def test_lazy_access(field): reqs = (LazyRequest(r.SerializeToString(), Envelope()) for r in _generate(random_docs(10))) for r in reqs: assert not r.is_used # access r.train print(getattr(r, field)) # now it is read assert r.is_used
def test_multiple_access(): reqs = [ LazyRequest(r.SerializeToString(), Envelope()) for r in _generate(random_docs(10)) ] for r in reqs: assert not r.is_used assert r assert not r.is_used for r in reqs: assert not r.is_used assert r.index assert r.is_used
def test_lazy_request_fields(): reqs = (LazyRequest(r.SerializeToString(), Envelope()) for r in _generate(random_docs(10))) for r in reqs: assert list(r.DESCRIPTOR.fields_by_name.keys())
def get_prev_reqs(): # three requests, each with the SAME doc, but diff evaluations result = [] for j in range(3): r = jina_pb2.Request() d = r.index.docs.add() d.id = 'SAME DOC THEY ARE' # same doc id ev1 = d.evaluations.add() ev1.value = j # diff eval ev1.op_name = f'op{j}' # diff eval result.append(r) return result prev_reqs = list(get_prev_reqs()) ev = Envelope() ev.num_part.extend([1, 3]) prev_msgs = [ ProtoMessage(ev, r.SerializeToString(), 'test', 'placeholder') for r in prev_reqs ] class MockCollectEvalDriver(CollectEvaluationDriver): @property def exec_fn(self): return self._exec_fn def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._num_call = -1