test_import.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.API_VERSION == "hth.api.v1"
  6. assert hth_sdk.__version__ == "0.1.0"
  7. def test_public_symbols():
  8. import hth_sdk
  9. for name in (
  10. "ActionBatch",
  11. "ActionBatchBuilder",
  12. "MockClient",
  13. "HthClient",
  14. "ControlLease",
  15. "connect",
  16. "DeviceEpochChanged",
  17. "DataGap",
  18. ):
  19. assert hasattr(hth_sdk, name)
  20. def test_sdk_does_not_import_heavy_deps():
  21. import ast
  22. from pathlib import Path
  23. import hth_sdk
  24. banned = {"numpy", "pandas", "torch", "tensorflow"}
  25. root = Path(hth_sdk.__file__).resolve().parent
  26. for path in root.rglob("*.py"):
  27. if "generated" in path.parts:
  28. continue
  29. tree = ast.parse(path.read_text(encoding="utf-8"))
  30. for node in ast.walk(tree):
  31. names: list[str] = []
  32. if isinstance(node, ast.Import):
  33. names = [n.name.split(".", 1)[0] for n in node.names]
  34. elif isinstance(node, ast.ImportFrom) and node.module:
  35. names = [node.module.split(".", 1)[0]]
  36. for name in names:
  37. assert name not in banned, f"{path} imports {name}"