Skip to content

Commit

Permalink
Update Python tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Velichkevich <[email protected]>
  • Loading branch information
andreyvelich committed Jan 18, 2025
1 parent 2d3a72a commit 100cb5b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 32 deletions.
30 changes: 12 additions & 18 deletions .github/workflows/test-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,35 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]

python-test:
test:
name: Test
runs-on: ubuntu-latest
env:
PYTHONPATH: ${{ github.workspace }}:${PYTHONPATH}

strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11"]
# Python version to run unit and integration tests.
python-version: ["3.11"]

steps:
- name: Check out code
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
- name: Run Python unit tests
run: |
pip install pytest python-dateutil urllib3 kubernetes
pip install -U './sdk/python[huggingface]'
make test-python
- name: Run unit test for training sdk
- name: Run Python integration tests.
run: |
pytest ./sdk/python/kubeflow/training/api/training_client_test.py
- name: Run Python unit tests for v2
run: |
pip install -U './sdk_v2'
export PYTHONPATH="${{ github.workspace }}:$PYTHONPATH"
pytest ./pkg/initializer_v2/model
pytest ./pkg/initializer_v2/dataset
pytest ./pkg/initializer_v2/utils
make test-python-integration
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ help: ## Display this help.

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))


## Tool Binaries
# Tool Binaries
LOCALBIN ?= $(PROJECT_DIR)/bin
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

ENVTEST_K8S_VERSION ?= 1.31

# Instructions to download tools for development.
.PHONY: envtest
envtest: ## Download the setup-envtest binary if required.
test -s $(ENVTEST) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/[email protected]
Expand All @@ -47,7 +47,7 @@ envtest: ## Download the setup-envtest binary if required.
controller-gen: ## Download the controller-gen binary if required.
test -s $(CONTROLLER_GEN) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/[email protected]

# Download external CRDs for the integration testings.
# Download external CRDs for Go integration testings.
EXTERNAL_CRDS_DIR ?= $(PROJECT_DIR)/manifests/external-crds

JOBSET_ROOT = $(shell go list -m -mod=readonly -f "{{.Dir}}" sigs.k8s.io/jobset)
Expand All @@ -62,6 +62,7 @@ scheduler-plugins-crd: ## Copy the CRDs from the Scheduler Plugins repository to
mkdir -p $(EXTERNAL_CRDS_DIR)/scheduler-plugins/
cp -f $(SCHEDULER_PLUGINS_ROOT)/manifests/coscheduling/* $(EXTERNAL_CRDS_DIR)/scheduler-plugins

# Instructions for code generation.
.PHONY: manifests
manifests: controller-gen ## Generate manifests.
$(CONTROLLER_GEN) "crd:generateEmbeddedObjectMeta=true" rbac:roleName=training-operator-v2 webhook \
Expand All @@ -80,6 +81,7 @@ generate: go-mod-download manifests ## Generate APIs and SDK.
go-mod-download: ## Run go mod download to download modules.
go mod download

# Instructions for code formatting.
.PHONY: fmt
fmt: ## Run go fmt against the code.
go fmt ./...
Expand All @@ -97,10 +99,27 @@ ifeq ($(GOLANGCI_LINT),)
endif
golangci-lint run --timeout 5m --go 1.23 ./...

# Instructions to run tests.
.PHONY: test
test: ## Run Go unit test.
go test ./pkg/apis/kubeflow.org/v2alpha1/... ./pkg/controller.v2/... ./pkg/runtime.v2/... ./pkg/webhooks.v2/... ./pkg/util.v2/... -coverprofile cover.out

.PHONY: test-integration
test-integration: envtest jobset-operator-crd scheduler-plugins-crd ## Run Go integration test.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./test/... -coverprofile cover.out

test-python: ## Run Python unit test.
export PYTHONPATH=$(PROJECT_DIR)
pip install pytest
pip install -r ./cmd/initializer_v2/dataset/requirements.txt

pytest ./pkg/initializer_v2/dataset
pytest ./pkg/initializer_v2/model
pytest ./pkg/initializer_v2/utils

test-python-integration: ## Run Python integration test.
export PYTHONPATH=$(PROJECT_DIR)
pip install pytest
pip install -r ./cmd/initializer_v2/dataset/requirements.txt

pytest ./test/integration/initializer_v2
Empty file removed test/__init__.py
Empty file.
Empty file removed test/integration/__init__.py
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions test/integration/initializer_v2/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ def configure_path(path_var: str):
shutil.rmtree(temp_dir, ignore_errors=True)
os.environ.clear()
os.environ.update(original_env)


def verify_downloaded_files(dir_path, expected_files):
"""Verify downloaded files"""
if expected_files:
actual_files = set(os.listdir(dir_path))
missing_files = set(expected_files) - actual_files
assert not missing_files, f"Missing expected files: {missing_files}"
2 changes: 1 addition & 1 deletion test/integration/initializer_v2/dataset_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import runpy
from test.integration.initializer_v2.utils import verify_downloaded_files

import pytest
from conftest import verify_downloaded_files

import pkg.initializer_v2.utils.utils as utils

Expand Down
2 changes: 1 addition & 1 deletion test/integration/initializer_v2/model_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import runpy
from test.integration.initializer_v2.utils import verify_downloaded_files

import pytest
from conftest import verify_downloaded_files

import pkg.initializer_v2.utils.utils as utils

Expand Down
9 changes: 0 additions & 9 deletions test/integration/initializer_v2/utils.py

This file was deleted.

0 comments on commit 100cb5b

Please sign in to comment.