test_userkit.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from __future__ import annotations
  2. import os
  3. import sys
  4. import zipfile
  5. from pathlib import Path
  6. import pytest
  7. TOOLS = Path(__file__).resolve().parents[3] / "tools"
  8. sys.path.insert(0, str(TOOLS))
  9. from package_hth_user_kits import VERSION, build_python_kit # noqa: E402
  10. from zip_unix_modes import extract_zip_with_unix_modes # noqa: E402
  11. def _wheel() -> Path | None:
  12. env = os.environ.get("HTH_SDK_WHEEL")
  13. if env and Path(env).is_file():
  14. return Path(env)
  15. dist = Path(__file__).resolve().parents[1] / "dist"
  16. wheels = sorted(dist.glob("hth_sdk-*.whl")) if dist.is_dir() else []
  17. return wheels[-1] if wheels else None
  18. def test_python_kit_zip_has_no_platform_guts(tmp_path):
  19. wheel = _wheel()
  20. if wheel is None:
  21. pytest.skip("build host/sdk/python wheel first")
  22. zpath = build_python_kit(wheel, tmp_path)
  23. assert zpath.is_file()
  24. with zipfile.ZipFile(zpath) as zf:
  25. names = zf.namelist()
  26. joined = "\n".join(names)
  27. assert "go.mod" not in joined
  28. assert ".proto" not in joined
  29. assert "reviews/" not in joined
  30. assert any(name.endswith("INSTALL.sh") for name in names)
  31. assert any(name.endswith("quickstart.py") for name in names)
  32. assert any(name.endswith("sample.jsonl") for name in names)
  33. assert f"hth-algorithm-python-kit-{VERSION}/" in names[0] or any(
  34. n.startswith(f"hth-algorithm-python-kit-{VERSION}/") for n in names
  35. )
  36. stage = tmp_path / "stage"
  37. extract_zip_with_unix_modes(zpath, stage)
  38. install = next(stage.rglob("INSTALL.sh"))
  39. assert install.stat().st_mode & 0o111
  40. def test_userkit_scripts_exist():
  41. root = Path(__file__).resolve().parents[2] / "userkit"
  42. for name in (
  43. "INSTALL.sh",
  44. "INSTALL.cmd",
  45. "START_HERE.sh",
  46. "SELF_TEST.sh",
  47. "install_kit.py",
  48. "README_FIRST_zh-CN.txt",
  49. ):
  50. assert (root / name).is_file(), name