Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[textanalytics] switch to kwargs where we run nonrecorded tests #22614

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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

This file was deleted.

43 changes: 23 additions & 20 deletions sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,15 +1235,16 @@ def test_analyze_continuation_token(self, client):
@TextAnalyticsCustomPreparer()
def test_generic_action_error_no_target(
self,
textanalytics_custom_text_endpoint,
textanalytics_custom_text_key,
textanalytics_single_category_classify_project_name,
textanalytics_single_category_classify_deployment_name,
textanalytics_multi_category_classify_project_name,
textanalytics_multi_category_classify_deployment_name,
textanalytics_custom_entities_project_name,
textanalytics_custom_entities_deployment_name
**kwargs
):
textanalytics_custom_text_endpoint = kwargs.pop("textanalytics_custom_text_endpoint")
textanalytics_custom_text_key = kwargs.pop("textanalytics_custom_text_key")
textanalytics_single_category_classify_project_name = kwargs.pop("textanalytics_single_category_classify_project_name")
textanalytics_single_category_classify_deployment_name = kwargs.pop("textanalytics_single_category_classify_deployment_name")
textanalytics_multi_category_classify_project_name = kwargs.pop("textanalytics_multi_category_classify_project_name")
textanalytics_multi_category_classify_deployment_name = kwargs.pop("textanalytics_multi_category_classify_deployment_name")
textanalytics_custom_entities_project_name = kwargs.pop("textanalytics_custom_entities_project_name")
textanalytics_custom_entities_deployment_name = kwargs.pop("textanalytics_custom_entities_deployment_name")
docs = [
{"id": "1", "language": "en", "text": "A recent report by the Government Accountability Office (GAO) found that the dramatic increase in oil and natural gas development on federal lands over the past six years has stretched the staff of the BLM to a point that it has been unable to meet its environmental protection responsibilities."},
{"id": "2", "language": "en", "text": ""},
Expand Down Expand Up @@ -1296,15 +1297,16 @@ def test_generic_action_error_no_target(
@TextAnalyticsCustomPreparer()
def test_action_errors_with_targets(
self,
textanalytics_custom_text_endpoint,
textanalytics_custom_text_key,
textanalytics_single_category_classify_project_name,
textanalytics_single_category_classify_deployment_name,
textanalytics_multi_category_classify_project_name,
textanalytics_multi_category_classify_deployment_name,
textanalytics_custom_entities_project_name,
textanalytics_custom_entities_deployment_name
**kwargs
):
textanalytics_custom_text_endpoint = kwargs.pop("textanalytics_custom_text_endpoint")
textanalytics_custom_text_key = kwargs.pop("textanalytics_custom_text_key")
textanalytics_single_category_classify_project_name = kwargs.pop("textanalytics_single_category_classify_project_name")
textanalytics_single_category_classify_deployment_name = kwargs.pop("textanalytics_single_category_classify_deployment_name")
textanalytics_multi_category_classify_project_name = kwargs.pop("textanalytics_multi_category_classify_project_name")
textanalytics_multi_category_classify_deployment_name = kwargs.pop("textanalytics_multi_category_classify_deployment_name")
textanalytics_custom_entities_project_name = kwargs.pop("textanalytics_custom_entities_project_name")
textanalytics_custom_entities_deployment_name = kwargs.pop("textanalytics_custom_entities_deployment_name")
docs = [
{"id": "1", "language": "en", "text": "A recent report by the Government Accountability Office (GAO) found that the dramatic increase in oil and natural gas development on federal lands over the past six years has stretched the staff of the BLM to a point that it has been unable to meet its environmental protection responsibilities."},
{"id": "2", "language": "en", "text": ""},
Expand Down Expand Up @@ -1387,11 +1389,12 @@ def test_action_errors_with_targets(
@TextAnalyticsCustomPreparer()
def test_action_job_failure(
self,
textanalytics_custom_text_endpoint,
textanalytics_custom_text_key,
textanalytics_custom_entities_project_name,
textanalytics_custom_entities_deployment_name
**kwargs
):
textanalytics_custom_text_endpoint = kwargs.pop("textanalytics_custom_text_endpoint")
textanalytics_custom_text_key = kwargs.pop("textanalytics_custom_text_key")
textanalytics_custom_entities_project_name = kwargs.pop("textanalytics_custom_entities_project_name")
textanalytics_custom_entities_deployment_name = kwargs.pop("textanalytics_custom_entities_deployment_name")
docs = [
{"id": "1", "language": "en",
"text": "A recent report by the Government Accountability Office (GAO) found that the dramatic increase in oil and natural gas development on federal lands over the past six years has stretched the staff of the BLM to a point that it has been unable to meet its environmental protection responsibilities."},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1324,15 +1324,16 @@ async def test_analyze_continuation_token(self, client):
@recorded_by_proxy_async
async def test_generic_action_error_no_target(
self,
textanalytics_custom_text_endpoint,
textanalytics_custom_text_key,
textanalytics_single_category_classify_project_name,
textanalytics_single_category_classify_deployment_name,
textanalytics_multi_category_classify_project_name,
textanalytics_multi_category_classify_deployment_name,
textanalytics_custom_entities_project_name,
textanalytics_custom_entities_deployment_name
**kwargs
):
textanalytics_custom_text_endpoint = kwargs.pop("textanalytics_custom_text_endpoint")
textanalytics_custom_text_key = kwargs.pop("textanalytics_custom_text_key")
textanalytics_single_category_classify_project_name = kwargs.pop("textanalytics_single_category_classify_project_name")
textanalytics_single_category_classify_deployment_name = kwargs.pop("textanalytics_single_category_classify_deployment_name")
textanalytics_multi_category_classify_project_name = kwargs.pop("textanalytics_multi_category_classify_project_name")
textanalytics_multi_category_classify_deployment_name = kwargs.pop("textanalytics_multi_category_classify_deployment_name")
textanalytics_custom_entities_project_name = kwargs.pop("textanalytics_custom_entities_project_name")
textanalytics_custom_entities_deployment_name = kwargs.pop("textanalytics_custom_entities_deployment_name")
docs = [
{"id": "1", "language": "en", "text": "A recent report by the Government Accountability Office (GAO) found that the dramatic increase in oil and natural gas development on federal lands over the past six years has stretched the staff of the BLM to a point that it has been unable to meet its environmental protection responsibilities."},
{"id": "2", "language": "en", "text": ""},
Expand Down Expand Up @@ -1389,15 +1390,16 @@ async def test_generic_action_error_no_target(
@recorded_by_proxy_async
async def test_action_errors_with_targets(
self,
textanalytics_custom_text_endpoint,
textanalytics_custom_text_key,
textanalytics_single_category_classify_project_name,
textanalytics_single_category_classify_deployment_name,
textanalytics_multi_category_classify_project_name,
textanalytics_multi_category_classify_deployment_name,
textanalytics_custom_entities_project_name,
textanalytics_custom_entities_deployment_name
**kwargs
):
textanalytics_custom_text_endpoint = kwargs.pop("textanalytics_custom_text_endpoint")
textanalytics_custom_text_key = kwargs.pop("textanalytics_custom_text_key")
textanalytics_single_category_classify_project_name = kwargs.pop("textanalytics_single_category_classify_project_name")
textanalytics_single_category_classify_deployment_name = kwargs.pop("textanalytics_single_category_classify_deployment_name")
textanalytics_multi_category_classify_project_name = kwargs.pop("textanalytics_multi_category_classify_project_name")
textanalytics_multi_category_classify_deployment_name = kwargs.pop("textanalytics_multi_category_classify_deployment_name")
textanalytics_custom_entities_project_name = kwargs.pop("textanalytics_custom_entities_project_name")
textanalytics_custom_entities_deployment_name = kwargs.pop("textanalytics_custom_entities_deployment_name")
docs = [
{"id": "1", "language": "en", "text": "A recent report by the Government Accountability Office (GAO) found that the dramatic increase in oil and natural gas development on federal lands over the past six years has stretched the staff of the BLM to a point that it has been unable to meet its environmental protection responsibilities."},
{"id": "2", "language": "en", "text": ""},
Expand Down Expand Up @@ -1486,11 +1488,12 @@ async def test_action_errors_with_targets(
@recorded_by_proxy_async
async def test_action_job_failure(
self,
textanalytics_custom_text_endpoint,
textanalytics_custom_text_key,
textanalytics_custom_entities_project_name,
textanalytics_custom_entities_deployment_name
**kwargs
):
textanalytics_custom_text_endpoint = kwargs.pop("textanalytics_custom_text_endpoint")
textanalytics_custom_text_key = kwargs.pop("textanalytics_custom_text_key")
textanalytics_custom_entities_project_name = kwargs.pop("textanalytics_custom_entities_project_name")
textanalytics_custom_entities_deployment_name = kwargs.pop("textanalytics_custom_entities_deployment_name")
docs = [
{"id": "1", "language": "en",
"text": "A recent report by the Government Accountability Office (GAO) found that the dramatic increase in oil and natural gas development on federal lands over the past six years has stretched the staff of the BLM to a point that it has been unable to meet its environmental protection responsibilities."},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@ def test_opinion_mining_no_mined_opinions(self, client):

@TextAnalyticsPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"api_version": TextAnalyticsApiVersion.V3_0})
@recorded_by_proxy
def test_opinion_mining_v3(self, client):
def test_opinion_mining_v3(self, **kwargs):
client = kwargs.pop("client")
with pytest.raises(ValueError) as excinfo:
client.analyze_sentiment(["will fail"], show_opinion_mining=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ async def test_opinion_mining_no_mined_opinions(self, client):

@TextAnalyticsPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"api_version": TextAnalyticsApiVersion.V3_0})
async def test_opinion_mining_v3(self, client):
async def test_opinion_mining_v3(self, **kwargs):
client = kwargs.pop("client")
with pytest.raises(ValueError) as excinfo:
await client.analyze_sentiment(["will fail"], show_opinion_mining=True)

Expand Down
15 changes: 10 additions & 5 deletions sdk/textanalytics/azure-ai-textanalytics/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class TestAuth(TextAnalyticsTest):

@pytest.mark.live_test_only
@TextAnalyticsPreparer()
def test_active_directory_auth(self, textanalytics_test_endpoint):
def test_active_directory_auth(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
token = self.get_credential(TextAnalyticsClient)
text_analytics_endpoint_suffix = os.environ.get("TEXTANALYTICS_ENDPOINT_SUFFIX",".cognitiveservices.azure.com")
credential_scopes = ["https://{}/.default".format(text_analytics_endpoint_suffix[1:])]
Expand All @@ -28,21 +29,25 @@ def test_active_directory_auth(self, textanalytics_test_endpoint):
response = text_analytics.detect_language(docs)

@TextAnalyticsPreparer()
def test_empty_credentials(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_empty_credentials(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
with pytest.raises(TypeError):
text_analytics = TextAnalyticsClient(textanalytics_test_endpoint, "")

@TextAnalyticsPreparer()
def test_bad_type_for_credentials(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_bad_type_for_credentials(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
with pytest.raises(TypeError):
text_analytics = TextAnalyticsClient(textanalytics_test_endpoint, [])

@TextAnalyticsPreparer()
def test_none_credentials(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_none_credentials(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
with pytest.raises(ValueError):
text_analytics = TextAnalyticsClient(textanalytics_test_endpoint, None)

@TextAnalyticsPreparer()
def test_none_endpoint(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_none_endpoint(self, **kwargs):
textanalytics_test_api_key = kwargs.pop("textanalytics_test_api_key")
with pytest.raises(ValueError):
text_analytics = TextAnalyticsClient(None, AzureKeyCredential(textanalytics_test_api_key))
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class TestAuth(TextAnalyticsTest):

@pytest.mark.live_test_only
@TextAnalyticsPreparer()
async def test_active_directory_auth(self, textanalytics_test_endpoint):
async def test_active_directory_auth(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
token = self.get_credential(TextAnalyticsClient, is_async=True)
text_analytics_endpoint_suffix = os.environ.get("TEXTANALYTICS_ENDPOINT_SUFFIX",".cognitiveservices.azure.com")
credential_scopes = ["https://{}/.default".format(text_analytics_endpoint_suffix[1:])]
Expand All @@ -29,21 +30,25 @@ async def test_active_directory_auth(self, textanalytics_test_endpoint):
response = await text_analytics.detect_language(docs)

@TextAnalyticsPreparer()
async def test_empty_credentials(self, textanalytics_test_endpoint, textanalytics_test_api_key):
async def test_empty_credentials(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
with pytest.raises(TypeError):
text_analytics = TextAnalyticsClient(textanalytics_test_endpoint, "")

@TextAnalyticsPreparer()
def test_bad_type_for_credentials(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_bad_type_for_credentials(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
with pytest.raises(TypeError):
text_analytics = TextAnalyticsClient(textanalytics_test_endpoint, [])

@TextAnalyticsPreparer()
def test_none_credentials(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_none_credentials(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
with pytest.raises(ValueError):
text_analytics = TextAnalyticsClient(textanalytics_test_endpoint, None)

@TextAnalyticsPreparer()
def test_none_endpoint(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_none_endpoint(self, **kwargs):
textanalytics_test_api_key = kwargs.pop("textanalytics_test_api_key")
with pytest.raises(ValueError):
text_analytics = TextAnalyticsClient(None, AzureKeyCredential(textanalytics_test_api_key))
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
class TestContextManager(TextAnalyticsTest):

@TextAnalyticsPreparer()
def test_close(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_close(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
textanalytics_test_api_key = kwargs.pop("textanalytics_test_api_key")
transport = mock.MagicMock()
client = TextAnalyticsClient(
textanalytics_test_endpoint,
Expand All @@ -27,7 +29,9 @@ def test_close(self, textanalytics_test_endpoint, textanalytics_test_api_key):
assert transport.__exit__.call_count == 1

@TextAnalyticsPreparer()
def test_context_manager(self, textanalytics_test_endpoint, textanalytics_test_api_key):
def test_context_manager(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
textanalytics_test_api_key = kwargs.pop("textanalytics_test_api_key")
transport = mock.MagicMock()
client = TextAnalyticsClient(
textanalytics_test_endpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def __init__(self, *args, **kwargs):

class TestContextManager(TextAnalyticsTest):
@TextAnalyticsPreparer()
async def test_close(self, textanalytics_test_endpoint, textanalytics_test_api_key):
async def test_close(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
textanalytics_test_api_key = kwargs.pop("textanalytics_test_api_key")
transport = AsyncMockTransport()
client = TextAnalyticsClient(
textanalytics_test_endpoint,
Expand All @@ -47,7 +49,9 @@ async def test_close(self, textanalytics_test_endpoint, textanalytics_test_api_k
assert transport.__aexit__.call_count == 1

@TextAnalyticsPreparer()
async def test_context_manager(self, textanalytics_test_endpoint, textanalytics_test_api_key):
async def test_context_manager(self, **kwargs):
textanalytics_test_endpoint = kwargs.pop("textanalytics_test_endpoint")
textanalytics_test_api_key = kwargs.pop("textanalytics_test_api_key")
transport = AsyncMockTransport()
client = TextAnalyticsClient(
textanalytics_test_endpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@
class TestMultiApi(TextAnalyticsTest):
@TextAnalyticsPreparer()
@TextAnalyticsClientPreparer()
def test_default_api_version(self, client):
def test_default_api_version(self, **kwargs):
client = kwargs.pop("client")
assert "v3.2-preview.2" in client._client._client._base_url

@TextAnalyticsPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"api_version": TextAnalyticsApiVersion.V3_0})
def test_v3_0_api_version(self, client):
def test_v3_0_api_version(self, **kwargs):
client = kwargs.pop("client")
assert "v3.0" in client._client._client._base_url

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

@TextAnalyticsPreparer()
@TextAnalyticsClientPreparer(client_kwargs={"api_version": TextAnalyticsApiVersion.V3_2_PREVIEW})
def test_v3_2_api_version(self, client):
def test_v3_2_api_version(self, **kwargs):
client = kwargs.pop("client")
assert "v3.2-preview.2" in client._client._client._base_url
Loading