litellm/tests/rust-python-harness/shared/unit_runners/test_rust_runner.py
yujonglee ee08c36fc0
refactor(tests): restructure rust python harness around strategy definitions (#39628)
* wip

* refactor(tests): move sdk function tracing into rust python harness

* dead code

* fix: handle harness keyboard interrupts

* refactor(tests): deduplicate rust python harness helpers

* fix(harness): expose validated strategy choices

* wip

* refactor(harness): let strategies own parity reports

* docs(harness): update strategy structure

* refactor(harness): localize strategy report views

* wip

* fix(harness): satisfy mapping runner type checks

* fix(harness): clarify trace parity output

* wip

* fix(harness): clarify unit mapping report

* fix(harness): finalize trace parity contracts

* refactor(harness): structure parity contracts

* feat: derive unit test mapping from traces

* feat(harness): map rstest test families

* feat(ocr): port Azure document intelligence tests

* feat(harness): enforce complete unit mappings

* feat(ocr): add reducto core transforms

* feat(harness): classify host-only unit tests

* fix(ocr): complete Rust provider plumbing

* fix(harness): reuse OCR parity workers
2026-09-03 21:15:01 -07:00

61 lines
2.7 KiB
Python

from __future__ import annotations
import shutil
from collections.abc import Callable
from pathlib import Path
from typing import Final
import pytest
from .rust_runner import RustTarget, RustTestScope, enumerate_rust_tests, run_command, run_rust_tests
@pytest.mark.skipif(shutil.which("cargo") is None, reason="Cargo is required for native runner integration")
def test_collects_and_runs_native_tests_and_propagates_failure(
tmp_path: Path,
cargo_project: Callable[[str, str], Path],
) -> None:
manifest: Final = cargo_project("harness-runner-check", "#[test] fn test_parity() { assert_eq!(2 + 2, 4); }\n")
source: Final = tmp_path / "src/lib.rs"
inventory: Final = run_rust_tests(manifest, "harness-runner-check", "test_parity", collect_only=True)
assert inventory.exit_code == 0, inventory.output
assert inventory.tests == ("test_parity",)
passing: Final = run_rust_tests(manifest, "harness-runner-check", "test_parity")
assert passing.exit_code == 0, passing.output
source.write_text("#[test] fn test_parity() { assert_eq!(2 + 2, 5); }\n")
failed: Final = run_rust_tests(manifest, "harness-runner-check", "test_parity")
assert failed.exit_code != 0
assert "test_parity" in failed.output
@pytest.mark.skipif(shutil.which("cargo") is None, reason="Cargo is required for compiled inventory tests")
def test_discovers_compiled_fully_qualified_tests(tmp_path: Path) -> None:
workspace: Final = tmp_path / "litellm-rust"
source: Final = workspace / "src"
external: Final = source / "ocr" / "external.rs"
external.parent.mkdir(parents=True)
(workspace / "Cargo.toml").write_text(
'[package]\nname = "inventory-fixture"\nversion = "0.1.0"\nedition = "2021"\n[workspace]\n',
encoding="utf-8",
)
(source / "lib.rs").write_text(
"#[cfg(test)]\n"
"mod ocr {\n"
" mod external;\n"
" #[test] fn same_name() {}\n"
" #[cfg(any())] #[test] fn compiled_out() {}\n"
" macro_rules! generate_test { ($name:ident) => { #[test] fn $name() {} }; }\n"
" generate_test!(generated_case);\n"
"}\n",
encoding="utf-8",
)
external.write_text("#[test] fn same_name() {}\n", encoding="utf-8")
run_command(("cargo", "generate-lockfile", "--offline"), workspace)
target: Final = RustTarget(package="inventory-fixture", name="inventory_fixture", kind="lib")
scope: Final = RustTestScope(target=target, modules=("ocr",))
inventory: Final = enumerate_rust_tests(tmp_path, (scope,))
assert frozenset(identity.name for identity in inventory) == frozenset(
("ocr::same_name", "ocr::external::same_name", "ocr::generated_case")
)