Skip to content

Commit

Permalink
fix(client): raise exception on bad input
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed May 27, 2020
1 parent fda5790 commit 82c7c52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions jina/clients/python/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def _generate(data: Union[Iterator[bytes], Iterator['jina_pb2.Document'], Iterat
d.file_path = _raw
elif scheme == 'data':
d.data_uri = _raw
else:
raise TypeError(f'{type(_raw)} type of input is not supported')

d.doc_id = first_doc_id if not random_doc_id else random.randint(0, ctypes.c_uint(-1).value)
d.weight = 1.0
first_doc_id += 1
Expand Down
6 changes: 3 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def test_check_input(self):
PyClient.check_input(input_fn)
input_fn = iter([Document(), Document()])
PyClient.check_input(input_fn, input_type=ClientInputType.PROTOBUF)
# bad_input_fn = iter([b'1234', '45467']) this is invalid as we convert str to binary
# self.assertRaises(TypeError, PyClient.check_input, bad_input_fn)
bad_input_fn = iter([Document()])
bad_input_fn = iter([b'1234', '45467', [12, 2, 3]])
self.assertRaises(TypeError, PyClient.check_input, bad_input_fn)
bad_input_fn = iter([Document(), None])
self.assertRaises(TypeError, PyClient.check_input, bad_input_fn)

def test_gateway_ready(self):
Expand Down

0 comments on commit 82c7c52

Please sign in to comment.