test_hatch_build.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import logging
  2. import subprocess
  3. from hatch_build import PRICING_FILE_RELATIVE_PATH, CustomBuildHook
  4. def _build_hook_with_root(tmp_path) -> CustomBuildHook:
  5. hook = CustomBuildHook.__new__(CustomBuildHook)
  6. hook.root = str(tmp_path)
  7. return hook
  8. def test_skipping_download_still_warns_if_pricing_file_missing(monkeypatch, tmp_path, caplog):
  9. def _raise_no_git(*_args, **_kwargs):
  10. raise FileNotFoundError("git")
  11. monkeypatch.setattr(subprocess, "run", _raise_no_git)
  12. hook = _build_hook_with_root(tmp_path)
  13. caplog.set_level(logging.INFO)
  14. hook.initialize(version="0.0.0", build_data={})
  15. expected_path = tmp_path / PRICING_FILE_RELATIVE_PATH
  16. assert "Skipping pricing data download (branch is not 'main')." in caplog.text
  17. assert f"Pricing file not found at {expected_path}" in caplog.text
  18. def test_skipping_download_does_not_error_when_pricing_file_exists(monkeypatch, tmp_path, caplog):
  19. monkeypatch.setattr(subprocess, "run", lambda *_args, **_kwargs: subprocess.CompletedProcess([], 0, stdout="dev\n"))
  20. pricing_file_path = tmp_path / PRICING_FILE_RELATIVE_PATH
  21. pricing_file_path.parent.mkdir(parents=True, exist_ok=True)
  22. pricing_file_path.write_text("{}", encoding="utf-8")
  23. hook = _build_hook_with_root(tmp_path)
  24. caplog.set_level(logging.INFO)
  25. hook.initialize(version="0.0.0", build_data={})
  26. assert "Skipping pricing data download (branch is not 'main')." in caplog.text
  27. assert "Pricing file not found at" not in caplog.text