mirror of
https://github.com/deepseek-ai/DeepInfer.git
synced 2026-10-29 23:37:28 +08:00
Merge d73c0f06cab34867f9d8b146346885ee513aacf3 into 553741557a57df44a46fb3ab72b6aafeaf945337
This commit is contained in:
commit
47221f7f9f
41
tests/engine/test_engine_type_consistency.py
Normal file
41
tests/engine/test_engine_type_consistency.py
Normal file
@ -0,0 +1,41 @@
|
||||
"""Guard against drift between the C++ and Python EngineType enums.
|
||||
|
||||
csrc/engine/scheduler.hpp and deepinfer/engine/engine_type.py define the same
|
||||
enum twice (the C++ side is not exposed through pybind), and the two copies
|
||||
are only kept in sync by a comment convention. Parse the header and assert
|
||||
both definitions match, so an accidental drift fails fast in CI instead of a
|
||||
Python enum value silently being interpreted as a different engine type by
|
||||
the C++ scheduler.
|
||||
"""
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from deepinfer.engine.engine_type import EngineType
|
||||
|
||||
pytestmark = [pytest.mark.ci, pytest.mark.ci_npu]
|
||||
|
||||
HEADER = Path(__file__).resolve().parents[2] / "csrc" / "engine" / "scheduler.hpp"
|
||||
|
||||
ENUM_RE = re.compile(r"enum\s+class\s+EngineType\s*:\s*int\s*\{(?P<body>.*?)\};", re.DOTALL)
|
||||
MEMBER_RE = re.compile(r"(\w+)\s*=\s*(-?\d+)")
|
||||
|
||||
|
||||
def cpp_engine_types() -> dict[str, int]:
|
||||
source = HEADER.read_text(encoding="utf-8")
|
||||
match = ENUM_RE.search(source)
|
||||
assert match is not None, f"enum class EngineType not found in {HEADER}"
|
||||
members = MEMBER_RE.findall(match.group("body"))
|
||||
assert members, f"no members parsed from enum EngineType in {HEADER}"
|
||||
return {name: int(value) for name, value in members}
|
||||
|
||||
|
||||
def test_engine_type_matches_cpp_definition() -> None:
|
||||
cpp = cpp_engine_types()
|
||||
py = {member.name: member.value for member in EngineType}
|
||||
assert py == cpp, (
|
||||
"EngineType definitions drifted between csrc/engine/scheduler.hpp and "
|
||||
f"deepinfer/engine/engine_type.py:\n C++: {cpp}\n Python: {py}"
|
||||
)
|
||||
Loading…
x
Reference in New Issue
Block a user