Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ jobs:
run: uv run mypy src/kernels

- name: Run tests
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
uv run pytest tests

- name: Run staging tests
env:
HF_TOKEN: ${{ secrets.HF_STAGING_TOKEN }}
run: |
HUGGINGFACE_CO_STAGING=true uv run pytest --token -m "is_staging_test" tests/

- name: Check kernel conversion
run: |
uv pip install wheel
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ markers =
darwin_only: marks tests that should only run on macOS
xpu_only: marks tests that should only run on hosts with Intel XPUs
token: enable tests that require a write token
is_staging_test: Marks tests that should only run on a staging environment
31 changes: 29 additions & 2 deletions tests/test_kernel_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from typing import List

import pytest
from huggingface_hub import model_info
from huggingface_hub import delete_repo, model_info

from kernels.cli import upload_kernels

REPO_ID = "kernels-test/kernels-upload-test"
REPO_ID = "valid_org/kernels-upload-test"


PY_CONTENT = """\
#!/usr/bin/env python3
Expand Down Expand Up @@ -68,7 +69,32 @@ def get_filenames_from_a_repo(repo_id: str) -> List[str]:


@pytest.mark.token
@pytest.mark.is_staging_test
def test_kernel_upload_works_as_expected():
with tempfile.TemporaryDirectory() as tmpdir:
path = f"{tmpdir}/build/torch-universal/upload_test"
build_dir = Path(path)
build_dir.mkdir(parents=True, exist_ok=True)
script_path = build_dir / "foo.py"
script_path.write_text(PY_CONTENT)
upload_kernels(UploadArgs(tmpdir, REPO_ID, False))

repo_filenames = get_filenames_from_a_repo(REPO_ID)
assert any(str(script_path.name) for f in repo_filenames)
delete_repo(repo_id=REPO_ID)


@pytest.mark.token
@pytest.mark.is_staging_test
def test_kernel_upload_deletes_as_expected():
with tempfile.TemporaryDirectory() as tmpdir:
path = f"{tmpdir}/build/torch-universal/upload_test"
build_dir = Path(path)
build_dir.mkdir(parents=True, exist_ok=True)
script_path = build_dir / "foo_2025.py"
script_path.write_text(PY_CONTENT)
upload_kernels(UploadArgs(tmpdir, REPO_ID, False))

repo_filenames = get_filenames_from_a_repo(REPO_ID)
filename_to_change = get_filename_to_change(repo_filenames)

Expand All @@ -86,3 +112,4 @@ def test_kernel_upload_deletes_as_expected():
assert not any(
str(filename_to_change) in k for k in repo_filenames
), f"{repo_filenames=}"
delete_repo(repo_id=REPO_ID)
Loading