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

Make WorkspaceClient and AccountClient more friendly with autospeccing #480

Merged
merged 3 commits into from
Dec 20, 2023

Conversation

nfx
Copy link
Contributor

@nfx nfx commented Dec 13, 2023

Changes

We cannot create_autospec(WorkspaceClient), because all public properties are created within the constructor:

>>> WorkspaceClient
<class 'databricks.sdk.WorkspaceClient'>
>>> ws = create_autospec(WorkspaceClient)
>>> ws
<MagicMock spec='WorkspaceClient' id='4394200816'>
>>> ws.workspace.list()
Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/opt/homebrew/Cellar/[email protected]/3.10.12_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/mock.py", line 643, in __getattr__
    raise AttributeError("Mock object has no attribute %r" % name)
AttributeError: Mock object has no attribute 'workspace'

This PR makes it easier to introspect the class instances and makes mocks more reliable.

All existing behavior stays the same.

See:

Tests

  • make test run locally
  • make fmt applied
  • relevant integration tests applied

We cannot `create_autospec(WorkspaceClient)`, because all public properties are created within the constructor. This PR makes it easier to introspect the class instances and make mocks more reliable.

See:
- https://docs.python.org/3/library/unittest.mock.html#autospeccing
- https://stackoverflow.com/a/35921144/277035
@nfx nfx changed the title Make WorkspaceClient and AccountClient friendly with autospeccing (WIP) Make WorkspaceClient and AccountClient friendly with autospeccing Dec 13, 2023
@codecov-commenter
Copy link

Codecov Report

Attention: 119 lines in your changes are missing coverage. Please review.

Comparison is base (1d04851) 57.72% compared to head (c089093) 57.78%.
Report is 2 commits behind head on main.

Files Patch % Lines
databricks/sdk/__init__.py 68.35% 119 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #480      +/-   ##
==========================================
+ Coverage   57.72%   57.78%   +0.05%     
==========================================
  Files          38       38              
  Lines       26162    26357     +195     
==========================================
+ Hits        15103    15231     +128     
- Misses      11059    11126      +67     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nfx nfx changed the title (WIP) Make WorkspaceClient and AccountClient friendly with autospeccing Make WorkspaceClient and AccountClient friendly with autospeccing Dec 19, 2023
@nfx
Copy link
Contributor Author

nfx commented Dec 19, 2023

random integration test passed:
image

@nfx nfx changed the title Make WorkspaceClient and AccountClient friendly with autospeccing Make WorkspaceClient and AccountClient more friendly with autospeccing Dec 19, 2023
@nfx nfx enabled auto-merge December 19, 2023 16:12
@tanmay-db tanmay-db requested a review from mgyucht December 19, 2023 16:41
@nfx nfx added this pull request to the merge queue Dec 20, 2023
Merged via the queue into main with commit 1fd3b9e Dec 20, 2023
9 checks passed
@nfx nfx deleted the autospec-clients branch December 20, 2023 07:58
kartikgupta-db added a commit that referenced this pull request Dec 20, 2023
* Sort imports in service template ([#479](#479)).
* Add `py.typed` to support PEP-561 ([#483](#483)).
* Fixed bug in `@retried` when exception subtypes were not respected ([#484](#484)).
* Make `WorkspaceClient` and `AccountClient` more friendly with autospeccing ([#480](#480)).

API Changes:

 * Added `azure_workspace_info` field for `databricks.sdk.service.provisioning.Workspace`.
 * Added `databricks.sdk.service.provisioning.AzureWorkspaceInfo` dataclass.
 * Changed `update_config()` method for [w.serving_endpoints](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/serving_endpoints.html) workspace-level service with new required argument order.
 * Changed `served_entities` field for `databricks.sdk.service.serving.EndpointCoreConfigInput` to no longer be required.
 * Changed `create()` method for [a.account_ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/account/account_ip_access_lists.html) account-level service with new required argument order.
 * Changed `replace()` method for [a.account_ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/account/account_ip_access_lists.html) account-level service with new required argument order.
 * Changed `update()` method for [a.account_ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/account/account_ip_access_lists.html) account-level service with new required argument order.
 * Changed `create()` method for [w.ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/ip_access_lists.html) workspace-level service with new required argument order.
 * Changed `replace()` method for [w.ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/ip_access_lists.html) workspace-level service with new required argument order.
 * Changed `update()` method for [w.ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/ip_access_lists.html) workspace-level service with new required argument order.
 * Changed `ip_addresses` field for `databricks.sdk.service.settings.CreateIpAccessList` to no longer be required.
 * Changed `ip_addresses` field for `databricks.sdk.service.settings.ReplaceIpAccessList` to no longer be required.
 * Removed `list_id` field for `databricks.sdk.service.settings.ReplaceIpAccessList`.
 * Changed `enabled` field for `databricks.sdk.service.settings.UpdateIpAccessList` to no longer be required.
 * Changed `ip_addresses` field for `databricks.sdk.service.settings.UpdateIpAccessList` to no longer be required.
 * Changed `label` field for `databricks.sdk.service.settings.UpdateIpAccessList` to no longer be required.
 * Removed `list_id` field for `databricks.sdk.service.settings.UpdateIpAccessList`.
 * Changed `list_type` field for `databricks.sdk.service.settings.UpdateIpAccessList` to no longer be required.

OpenAPI SHA: d3853c8dee5806d04da2ae8910f273ffb35719a5, Date: 2023-12-14
@kartikgupta-db kartikgupta-db mentioned this pull request Dec 20, 2023
github-merge-queue bot pushed a commit that referenced this pull request Dec 20, 2023
* Sort imports in service template
([#479](#479)).
* Add `py.typed` to support PEP-561
([#483](#483)).
* Fixed bug in `@retried` when exception subtypes were not respected
([#484](#484)).
* Make `WorkspaceClient` and `AccountClient` more friendly with
autospeccing
([#480](#480)).

API Changes:

* Added `azure_workspace_info` field for
`databricks.sdk.service.provisioning.Workspace`.
* Added `databricks.sdk.service.provisioning.AzureWorkspaceInfo`
dataclass.
* Changed `update_config()` method for
[w.serving_endpoints](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/serving_endpoints.html)
workspace-level service with new required argument order.
* Changed `served_entities` field for
`databricks.sdk.service.serving.EndpointCoreConfigInput` to no longer be
required.
* Changed `create()` method for
[a.account_ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/account/account_ip_access_lists.html)
account-level service with new required argument order.
* Changed `replace()` method for
[a.account_ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/account/account_ip_access_lists.html)
account-level service with new required argument order.
* Changed `update()` method for
[a.account_ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/account/account_ip_access_lists.html)
account-level service with new required argument order.
* Changed `create()` method for
[w.ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/ip_access_lists.html)
workspace-level service with new required argument order.
* Changed `replace()` method for
[w.ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/ip_access_lists.html)
workspace-level service with new required argument order.
* Changed `update()` method for
[w.ip_access_lists](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/ip_access_lists.html)
workspace-level service with new required argument order.
* Changed `ip_addresses` field for
`databricks.sdk.service.settings.CreateIpAccessList` to no longer be
required.
* Changed `ip_addresses` field for
`databricks.sdk.service.settings.ReplaceIpAccessList` to no longer be
required.
* Removed `list_id` field for
`databricks.sdk.service.settings.ReplaceIpAccessList`.
* Changed `enabled` field for
`databricks.sdk.service.settings.UpdateIpAccessList` to no longer be
required.
* Changed `ip_addresses` field for
`databricks.sdk.service.settings.UpdateIpAccessList` to no longer be
required.
* Changed `label` field for
`databricks.sdk.service.settings.UpdateIpAccessList` to no longer be
required.
* Removed `list_id` field for
`databricks.sdk.service.settings.UpdateIpAccessList`.
* Changed `list_type` field for
`databricks.sdk.service.settings.UpdateIpAccessList` to no longer be
required.

OpenAPI SHA: d3853c8dee5806d04da2ae8910f273ffb35719a5, Date: 2023-12-14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants