Improve tests, downloader, and project config
- Expand blender_downloader with better error handling and platform support - Add test_main.py for main module tests - Expand test coverage for introspect and generate_stubs - Remove reportUnknownMemberType suppression from conformance config - Exclude conformance/ from ruff linting (docs examples have E402) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
"""Tests for main orchestration helpers."""
|
||||
|
||||
import tempfile
|
||||
import tomllib
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import main
|
||||
|
||||
|
||||
class TestTemporaryConfigCleanup(unittest.TestCase):
|
||||
def test_typecheck_stubs_removes_config_on_subprocess_exception(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
script_dir = Path(td)
|
||||
version_dir = script_dir / "dist" / "5.0"
|
||||
version_dir.mkdir(parents=True)
|
||||
(version_dir / ".python-version").write_text("3.11")
|
||||
config_path = version_dir / "pyrightconfig.json"
|
||||
|
||||
with patch("main.SCRIPT_DIR", script_dir):
|
||||
with patch("main.subprocess.run", side_effect=RuntimeError("boom")):
|
||||
with self.assertRaises(RuntimeError):
|
||||
main.typecheck_stubs(["5.0"])
|
||||
|
||||
self.assertFalse(config_path.exists())
|
||||
|
||||
def test_conformance_removes_config_on_subprocess_exception(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
script_dir = Path(td)
|
||||
version_dir = script_dir / "dist" / "5.0"
|
||||
version_dir.mkdir(parents=True)
|
||||
(version_dir / ".python-version").write_text("3.11")
|
||||
test_dir = script_dir / "conformance" / "5.0"
|
||||
test_dir.mkdir(parents=True)
|
||||
(test_dir / "test_dummy.py").write_text("x = 1\n")
|
||||
config_path = version_dir / "pyrightconfig.conformance.json"
|
||||
|
||||
with patch("main.SCRIPT_DIR", script_dir):
|
||||
with patch("main.subprocess.run", side_effect=RuntimeError("boom")):
|
||||
with self.assertRaises(RuntimeError):
|
||||
main.conformance_check(["5.0"])
|
||||
|
||||
self.assertFalse(config_path.exists())
|
||||
|
||||
|
||||
class TestGeneratedPyproject(unittest.TestCase):
|
||||
def test_generated_pyproject_is_valid_toml(self) -> None:
|
||||
metadata: dict[str, object] = {
|
||||
"name": "blender-python-stubs",
|
||||
"license": "MIT",
|
||||
"keywords": ["blender", "typing"],
|
||||
"authors": [
|
||||
{"name": "Alice", "email": "alice@example.com"},
|
||||
{"name": "Bob"},
|
||||
],
|
||||
"classifiers": ["Programming Language :: Python :: 3"],
|
||||
"urls": {
|
||||
"Homepage": "https://example.test/home",
|
||||
"Issue Tracker": "https://example.test/issues",
|
||||
},
|
||||
}
|
||||
with patch("main.load_project_metadata", return_value=metadata):
|
||||
content = main.build_generated_pyproject(
|
||||
blender_version="5.1",
|
||||
package_version="5.1.0",
|
||||
packages=["bpy", "mathutils"],
|
||||
python_version="3.13",
|
||||
)
|
||||
|
||||
parsed = tomllib.loads(content)
|
||||
self.assertEqual(parsed["project"]["name"], "blender-python-stubs")
|
||||
self.assertEqual(parsed["project"]["version"], "5.1.0")
|
||||
self.assertEqual(parsed["project"]["requires-python"], ">=3.13")
|
||||
self.assertEqual(
|
||||
parsed["tool"]["hatch"]["build"]["targets"]["wheel"]["packages"],
|
||||
["bpy", "mathutils"],
|
||||
)
|
||||
self.assertEqual(
|
||||
parsed["project"]["urls"]["Issue Tracker"],
|
||||
"https://example.test/issues",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user