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

feat: Add initial Model Builder SDK samples #265

Merged
merged 5 commits into from Mar 25, 2021

Conversation

vinnysenthil
Copy link
Contributor

Adds an initial set of Model Builder SDK samples and their tests, along with a conftest.py file to hold mocks.

Here are the samples added:

  • init_sample
  • create_and_import_dataset_image_sample
  • create_batch_prediction_job_sample
  • create_training_pipeline_image_classification_sample

@vinnysenthil vinnysenthil added samples Issues that are directly related to samples. api: aiplatform Issues related to the AI Platform API. labels Mar 19, 2021
@vinnysenthil vinnysenthil requested review from dizcology and a team as code owners March 19, 2021 17:39
@snippet-bot
Copy link

snippet-bot bot commented Mar 19, 2021

Here is the summary of changes.

You are about to add 4 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 19, 2021
Copy link
Member

@sasha-gitg sasha-gitg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Added some comments.

with patch.object(
aiplatform.training_jobs.AutoMLImageTrainingJob, "__init__"
) as mock:
mock.return_value = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems either superfluous or possibly will cause an error because we would call run on None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not returning None when patching the __init__ caused the following exception:

TypeError: __init__() should return None, not 'MagicMock'

The downstream calls would also be patched so it shouldn't cause an error. Is this alright or should we look for alternative approaches?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I was wrong on that. Leave it as is. That makes sense, __new__ returns the instance, not __init__.

@vinnysenthil vinnysenthil requested review from busunkim96 and removed request for leahecole March 23, 2021 21:09
@vinnysenthil
Copy link
Contributor Author

PTAL when you get a chance @busunkim96 @tmatsuo — thanks!

Copy link
Contributor

@busunkim96 busunkim96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend turning on Autospeccing (https://docs.python.org/3/library/unittest.mock.html#autospeccing) where possible. It makes it easier to catch incorrect method calls.

The conftest.py approach seems good for sharing code needed by the tests. For very simple mocks IMO it is easier for folks to follow when the mock is right next to the test using the patch() decorator syntax. (example in google-auth)

@vinnysenthil vinnysenthil merged commit 1230dc6 into googleapis:dev Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: aiplatform Issues related to the AI Platform API. cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants