Skip to content

[text analytics] have tests pass (as much as they can) in ci #11055

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

Merged
merged 5 commits into from
Apr 27, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ class DetectedLanguage(DictMixin):
:param iso6391_name: A two letter representation of the detected
language according to the ISO 639-1 standard (e.g. en, fr).
:type iso6391_name: str
:param score: A confidence score between 0 and 1. Scores close
:param confidence_score: A confidence score between 0 and 1. Scores close
to 1 indicate 100% certainty that the identified language is true.
:type score: float
:type confidence_score: float
"""

def __init__(self, **kwargs):
self.name = kwargs.get("name", None)
self.iso6391_name = kwargs.get("iso6391_name", None)
self.score = kwargs.get("score", None)
self.confidence_score = kwargs.get("confidence_score", None)

@classmethod
def _from_generated(cls, language):
return cls(
name=language.name, iso6391_name=language.iso6391_name, score=language.score
name=language.name, iso6391_name=language.iso6391_name, confidence_score=language.confidence_score
)

def __repr__(self):
return "DetectedLanguage(name={}, iso6391_name={}, score={})" \
.format(self.name, self.iso6391_name, self.score)[:1024]
.format(self.name, self.iso6391_name, self.confidence_score)[:1024]


class RecognizeEntitiesResult(DictMixin):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,13 @@ def test_repr(self):
self.assertEqual("SentimentConfidenceScores(positive=0.99, neutral=0.05, negative=0.02)",
repr(sentiment_confidence_score_per_label))
self.assertEqual("SentenceSentiment(sentiment=neutral, confidence_scores=SentimentConfidenceScores("
"positive=0.99, neutral=0.05, negative=0.02), grapheme_offset=0, grapheme_length=10, warnings="
"['sentence was too short to find sentiment'])", repr(sentence_sentiment))
"positive=0.99, neutral=0.05, negative=0.02), grapheme_offset=0, grapheme_length=10)", repr(sentence_sentiment))
self.assertEqual("AnalyzeSentimentResult(id=1, sentiment=positive, statistics=TextDocumentStatistics("
"grapheme_count=14, transaction_count=18), confidence_scores=SentimentConfidenceScores"
"(positive=0.99, neutral=0.05, negative=0.02), "
"sentences=[SentenceSentiment(sentiment=neutral, confidence_scores="
"SentimentConfidenceScores(positive=0.99, neutral=0.05, negative=0.02), "
"grapheme_offset=0, grapheme_length=10, "
"warnings=['sentence was too short to find sentiment'])], is_error=False)",
"grapheme_offset=0, grapheme_length=10)], is_error=False)",
repr(analyze_sentiment_result))
self.assertEqual("DocumentError(id=1, error=TextAnalyticsError(code=invalidRequest, "
"message=The request is invalid, target=request), is_error=True)", repr(document_error))
Expand Down
28 changes: 17 additions & 11 deletions sdk/textanalytics/azure-ai-textanalytics/tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,20 @@ def __init__(self):
)

def create_resource(self, name, **kwargs):
text_analytics_account = TextAnalyticsTest._TEXT_ANALYTICS_ACCOUNT

return {
'location': 'westus2',
'resource_group': TextAnalyticsTest._RESOURCE_GROUP,
'text_analytics_account': text_analytics_account,
'text_analytics_account_key': TextAnalyticsTest._TEXT_ANALYTICS_KEY,
}
if self.is_live:
return {
'location': 'westus2',
'resource_group': TextAnalyticsTest._RESOURCE_GROUP,
'text_analytics_account': os.environ['AZURE_TEXT_ANALYTICS_ENDPOINT'],
'text_analytics_account_key': os.environ['AZURE_TEXT_ANALYTICS_KEY'],
}
else:
return {
'location': 'westus2',
'resource_group': TextAnalyticsTest._RESOURCE_GROUP,
'text_analytics_account': "https://westus2.ppe.cognitiveservices.azure.com",
'text_analytics_account_key': "fake_key",
}

class TextAnalyticsClientPreparer(AzureMgmtPreparer):
def __init__(self, client_cls, client_kwargs={}, **kwargs):
Expand Down Expand Up @@ -129,15 +135,15 @@ def create_text_analytics_client(self, **kwargs):
def text_analytics_account():
test_case = AzureTestCase("__init__")
rg_preparer = ResourceGroupPreparer(random_name_enabled=True, name_prefix='pycog')
text_analytics_preparer = CognitiveServicesAccountPreparer(random_name_enabled=True, name_prefix='pycog', sku='S0')
text_analytics_preparer = CognitiveServicesAccountPreparer(random_name_enabled=True, name_prefix='pycog')

try:
rg_name, rg_kwargs = rg_preparer._prepare_create_resource(test_case)
TextAnalyticsTest._RESOURCE_GROUP = rg_kwargs['resource_group']
try:
text_analytics_name, text_analytics_kwargs = text_analytics_preparer._prepare_create_resource(test_case, **rg_kwargs)
TextAnalyticsTest._TEXT_ANALYTICS_ACCOUNT = os.environ['AZURE_TEXT_ANALYTICS_ENDPOINT'] #text_analytics_kwargs['cognitiveservices_account']
TextAnalyticsTest._TEXT_ANALYTICS_KEY = os.environ['AZURE_TEXT_ANALYTICS_KEY'] # text_analytics_kwargs['cognitiveservices_account_key']
TextAnalyticsTest._TEXT_ANALYTICS_ACCOUNT = text_analytics_kwargs['cognitiveservices_account']
TextAnalyticsTest._TEXT_ANALYTICS_KEY = text_analytics_kwargs['cognitiveservices_account_key']
yield
finally:
text_analytics_preparer.remove_resource(
Expand Down