Skip to content

Commit

Permalink
some more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapratico committed Jun 14, 2021
1 parent e44172e commit 6fcb85c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from azure.core.paging import ItemPaged
from azure.core.tracing.decorator import distributed_trace
from azure.core.exceptions import HttpResponseError
from ._base_client import TextAnalyticsClientBase
from ._base_client import TextAnalyticsClientBase, TextAnalyticsApiVersion
from ._request_handlers import (
_validate_input,
_determine_action_type,
Expand Down Expand Up @@ -785,6 +785,10 @@ def analyze_sentiment( # type: ignore
kwargs.update({"string_index_type": string_index_type})

if show_opinion_mining is not None:
if self._api_version == TextAnalyticsApiVersion.V3_0 and show_opinion_mining:
raise ValueError(
"'show_opinion_mining' is only available for API version v3.1 and up"
)
kwargs.update({"opinion_mining": show_opinion_mining})

try:
Expand All @@ -795,12 +799,6 @@ def analyze_sentiment( # type: ignore
cls=kwargs.pop("cls", sentiment_result),
**kwargs
)
except TypeError as error:
if "opinion_mining" in str(error):
raise ValueError(
"'show_opinion_mining' is only available for API version v3.1 and up"
)
raise error
except HttpResponseError as error:
process_http_response_error(error)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from azure.core.exceptions import HttpResponseError
from azure.core.credentials import AzureKeyCredential
from ._base_client_async import AsyncTextAnalyticsClientBase
from .._base_client import TextAnalyticsApiVersion
from .._request_handlers import _validate_input, _determine_action_type, _check_string_index_type_arg
from .._response_handlers import (
process_http_response_error,
Expand Down Expand Up @@ -646,6 +647,10 @@ async def analyze_sentiment( # type: ignore
kwargs.update({"string_index_type": string_index_type})

if show_opinion_mining is not None:
if self._api_version == TextAnalyticsApiVersion.V3_0 and show_opinion_mining:
raise ValueError(
"'show_opinion_mining' is only available for API version v3.1 and up"
)
kwargs.update({"opinion_mining": show_opinion_mining})

try:
Expand All @@ -656,12 +661,6 @@ async def analyze_sentiment( # type: ignore
cls=kwargs.pop("cls", sentiment_result),
**kwargs
)
except TypeError as error:
if "opinion_mining" in str(error):
raise ValueError(
"'show_opinion_mining' is only available for API version v3.1 and up"
)
raise error
except HttpResponseError as error:
process_http_response_error(error)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,6 @@ async def test_out_of_order_ids_multiple_tasks(self, client):
@TextAnalyticsClientPreparer()
async def test_show_stats_and_model_version_multiple_tasks(self, client):

def callback(resp):
if not resp.raw_response:
# this is the initial post call
request_body = json.loads(resp.http_request.body)
assert len(request_body["tasks"]) == 5
for task in request_body["tasks"].values():
assert len(task) == 1
assert task[0]['parameters']['model-version'] == 'latest'
assert not task[0]['parameters']['loggingOptOut']

docs = [{"id": "56", "text": ":)"},
{"id": "0", "text": ":("},
{"id": "19", "text": ":P"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def test_opinion_mining_v3(self, client):
with pytest.raises(ValueError) as excinfo:
client.analyze_sentiment(["will fail"], show_opinion_mining=True)

assert "'show_opinion_mining' is only available for API version v3.1-preview and up" in str(excinfo.value)
assert "'show_opinion_mining' is only available for API version v3.1 and up" in str(excinfo.value)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ async def test_opinion_mining_v3(self, client):
with pytest.raises(ValueError) as excinfo:
await client.analyze_sentiment(["will fail"], show_opinion_mining=True)

assert "'show_opinion_mining' is only available for API version v3.1-preview and up" in str(excinfo.value)
assert "'show_opinion_mining' is only available for API version v3.1 and up" in str(excinfo.value)

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def test_v3_0_api_version(self, client):
assert "v3.0" in client._client._client._base_url

@GlobalTextAnalyticsAccountPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"api_version": TextAnalyticsApiVersion.V3_1_PREVIEW})
@TextAnalyticsClientPreparer(client_kwargs={"api_version": TextAnalyticsApiVersion.V3_1})
def test_v3_1_api_version(self, client):
assert "v3.1" in client._client._client._base_url

0 comments on commit 6fcb85c

Please sign in to comment.