Skip to content

Commit 49d5c9b

Browse files
authored
[text analytics] have tests pass (as much as they can) in ci (#11055)
1 parent 91d7673 commit 49d5c9b

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ class DetectedLanguage(DictMixin):
6969
:param iso6391_name: A two letter representation of the detected
7070
language according to the ISO 639-1 standard (e.g. en, fr).
7171
:type iso6391_name: str
72-
:param score: A confidence score between 0 and 1. Scores close
72+
:param confidence_score: A confidence score between 0 and 1. Scores close
7373
to 1 indicate 100% certainty that the identified language is true.
74-
:type score: float
74+
:type confidence_score: float
7575
"""
7676

7777
def __init__(self, **kwargs):
7878
self.name = kwargs.get("name", None)
7979
self.iso6391_name = kwargs.get("iso6391_name", None)
80-
self.score = kwargs.get("score", None)
80+
self.confidence_score = kwargs.get("confidence_score", None)
8181

8282
@classmethod
8383
def _from_generated(cls, language):
8484
return cls(
85-
name=language.name, iso6391_name=language.iso6391_name, score=language.score
85+
name=language.name, iso6391_name=language.iso6391_name, confidence_score=language.confidence_score
8686
)
8787

8888
def __repr__(self):
8989
return "DetectedLanguage(name={}, iso6391_name={}, score={})" \
90-
.format(self.name, self.iso6391_name, self.score)[:1024]
90+
.format(self.name, self.iso6391_name, self.confidence_score)[:1024]
9191

9292

9393
class RecognizeEntitiesResult(DictMixin):

sdk/textanalytics/azure-ai-textanalytics/tests/test_text_analytics.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,13 @@ def test_repr(self):
142142
self.assertEqual("SentimentConfidenceScores(positive=0.99, neutral=0.05, negative=0.02)",
143143
repr(sentiment_confidence_score_per_label))
144144
self.assertEqual("SentenceSentiment(sentiment=neutral, confidence_scores=SentimentConfidenceScores("
145-
"positive=0.99, neutral=0.05, negative=0.02), grapheme_offset=0, grapheme_length=10, warnings="
146-
"['sentence was too short to find sentiment'])", repr(sentence_sentiment))
145+
"positive=0.99, neutral=0.05, negative=0.02), grapheme_offset=0, grapheme_length=10)", repr(sentence_sentiment))
147146
self.assertEqual("AnalyzeSentimentResult(id=1, sentiment=positive, statistics=TextDocumentStatistics("
148147
"grapheme_count=14, transaction_count=18), confidence_scores=SentimentConfidenceScores"
149148
"(positive=0.99, neutral=0.05, negative=0.02), "
150149
"sentences=[SentenceSentiment(sentiment=neutral, confidence_scores="
151150
"SentimentConfidenceScores(positive=0.99, neutral=0.05, negative=0.02), "
152-
"grapheme_offset=0, grapheme_length=10, "
153-
"warnings=['sentence was too short to find sentiment'])], is_error=False)",
151+
"grapheme_offset=0, grapheme_length=10)], is_error=False)",
154152
repr(analyze_sentiment_result))
155153
self.assertEqual("DocumentError(id=1, error=TextAnalyticsError(code=invalidRequest, "
156154
"message=The request is invalid, target=request), is_error=True)", repr(document_error))

sdk/textanalytics/azure-ai-textanalytics/tests/testcase.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,20 @@ def __init__(self):
8787
)
8888

8989
def create_resource(self, name, **kwargs):
90-
text_analytics_account = TextAnalyticsTest._TEXT_ANALYTICS_ACCOUNT
91-
92-
return {
93-
'location': 'westus2',
94-
'resource_group': TextAnalyticsTest._RESOURCE_GROUP,
95-
'text_analytics_account': text_analytics_account,
96-
'text_analytics_account_key': TextAnalyticsTest._TEXT_ANALYTICS_KEY,
97-
}
90+
if self.is_live:
91+
return {
92+
'location': 'westus2',
93+
'resource_group': TextAnalyticsTest._RESOURCE_GROUP,
94+
'text_analytics_account': os.environ['AZURE_TEXT_ANALYTICS_ENDPOINT'],
95+
'text_analytics_account_key': os.environ['AZURE_TEXT_ANALYTICS_KEY'],
96+
}
97+
else:
98+
return {
99+
'location': 'westus2',
100+
'resource_group': TextAnalyticsTest._RESOURCE_GROUP,
101+
'text_analytics_account': "https://westus2.ppe.cognitiveservices.azure.com",
102+
'text_analytics_account_key': "fake_key",
103+
}
98104

99105
class TextAnalyticsClientPreparer(AzureMgmtPreparer):
100106
def __init__(self, client_cls, client_kwargs={}, **kwargs):
@@ -129,15 +135,15 @@ def create_text_analytics_client(self, **kwargs):
129135
def text_analytics_account():
130136
test_case = AzureTestCase("__init__")
131137
rg_preparer = ResourceGroupPreparer(random_name_enabled=True, name_prefix='pycog')
132-
text_analytics_preparer = CognitiveServicesAccountPreparer(random_name_enabled=True, name_prefix='pycog', sku='S0')
138+
text_analytics_preparer = CognitiveServicesAccountPreparer(random_name_enabled=True, name_prefix='pycog')
133139

134140
try:
135141
rg_name, rg_kwargs = rg_preparer._prepare_create_resource(test_case)
136142
TextAnalyticsTest._RESOURCE_GROUP = rg_kwargs['resource_group']
137143
try:
138144
text_analytics_name, text_analytics_kwargs = text_analytics_preparer._prepare_create_resource(test_case, **rg_kwargs)
139-
TextAnalyticsTest._TEXT_ANALYTICS_ACCOUNT = os.environ['AZURE_TEXT_ANALYTICS_ENDPOINT'] #text_analytics_kwargs['cognitiveservices_account']
140-
TextAnalyticsTest._TEXT_ANALYTICS_KEY = os.environ['AZURE_TEXT_ANALYTICS_KEY'] # text_analytics_kwargs['cognitiveservices_account_key']
145+
TextAnalyticsTest._TEXT_ANALYTICS_ACCOUNT = text_analytics_kwargs['cognitiveservices_account']
146+
TextAnalyticsTest._TEXT_ANALYTICS_KEY = text_analytics_kwargs['cognitiveservices_account_key']
141147
yield
142148
finally:
143149
text_analytics_preparer.remove_resource(

0 commit comments

Comments
 (0)