feat(language): update code example for Cloud NL v2 - python#10544
Conversation
|
Here is the summary of changes. You are about to add 6 region tags.
This comment is generated by snippet-bot.
|
dandhlee
left a comment
There was a problem hiding this comment.
Will you be adding tests?
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
|
I copied the test folder from https://github.com/GoogleCloudPlatform/python-docs-samples/tree/HEAD/language/v1/test. Does this work? Plan to have the other API samples once this |
|
Gotcha. I'm not entirely sure how the test layout is done since this sample was from a client library repository. I'll leave it to the product team to help verify, but looks like the tests are included in the new run under v2! |
|
@dandhlee Thank you for the review! I've addressed all your comments. Please let me know if you have any more concerns. |
dandhlee
left a comment
There was a problem hiding this comment.
Reviewing for Python style.
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
|
Be sure to review the Python style guidance and Style Guide. |
dandhlee
left a comment
There was a problem hiding this comment.
Reviewing for Python style.
|
Added tests and minor changes in style. |
| # [END language_classify_gcs] | ||
|
|
||
|
|
||
| def main(): |
There was a problem hiding this comment.
issue: remove CLI.
https://googlecloudplatform.github.io/samples-style-guide/#no-cli
There was a problem hiding this comment.
Not sure why you still see this but I've removed all the main() functions already. Probably a github glitch or browser not refreshed.
| # [END language_classify_text] | ||
|
|
||
|
|
||
| def main(): |
There was a problem hiding this comment.
It's already removed.
| language_classify_gcs.sample_classify_text() | ||
| captured = capsys.readouterr() | ||
| assert ( | ||
| "TV" in captured.out |
There was a problem hiding this comment.
issue: don't test for model results in these integration tests. Model changes can affect API output, which leads to these tests being broken.
Instead, test for the string literals printed to stdout (e.g. "Confidence" and "Category"). These literals won't be printed if the call to the API fails, which provides sufficient signal for sample quality.
| language_classify_text.sample_classify_text() | ||
| captured = capsys.readouterr() | ||
| assert ( | ||
| "TV" in captured.out |
There was a problem hiding this comment.
See previous about API output.
| captured = capsys.readouterr() | ||
| assert ( | ||
| "Representative name for the entity: California" in captured.out | ||
| and "Entity type: LOCATION" in captured.out |
There was a problem hiding this comment.
See previous about testing for API output.
| # the language specified in the request or, if not specified, | ||
| # the automatically-detected language. | ||
| print(f"Language of the text: {response.language_code}") | ||
|
|
| language_entities_text.sample_analyze_entities() | ||
| captured = capsys.readouterr() | ||
| assert ( | ||
| "Representative name for the entity: California" in captured.out |
There was a problem hiding this comment.
See previous about testing for output.
| # the language specified in the request or, if not specified, | ||
| # the automatically-detected language. | ||
| print(f"Language of the text: {response.language_code}") | ||
|
|
There was a problem hiding this comment.
Remove extraneous empty line.
| language_sentiment_gcs.sample_analyze_sentiment() | ||
| captured = capsys.readouterr() | ||
| assert ( | ||
| "Document sentiment score: 0." in captured.out |
There was a problem hiding this comment.
See previous about testing for output.
| language_sentiment_text.sample_analyze_sentiment() | ||
| captured = capsys.readouterr() | ||
| assert ( | ||
| "Document sentiment score: 0." in captured.out |
There was a problem hiding this comment.
See previous about testing for API output.
telpirion
left a comment
There was a problem hiding this comment.
Looks great! Let's merge it when we can.
Description
Fixes b/296927741
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
nox -s py-3.9(see Test Environment Setup)nox -s lint(see Test Environment Setup)