Files
AnyImage/tests/test_pack.py
nan 0c8d3a8988 Bump version to 0.11.2 and update uv version to 0.11.3
- Updated version in pyproject.toml and blender_manifest.toml to 0.11.2.
- Enhanced uv executable path documentation in client.py.
- Added inference_mode parameter to reconstruct_request function in client.py.
- Implemented uv download functionality in install_env.py with improved error handling and checksum verification.
- Modified install_uv function to download and extract uv binary instead of using bundled version.
- Updated job progress handling in operators.py to track progress stages.
- Improved download progress reporting in worker.py and adjusted related tests.
- Refactored tests to accommodate changes in status reporting and model downloading.
- Removed vendor.lock.toml as part of the cleanup process.
2026-08-14 23:43:01 +08:00

98 lines
3.3 KiB
Python

import importlib.util
import tempfile
import tomllib
import unittest
from pathlib import Path
from zipfile import ZipFile
PROJECT_ROOT = Path(__file__).resolve().parents[1]
def load_pack():
specification = importlib.util.spec_from_file_location(
"snapform_pack",
PROJECT_ROOT / "pack.py",
)
module = importlib.util.module_from_spec(specification)
specification.loader.exec_module(module)
return module
class PackTest(unittest.TestCase):
def test_builds_platform_specific_extension_zips(self):
pack = load_pack()
with tempfile.TemporaryDirectory() as directory:
original_dist = pack.DIST_DIR
pack.DIST_DIR = Path(directory)
try:
output_paths = pack.build_all()
finally:
pack.DIST_DIR = original_dist
version = tomllib.loads(
(pack.SOURCE_DIR / "blender_manifest.toml").read_text(
encoding="utf-8"
)
)["version"]
self.assertEqual(
{path.name for path in output_paths},
{
f"SnapForm.v{version}.{platform}.zip"
for platform in pack.PLATFORMS
},
)
for output_path in output_paths:
platform = output_path.stem.split(".")[-1]
with ZipFile(output_path) as archive:
names = set(archive.namelist())
manifest = archive.read("blender_manifest.toml").decode(
"utf-8"
)
self.assertIn("__init__.py", names)
self.assertIn("blender_manifest.toml", names)
self.assertIn("image_depth.py", names)
self.assertIn(
"assets/O_SnapForm.blend",
names,
)
self.assertIn("worker.py", names)
self.assertIn("service.py", names)
self.assertNotIn("snapform/__init__.py", names)
self.assertNotIn("importer.py", names)
self.assertFalse(
any(name.startswith("sources/") for name in names)
)
self.assertFalse(
any(name.startswith("vendor/") for name in names)
)
self.assertIn(f'platforms = ["{platform}"]', manifest)
self.assertNotIn(
"windows-x64"
if platform != "windows-x64"
else "macos-arm64",
manifest.split("platforms =", 1)[-1],
)
def test_rejects_unknown_platform(self):
pack = load_pack()
with self.assertRaisesRegex(ValueError, "Unsupported platform"):
pack.build_extension("windows-arm64")
def test_platforms_match_manifest(self):
pack = load_pack()
manifest = tomllib.loads(
(pack.SOURCE_DIR / "blender_manifest.toml").read_text(
encoding="utf-8"
)
)
self.assertEqual(set(pack.PLATFORMS), set(manifest["platforms"]))
self.assertEqual(
set(pack.PLATFORMS),
{"windows-x64", "macos-arm64", "linux-x64"},
)
if __name__ == "__main__":
unittest.main()