[tests] turn the kernels upload tests to be staging tests (#152)

This commit is contained in:
Sayak Paul
2025-09-22 22:23:53 +05:30
committed by GitHub
parent bf488208be
commit 93e5765611
3 changed files with 36 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -7,11 +7,12 @@ from pathlib import Path
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
@ -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)
@ -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)