Files
AnyImage/tests/test_prepare_vendor.py
nan 2e8af26cdf feat: Add GitHub Actions workflow for building and testing the Depth Anything 3 extension
- Create a build workflow in `.github/workflows/build.yml` to automate the build process.
- Configure Python environment and install dependencies.
- Add steps for running tests and packaging the extension.

chore: Initialize project metadata and dependencies for Depth Anything 3

- Add `pyproject.toml` for project configuration and dependencies.
- Include optional dependencies for app and gs functionalities.
- Define project scripts and metadata.

chore: Add requirements file for Depth Anything 3 dependencies

- Create `requirements.txt` listing all necessary packages for the project.

feat: Implement export utility functions for Depth Anything 3

- Create `src/depth_anything_3/utils/export/__init__.py` to handle various export formats.
- Implement functions for exporting predictions in different formats.

feat: Add ray utility functions for homography estimation

- Create `src/depth_anything_3/utils/ray_utils.py` with functions for computing optimal rotation and homography using RANSAC.

feat: Implement vendor preparation script

- Add `prepare_vendor.py` to manage third-party dependencies and artifacts.
- Include functions for downloading and verifying artifacts based on a lock file.

test: Add unit tests for vendor preparation script

- Create `tests/test_prepare_vendor.py` to test artifact downloading and verification.
- Implement tests for handling hash mismatches and unsupported platforms.

chore: Add vendor lock file for dependency management

- Create `vendor.lock.toml` to define artifacts and platforms for the project.
2026-08-09 11:44:24 +08:00

68 lines
2.3 KiB
Python

import hashlib
import importlib.util
import io
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
PROJECT_ROOT = Path(__file__).resolve().parents[1]
def load_prepare_vendor():
specification = importlib.util.spec_from_file_location(
"snapform_prepare_vendor",
PROJECT_ROOT / "prepare_vendor.py",
)
module = importlib.util.module_from_spec(specification)
specification.loader.exec_module(module)
return module
class PrepareVendorTest(unittest.TestCase):
def test_downloads_and_verifies_artifact(self):
prepare = load_prepare_vendor()
content = b"locked artifact"
artifact = {
"filename": "artifact.tar.gz",
"url": "https://example.invalid/artifact.tar.gz",
"sha256": hashlib.sha256(content).hexdigest(),
}
with tempfile.TemporaryDirectory() as directory, patch.object(
prepare.urllib.request,
"urlopen",
return_value=io.BytesIO(content),
):
path = prepare.download_artifact(artifact, Path(directory))
self.assertEqual(path.read_bytes(), content)
def test_rejects_hash_mismatch_without_leaving_partial_file(self):
prepare = load_prepare_vendor()
artifact = {
"filename": "artifact.tar.gz",
"url": "https://example.invalid/artifact.tar.gz",
"sha256": hashlib.sha256(b"expected").hexdigest(),
}
with tempfile.TemporaryDirectory() as directory, patch.object(
prepare.urllib.request,
"urlopen",
return_value=io.BytesIO(b"unexpected"),
):
destination = Path(directory)
with self.assertRaisesRegex(RuntimeError, "SHA-256 mismatch"):
prepare.download_artifact(artifact, destination)
self.assertFalse((destination / artifact["filename"]).exists())
self.assertFalse(
(destination / f"{artifact['filename']}.part").exists()
)
def test_rejects_unknown_platform(self):
prepare = load_prepare_vendor()
with self.assertRaisesRegex(ValueError, "Unsupported platform"):
prepare.prepare(["windows-arm64"])
if __name__ == "__main__":
unittest.main()