chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:11:15 +08:00
commit ef8818bca3
1664 changed files with 540565 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
"""Shared helpers for repository-owned Python tests."""
+48
View File
@@ -0,0 +1,48 @@
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from unittest import mock
from tests.python.support.paths import add_repo_path
add_repo_path("skills/cad/scripts")
from cadpy import assembly_spec, catalog, generation, glb_topology, metadata, render, step_scene, step_targets
from tests.python.support.tmp_root import CAD_TEST_TMP_ROOT, temporary_directory
IGNORED_TEST_ROOT = CAD_TEST_TMP_ROOT
class IsolatedCadRoots:
def __init__(self, testcase: unittest.TestCase, *, prefix: str) -> None:
self._tempdir = temporary_directory(prefix=prefix)
testcase.addCleanup(self._tempdir.cleanup)
self.root = Path(self._tempdir.name)
self.cad_root = self.root / "workspace"
self.cad_root.mkdir(parents=True, exist_ok=True)
patches = []
for module in (
assembly_spec,
catalog,
render,
generation,
glb_topology,
metadata,
step_scene,
step_targets,
):
if hasattr(module, "CAD_ROOT"):
patches.append(mock.patch.object(module, "CAD_ROOT", self.cad_root))
if hasattr(module, "REPO_ROOT"):
patches.append(mock.patch.object(module, "REPO_ROOT", self.cad_root))
for patcher in patches:
patcher.start()
testcase.addCleanup(patcher.stop)
def temporary_cad_directory(self, *, prefix: str) -> tempfile.TemporaryDirectory[str]:
return tempfile.TemporaryDirectory(prefix=prefix, dir=self.cad_root)
+19
View File
@@ -0,0 +1,19 @@
from __future__ import annotations
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[3]
def repo_path(*parts: str) -> Path:
return REPO_ROOT.joinpath(*parts)
def add_repo_path(*parts: str) -> Path:
path = repo_path(*parts)
path_text = str(path)
if path_text not in sys.path:
sys.path.insert(0, path_text)
return path
+20
View File
@@ -0,0 +1,20 @@
from __future__ import annotations
import tempfile
from pathlib import Path
from tests.python.support.paths import REPO_ROOT
TMP_ROOT = REPO_ROOT / "tmp"
CAD_TEST_TMP_ROOT = TMP_ROOT / "cad-skill-tests"
def temporary_directory(*, prefix: str) -> tempfile.TemporaryDirectory[str]:
CAD_TEST_TMP_ROOT.mkdir(parents=True, exist_ok=True)
return tempfile.TemporaryDirectory(prefix=prefix, dir=CAD_TEST_TMP_ROOT)
def named_tmp_root(name: str) -> Path:
tmp_root = TMP_ROOT / name
tmp_root.mkdir(parents=True, exist_ok=True)
return tmp_root