test_import.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Import and packaging smoke tests. Do not require a running daemon."""
  2. from __future__ import annotations
  3. def test_import_package():
  4. import hth_sdk
  5. assert hth_sdk.__version__ == "0.3.0"
  6. def test_public_symbols():
  7. import hth_sdk
  8. assert hth_sdk.__all__ == ["HTH", "State", "Control", "Result", "HTHError"]
  9. for name in hth_sdk.__all__:
  10. assert hasattr(hth_sdk, name)
  11. assert "ActionBatch" not in hth_sdk.__all__
  12. assert "HthClient" not in hth_sdk.__all__
  13. assert "ControlLease" not in hth_sdk.__all__
  14. def test_sdk_does_not_import_heavy_deps():
  15. import ast
  16. from pathlib import Path
  17. import hth_sdk
  18. banned = {"numpy", "pandas", "torch", "tensorflow"}
  19. root = Path(hth_sdk.__file__).resolve().parent
  20. for path in root.rglob("*.py"):
  21. if "generated" in path.parts:
  22. continue
  23. tree = ast.parse(path.read_text(encoding="utf-8"))
  24. for node in ast.walk(tree):
  25. names: list[str] = []
  26. if isinstance(node, ast.Import):
  27. names = [n.name.split(".", 1)[0] for n in node.names]
  28. elif isinstance(node, ast.ImportFrom) and node.module:
  29. names = [node.module.split(".", 1)[0]]
  30. for name in names:
  31. assert name not in banned, f"{path} imports {name}"