[misc] CI hygiene: enforce __main__ entry, drop silent-skipped tests, fix rerun-test protoc (#23305)
This commit is contained in:
@@ -42,3 +42,9 @@ class TestExpandPreset:
|
||||
"""Unknown preset name raises ValueError."""
|
||||
with pytest.raises(ValueError, match="Unknown value for --preset"):
|
||||
expand_preset(["--preset", "nonexistent"], presets=PRESETS)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
sys.exit(pytest.main([__file__, "-v"]))
|
||||
|
||||
@@ -254,3 +254,9 @@ class TestCodePatcher:
|
||||
raise RuntimeError("test error")
|
||||
|
||||
assert obj.greet("world") == "hello world"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
sys.exit(pytest.main([__file__, "-v"]))
|
||||
|
||||
@@ -55,3 +55,11 @@ class TestDumperApplySourcePatches:
|
||||
cls.greet.__code__ = original_code
|
||||
|
||||
assert obj.greet("world") == "hello world"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
sys.exit(pytest.main([__file__, "-v"]))
|
||||
|
||||
@@ -290,3 +290,9 @@ class TestApplyEdits:
|
||||
]
|
||||
result = apply_edits(source=source, edits=edits)
|
||||
assert result == ("def foo():\n" " x = 1\n" " y = 20\n" " return x\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
sys.exit(pytest.main([__file__, "-v"]))
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
from argparse import Namespace
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
@@ -9,9 +6,7 @@ from sglang.srt.debug_utils.dump_comparator import (
|
||||
_calc_rel_diff,
|
||||
_compute_smaller_dtype,
|
||||
_try_unify_shape,
|
||||
main,
|
||||
)
|
||||
from sglang.srt.debug_utils.dumper import DumperConfig, _Dumper
|
||||
from sglang.test.ci.ci_register import register_cpu_ci
|
||||
|
||||
register_cpu_ci(est_time=30, suite="stage-a-test-cpu", nightly=True)
|
||||
@@ -59,101 +54,7 @@ class TestComputeSmallerDtype:
|
||||
assert _compute_smaller_dtype(torch.float32, torch.float32) is None
|
||||
|
||||
|
||||
# ----------------------------- Integration tests -----------------------------
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
|
||||
def _make_dumper(directory: Path) -> _Dumper:
|
||||
return _Dumper(
|
||||
config=DumperConfig(
|
||||
enable=True,
|
||||
dir=str(directory),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _create_dumps(
|
||||
tmp_path: Path,
|
||||
tensor_names: list[str],
|
||||
*,
|
||||
baseline_names: list[str] | None = None,
|
||||
) -> tuple[Path, Path]:
|
||||
if baseline_names is None:
|
||||
baseline_names = tensor_names
|
||||
|
||||
d_baseline: Path = tmp_path / "baseline"
|
||||
d_target: Path = tmp_path / "target"
|
||||
d_baseline.mkdir()
|
||||
d_target.mkdir()
|
||||
|
||||
torch.manual_seed(42)
|
||||
baseline_tensor: torch.Tensor = torch.randn(10, 10)
|
||||
target_tensor: torch.Tensor = baseline_tensor + torch.randn(10, 10) * 0.01
|
||||
|
||||
exp_paths: list[Path] = []
|
||||
for d, names, tensor in [
|
||||
(d_baseline, baseline_names, baseline_tensor),
|
||||
(d_target, tensor_names, target_tensor),
|
||||
]:
|
||||
dumper: _Dumper = _make_dumper(d)
|
||||
for name in names:
|
||||
dumper.dump(name, tensor)
|
||||
dumper.step()
|
||||
exp_paths.append(d / dumper._config.exp_name)
|
||||
|
||||
return exp_paths[0], exp_paths[1]
|
||||
|
||||
|
||||
def _make_args(
|
||||
baseline_path: Path,
|
||||
target_path: Path,
|
||||
*,
|
||||
filter_pattern: str | None = None,
|
||||
) -> Namespace:
|
||||
return Namespace(
|
||||
baseline_path=str(baseline_path),
|
||||
target_path=str(target_path),
|
||||
start_step=0,
|
||||
end_step=1000000,
|
||||
diff_threshold=1e-3,
|
||||
filter=filter_pattern,
|
||||
)
|
||||
|
||||
|
||||
class TestMainBasic:
|
||||
def test_matching_tensors(
|
||||
self, tmp_path: Path, capsys: pytest.CaptureFixture
|
||||
) -> None:
|
||||
baseline_path, target_path = _create_dumps(tmp_path, ["tensor_a", "tensor_b"])
|
||||
args: Namespace = _make_args(baseline_path, target_path)
|
||||
|
||||
main(args)
|
||||
|
||||
captured: str = capsys.readouterr().out
|
||||
assert "✅" in captured
|
||||
|
||||
def test_with_filter(self, tmp_path: Path, capsys: pytest.CaptureFixture) -> None:
|
||||
baseline_path, target_path = _create_dumps(tmp_path, ["tensor_a", "tensor_b"])
|
||||
args: Namespace = _make_args(
|
||||
baseline_path, target_path, filter_pattern="tensor_a"
|
||||
)
|
||||
|
||||
main(args)
|
||||
|
||||
captured: str = capsys.readouterr().out
|
||||
assert "tensor_a" in captured
|
||||
assert "Check:" in captured
|
||||
|
||||
def test_no_match_skips(
|
||||
self, tmp_path: Path, capsys: pytest.CaptureFixture
|
||||
) -> None:
|
||||
baseline_path, target_path = _create_dumps(
|
||||
tmp_path,
|
||||
["only_in_target"],
|
||||
baseline_names=["only_in_baseline"],
|
||||
)
|
||||
args: Namespace = _make_args(baseline_path, target_path)
|
||||
|
||||
main(args)
|
||||
|
||||
captured: str = capsys.readouterr().out
|
||||
assert "Skip" in captured
|
||||
sys.exit(pytest.main([__file__, "-v"]))
|
||||
|
||||
Reference in New Issue
Block a user