Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
raise better error for multiapi
  • Loading branch information
kristapratico committed Oct 7, 2020
commit 5a70733358c18ffe112458d8e47a1621ba6b3acf
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument
cls = kwargs.pop("cls", None)
display_name = kwargs.pop("display_name", None)
if display_name and self.api_version == "2.0":
raise ValueError("'display_name' is only available for API version v2.1-preview and up")
raise ValueError("'display_name' is only available for API version V2_1_PREVIEW and up")
continuation_token = kwargs.pop("continuation_token", None)
polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval)

Expand Down Expand Up @@ -417,14 +417,18 @@ def _compose_callback(raw_response, _, headers): # pylint: disable=unused-argum
display_name = kwargs.pop("display_name", None)
polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval)
continuation_token = kwargs.pop("continuation_token", None)

return self._client.begin_compose_custom_models_async(
{"model_ids": model_ids, "model_name": display_name},
cls=kwargs.pop("cls", _compose_callback),
polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[TrainingPolling()], **kwargs),
continuation_token=continuation_token,
**kwargs
)
try:
return self._client.begin_compose_custom_models_async(
{"model_ids": model_ids, "model_name": display_name},
cls=kwargs.pop("cls", _compose_callback),
polling=LROBasePolling(timeout=polling_interval, lro_algorithms=[TrainingPolling()], **kwargs),
continuation_token=continuation_token,
**kwargs
)
except ValueError:
raise ValueError(
"Method 'begin_create_composed_model' is only available for API version V2_1_PREVIEW and up"
)

def get_form_recognizer_client(self, **kwargs):
# type: (Any) -> FormRecognizerClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument
cls = kwargs.pop("cls", None)
display_name = kwargs.pop("display_name", None)
if display_name and self.api_version == "2.0":
raise ValueError("'display_name' is only available for API version v2.1-preview and up")
raise ValueError("'display_name' is only available for API version V2_1_PREVIEW and up")
continuation_token = kwargs.pop("continuation_token", None)
polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval)

Expand Down Expand Up @@ -429,13 +429,18 @@ def _compose_callback(raw_response, _, headers): # pylint: disable=unused-argum
polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval)
continuation_token = kwargs.pop("continuation_token", None)

return await self._client.begin_compose_custom_models_async( # type: ignore
{"model_ids": model_ids, "model_name": display_name},
cls=kwargs.pop("cls", _compose_callback),
polling=AsyncLROBasePolling(timeout=polling_interval, lro_algorithms=[TrainingPolling()], **kwargs),
continuation_token=continuation_token,
**kwargs
)
try:
return await self._client.begin_compose_custom_models_async( # type: ignore
{"model_ids": model_ids, "model_name": display_name},
cls=kwargs.pop("cls", _compose_callback),
polling=AsyncLROBasePolling(timeout=polling_interval, lro_algorithms=[TrainingPolling()], **kwargs),
continuation_token=continuation_token,
**kwargs
)
except ValueError:
raise ValueError(
"Method 'begin_create_composed_model' is only available for API version V2_1_PREVIEW and up"
)

def get_form_recognizer_client(self, **kwargs: Any) -> FormRecognizerClient:
"""Get an instance of a FormRecognizerClient from FormTrainingClient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ def test_compose_model_bad_api_version(self, client, container_sas_url):
with pytest.raises(ValueError) as excinfo:
poller = client.begin_create_composed_model(["00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000"])
result = poller.result()
assert "API version 2.0 does not have operation 'begin_compose_custom_models_async'" in str(excinfo.value)
assert "Method 'begin_create_composed_model' is only available for API version V2_1_PREVIEW and up" in str(excinfo.value)
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ async def test_compose_model_bad_api_version(self, client, container_sas_url):
with pytest.raises(ValueError) as excinfo:
poller = await client.begin_create_composed_model(["00000000-0000-0000-0000-000000000000", "00000000-0000-0000-0000-000000000000"])
result = await poller.result()
assert "API version 2.0 does not have operation 'begin_compose_custom_models_async'" in str(excinfo.value)
assert "Method 'begin_create_composed_model' is only available for API version V2_1_PREVIEW and up" in str(excinfo.value)
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ def test_training_with_display_name_bad_api_version(self, client, container_sas_
with pytest.raises(ValueError) as excinfo:
poller = client.begin_training(training_files_url="url", use_training_labels=True, display_name="not supported in v2.0")
result = poller.result()
assert "'display_name' is only available for API version v2.1-preview and up" in str(excinfo.value)
assert "'display_name' is only available for API version V2_1_PREVIEW and up" in str(excinfo.value)
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,4 @@ async def test_training_with_display_name_bad_api_version(self, client, containe
with pytest.raises(ValueError) as excinfo:
poller = await client.begin_training(training_files_url="url", use_training_labels=True, display_name="not supported in v2.0")
result = await poller.result()
assert "'display_name' is only available for API version v2.1-preview and up" in str(excinfo.value)
assert "'display_name' is only available for API version V2_1_PREVIEW and up" in str(excinfo.value)