chore(trainer): add unit tests for DockerClientAdapter #821
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign astefanutti for approval. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":["astefanutti"]} -->
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
@tariq-hasan @Shekharrajak @andreyvelich @Electronic-Waste @astefanutti
Could you please review this?
/ok-to-test
/retest
# Copyright The Kubeflow Authors.
#
The test utilities have been moved to https://github.com/kubeflow/sdk/blob/ee22b33fbb261a2601f5dae9b11c2d82ea7dc7db/kubeflow/test/common.py. Please rebase the PR on main as the error would not have been detected otherwise on CI.
from kubeflow.test.common import FAILED, SUCCESS, TestCase
Hi @chinthanasathyajithcs! Thanks for raising the PR. I have added a few comments.
Done, thanks!
Done, thanks!
Rebased on main and addressed the review comments. PTAL, thanks! @tariq-hasan
tariq-hasan
chinthanasathyajithcs
<!-- Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, check our contributor guidelines: https://www.kubeflow.org/docs/about/contributing
2. To know more about Kubeflow SDK, check the developer guide:
https://github.com/kubeflow/sdk/blob/main/CONTRIBUTING.md
3. If you want faster PR reviews, check how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
-->
What this PR does / why we need it:
Adds unit tests for
DockerClientAdapter, which had 17% coverage and no test file of its own.backend_test.pyreplaces the adapter with a mock, so the adapter's own logic was never run.The tests use a mocked Docker client (no daemon or network needed) and follow the existing
TestCase/parametrizestyle.docker.pycoverage goes from 17% to 95%. The simple pass-through methods (ping,stop_container,remove_container,pull_image) are intentionally left out.The adapter is built with
__new__in the tests, and the constructor tests inject a fakedockermodule throughsys.modules. This is becauseadapters/has no__init__.py, so pytest puts that folder onsys.pathandadapters/docker.pyshadows the realdockerpackage. #792 uses the same__new__approach for the Podman adapter.This PR only adds a test file and does not change any source code.
Local verification:
make verifypassesuv run pytest kubeflow/trainer/backends/containerpassesdocker.pycoverage: 17% -> 95%Assisted-by: Claude
Which issue(s) this PR fixes (optional, in
Fixes #<issue number>, #<issue number>, ...format, will close the issue(s) when PR gets merged):Fixes #818
Checklist: