Skip to content

Commit 0160912

Browse files
authored
[text analytics] Update ta tests (#11461)
1 parent 4e48ee5 commit 0160912

File tree

52 files changed

+1676
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1676
-375
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ def _validate_batch_input(documents, hint, whole_batch_hint):
2323
:return: A list of DetectLanguageInput or TextDocumentInput
2424
"""
2525
if not documents:
26-
raise ValueError("Input documents can not be empty")
26+
raise ValueError("Input documents can not be empty or None")
2727

2828
if isinstance(documents, six.string_types):
2929
raise TypeError("Input documents cannot be a string.")
3030

31+
if isinstance(documents, dict):
32+
raise TypeError("Input documents cannot be a dict")
33+
3134
if not all(isinstance(x, six.string_types) for x in documents):
3235
if not all(isinstance(x, (dict, TextDocumentInput, DetectLanguageInput)) for x in documents):
3336
raise TypeError("Mixing string and dictionary/object document input unsupported.")
3437

38+
3539
request_batch = []
3640
for idx, doc in enumerate(documents):
3741
if isinstance(doc, six.string_types):
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interactions:
22
- request:
3-
body: '{"documents": [{"id": "0", "text": "Microsoft was founded by Bill Gates.",
4-
"countryHint": "US"}]}'
3+
body: '{"documents": [{"id": "1", "text": "This should fail because we''re passing
4+
in an invalid language hint", "language": "notalanguage"}]}'
55
headers:
66
Accept:
77
- application/json
@@ -10,34 +10,35 @@ interactions:
1010
Connection:
1111
- keep-alive
1212
Content-Length:
13-
- '97'
13+
- '134'
1414
Content-Type:
1515
- application/json
1616
User-Agent:
17-
- azsdk-python-ai-textanalytics/1.0.0b4 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
17+
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
1818
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
1919
method: POST
20-
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages?model-version=old&showStats=false
20+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
2121
response:
2222
body:
23-
string: '{"error":{"code":"InvalidRequest","message":"Specified Model version
24-
is incorrect. Allowed values are latest,2019-10-01"}}'
23+
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","message":"Invalid
24+
Language Code.","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
25+
language not supported. Pass in one of: de,en,es,fr,it,ja,ko,nl,pt-PT,zh-Hans,zh-Hant"}}}],"modelVersion":"2020-04-01"}'
2526
headers:
2627
apim-request-id:
27-
- 4348cf49-e795-4443-8812-6161afd73126
28+
- d3021074-c432-445c-8743-432049584ef8
2829
content-type:
2930
- application/json; charset=utf-8
3031
date:
31-
- Thu, 02 Apr 2020 15:06:23 GMT
32+
- Fri, 15 May 2020 15:23:32 GMT
3233
strict-transport-security:
3334
- max-age=31536000; includeSubDomains; preload
3435
transfer-encoding:
3536
- chunked
3637
x-content-type-options:
3738
- nosniff
3839
x-envoy-upstream-service-time:
39-
- '5'
40+
- '3'
4041
status:
41-
code: 400
42-
message: Bad Request
42+
code: 200
43+
message: OK
4344
version: 1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interactions:
22
- request:
3-
body: '{"documents": [{"id": "0", "text": "Microsoft was founded by Bill Gates.",
4-
"language": "en"}]}'
3+
body: '{"documents": [{"id": "0", "text": "This should fail because we''re passing
4+
in an invalid language hint", "language": "notalanguage"}]}'
55
headers:
66
Accept:
77
- application/json
@@ -10,34 +10,35 @@ interactions:
1010
Connection:
1111
- keep-alive
1212
Content-Length:
13-
- '94'
13+
- '134'
1414
Content-Type:
1515
- application/json
1616
User-Agent:
17-
- azsdk-python-ai-textanalytics/1.0.0b4 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
17+
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
1818
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
1919
method: POST
20-
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/entities/recognition/general?model-version=old&showStats=false
20+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
2121
response:
2222
body:
23-
string: '{"error":{"code":"InvalidRequest","message":"Specified Model version
24-
is incorrect. Allowed values are latest,2019-10-01,2020-02-01"}}'
23+
string: '{"documents":[],"errors":[{"id":"0","error":{"code":"InvalidArgument","message":"Invalid
24+
Language Code.","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
25+
language not supported. Pass in one of: de,en,es,fr,it,ja,ko,nl,pt-PT,zh-Hans,zh-Hant"}}}],"modelVersion":"2020-04-01"}'
2526
headers:
2627
apim-request-id:
27-
- a932797b-901c-4c62-a042-5bdc64b2964d
28+
- 01dd7077-1342-444b-8feb-98bfd25fba54
2829
content-type:
2930
- application/json; charset=utf-8
3031
date:
31-
- Thu, 02 Apr 2020 15:07:19 GMT
32+
- Fri, 15 May 2020 15:09:16 GMT
3233
strict-transport-security:
3334
- max-age=31536000; includeSubDomains; preload
3435
transfer-encoding:
3536
- chunked
3637
x-content-type-options:
3738
- nosniff
3839
x-envoy-upstream-service-time:
39-
- '4'
40+
- '3'
4041
status:
41-
code: 400
42-
message: Bad Request
42+
code: 200
43+
message: OK
4344
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
interactions:
2+
- request:
3+
body: '{"documents": [{"id": "1", "text": "one", "language": "en"}, {"id": "2",
4+
"text": "two", "language": "en"}, {"id": "3", "text": "three", "language": "en"},
5+
{"id": "4", "text": "four", "language": "en"}, {"id": "5", "text": "five", "language":
6+
"en"}]}'
7+
headers:
8+
Accept:
9+
- application/json
10+
Accept-Encoding:
11+
- gzip, deflate
12+
Connection:
13+
- keep-alive
14+
Content-Length:
15+
- '249'
16+
Content-Type:
17+
- application/json
18+
User-Agent:
19+
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
20+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
21+
method: POST
22+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
23+
response:
24+
body:
25+
string: '{"documents":[{"id":"1","sentiment":"neutral","documentScores":{"positive":0.06,"neutral":0.9,"negative":0.04},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.06,"neutral":0.9,"negative":0.04},"offset":0,"length":3}]},{"id":"2","sentiment":"neutral","documentScores":{"positive":0.01,"neutral":0.97,"negative":0.02},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.01,"neutral":0.97,"negative":0.02},"offset":0,"length":3}]},{"id":"3","sentiment":"neutral","documentScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"offset":0,"length":5}]},{"id":"4","sentiment":"neutral","documentScores":{"positive":0.03,"neutral":0.96,"negative":0.01},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.03,"neutral":0.96,"negative":0.01},"offset":0,"length":4}]},{"id":"5","sentiment":"neutral","documentScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"offset":0,"length":4}]}],"errors":[],"modelVersion":"2020-04-01"}'
26+
headers:
27+
apim-request-id:
28+
- a30e449b-00ff-46f9-88c0-0f74772bbc00
29+
content-type:
30+
- application/json; charset=utf-8
31+
csp-billing-usage:
32+
- CognitiveServices.TextAnalytics.BatchScoring=5
33+
date:
34+
- Fri, 15 May 2020 16:02:11 GMT
35+
strict-transport-security:
36+
- max-age=31536000; includeSubDomains; preload
37+
transfer-encoding:
38+
- chunked
39+
x-content-type-options:
40+
- nosniff
41+
x-envoy-upstream-service-time:
42+
- '112'
43+
status:
44+
code: 200
45+
message: OK
46+
version: 1

sdk/textanalytics/azure-ai-textanalytics/tests/recordings/test_analyze_sentiment_async.test_bad_model_version.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
interactions:
2+
- request:
3+
body: '{"documents": [{"id": "1", "text": "This should fail because we''re passing
4+
in an invalid language hint", "language": "notalanguage"}]}'
5+
headers:
6+
Accept:
7+
- application/json
8+
Content-Length:
9+
- '134'
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
14+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
15+
method: POST
16+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
17+
response:
18+
body:
19+
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","message":"Invalid
20+
Language Code.","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
21+
language not supported. Pass in one of: de,en,es,fr,it,ja,ko,nl,pt-PT,zh-Hans,zh-Hant"}}}],"modelVersion":"2020-04-01"}'
22+
headers:
23+
apim-request-id: 0e47233a-f34a-4396-8767-d050e9ebe993
24+
content-type: application/json; charset=utf-8
25+
date: Fri, 15 May 2020 15:23:32 GMT
26+
strict-transport-security: max-age=31536000; includeSubDomains; preload
27+
transfer-encoding: chunked
28+
x-content-type-options: nosniff
29+
x-envoy-upstream-service-time: '2'
30+
status:
31+
code: 200
32+
message: OK
33+
url: https://westus2.api.cognitive.microsoft.com//text/analytics/v3.0-preview.1/sentiment?showStats=false
34+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
interactions:
2+
- request:
3+
body: '{"documents": [{"id": "0", "text": "This should fail because we''re passing
4+
in an invalid language hint", "language": "notalanguage"}]}'
5+
headers:
6+
Accept:
7+
- application/json
8+
Content-Length:
9+
- '134'
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
14+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
15+
method: POST
16+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
17+
response:
18+
body:
19+
string: '{"documents":[],"errors":[{"id":"0","error":{"code":"InvalidArgument","message":"Invalid
20+
Language Code.","innerError":{"code":"UnsupportedLanguageCode","message":"Supplied
21+
language not supported. Pass in one of: de,en,es,fr,it,ja,ko,nl,pt-PT,zh-Hans,zh-Hant"}}}],"modelVersion":"2020-04-01"}'
22+
headers:
23+
apim-request-id: b09d0a6e-a462-47f4-905e-355f3a8ce6b7
24+
content-type: application/json; charset=utf-8
25+
date: Fri, 15 May 2020 16:25:24 GMT
26+
strict-transport-security: max-age=31536000; includeSubDomains; preload
27+
transfer-encoding: chunked
28+
x-content-type-options: nosniff
29+
x-envoy-upstream-service-time: '3'
30+
status:
31+
code: 200
32+
message: OK
33+
url: https://westus2.api.cognitive.microsoft.com//text/analytics/v3.0-preview.1/sentiment?showStats=false
34+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
interactions:
2+
- request:
3+
body: '{"documents": [{"id": "1", "text": "one", "language": "en"}, {"id": "2",
4+
"text": "two", "language": "en"}, {"id": "3", "text": "three", "language": "en"},
5+
{"id": "4", "text": "four", "language": "en"}, {"id": "5", "text": "five", "language":
6+
"en"}]}'
7+
headers:
8+
Accept:
9+
- application/json
10+
Content-Length:
11+
- '249'
12+
Content-Type:
13+
- application/json
14+
User-Agent:
15+
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
16+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
17+
method: POST
18+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/sentiment?showStats=false
19+
response:
20+
body:
21+
string: '{"documents":[{"id":"1","sentiment":"neutral","documentScores":{"positive":0.06,"neutral":0.9,"negative":0.04},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.06,"neutral":0.9,"negative":0.04},"offset":0,"length":3}]},{"id":"2","sentiment":"neutral","documentScores":{"positive":0.01,"neutral":0.97,"negative":0.02},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.01,"neutral":0.97,"negative":0.02},"offset":0,"length":3}]},{"id":"3","sentiment":"neutral","documentScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"offset":0,"length":5}]},{"id":"4","sentiment":"neutral","documentScores":{"positive":0.03,"neutral":0.96,"negative":0.01},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.03,"neutral":0.96,"negative":0.01},"offset":0,"length":4}]},{"id":"5","sentiment":"neutral","documentScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"sentences":[{"sentiment":"neutral","sentenceScores":{"positive":0.05,"neutral":0.93,"negative":0.02},"offset":0,"length":4}]}],"errors":[],"modelVersion":"2020-04-01"}'
22+
headers:
23+
apim-request-id: 272cc09d-757b-44a0-8f21-97add1137ed1
24+
content-type: application/json; charset=utf-8
25+
csp-billing-usage: CognitiveServices.TextAnalytics.BatchScoring=5
26+
date: Fri, 15 May 2020 16:02:12 GMT
27+
strict-transport-security: max-age=31536000; includeSubDomains; preload
28+
transfer-encoding: chunked
29+
x-content-type-options: nosniff
30+
x-envoy-upstream-service-time: '87'
31+
status:
32+
code: 200
33+
message: OK
34+
url: https://westus2.api.cognitive.microsoft.com//text/analytics/v3.0-preview.1/sentiment?showStats=false
35+
version: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
interactions:
2+
- request:
3+
body: '{"documents": [{"id": "1", "text": "hello world", "countryHint": "United
4+
States"}]}'
5+
headers:
6+
Accept:
7+
- application/json
8+
Accept-Encoding:
9+
- gzip, deflate
10+
Connection:
11+
- keep-alive
12+
Content-Length:
13+
- '83'
14+
Content-Type:
15+
- application/json
16+
User-Agent:
17+
- azsdk-python-ai-textanalytics/1.0.0b5 Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
18+
Python/3.7.7 (Darwin-17.7.0-x86_64-i386-64bit)
19+
method: POST
20+
uri: https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages?showStats=false
21+
response:
22+
body:
23+
string: '{"documents":[],"errors":[{"id":"1","error":{"code":"InvalidArgument","message":"Invalid
24+
Country Hint.","innerError":{"code":"InvalidCountryHint","message":"Country
25+
hint is not valid. Please specify an ISO 3166-1 alpha-2 two letter country
26+
code."}}}],"modelVersion":"2019-10-01"}'
27+
headers:
28+
apim-request-id:
29+
- 62417eb9-9e24-4209-ba80-5b019a9e7bc8
30+
content-type:
31+
- application/json; charset=utf-8
32+
csp-billing-usage:
33+
- CognitiveServices.TextAnalytics.BatchScoring=0
34+
date:
35+
- Fri, 15 May 2020 14:52:41 GMT
36+
strict-transport-security:
37+
- max-age=31536000; includeSubDomains; preload
38+
transfer-encoding:
39+
- chunked
40+
x-content-type-options:
41+
- nosniff
42+
x-envoy-upstream-service-time:
43+
- '3'
44+
status:
45+
code: 200
46+
message: OK
47+
version: 1

0 commit comments

Comments
 (0)