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:
+102
-4
@@ -1,7 +1,9 @@
|
||||
"""Tests for the introspection module."""
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from typing import cast
|
||||
from unittest.mock import patch
|
||||
|
||||
from introspect import (
|
||||
FunctionData,
|
||||
@@ -12,6 +14,8 @@ from introspect import (
|
||||
refine_types_by_context,
|
||||
clean_docstring,
|
||||
clean_type_str,
|
||||
introspect_ops_module,
|
||||
introspect_screen_context_members,
|
||||
parse_docstring_types,
|
||||
python_type_name,
|
||||
)
|
||||
@@ -160,6 +164,30 @@ class TestParseDocstringTypes(unittest.TestCase):
|
||||
def test_plural_matrices(self) -> None:
|
||||
self.assertEqual(clean_type_str("matrices"), "mathutils.Matrix")
|
||||
|
||||
def test_informal_mathutils_types_are_qualified(self) -> None:
|
||||
self.assertEqual(
|
||||
clean_type_str("vector | matrix | quaternion | euler | color"),
|
||||
"mathutils.Vector | mathutils.Matrix | mathutils.Quaternion | mathutils.Euler | mathutils.Color",
|
||||
)
|
||||
|
||||
def test_literal_values_are_quoted(self) -> None:
|
||||
self.assertEqual(
|
||||
clean_type_str("Literal[NONE, ALPHA]"),
|
||||
"Literal['NONE', 'ALPHA']",
|
||||
)
|
||||
|
||||
def test_str_in_values_converts_to_literal(self) -> None:
|
||||
self.assertEqual(
|
||||
clean_type_str("string in ['NONE', 'ALPHA']"),
|
||||
"Literal['NONE', 'ALPHA']",
|
||||
)
|
||||
|
||||
def test_str_in_values_supports_double_quotes(self) -> None:
|
||||
self.assertEqual(
|
||||
clean_type_str('str in ["NONE", "ALPHA"]'),
|
||||
"Literal['NONE', 'ALPHA']",
|
||||
)
|
||||
|
||||
def test_sequence_multi_arg_to_tuple(self) -> None:
|
||||
self.assertEqual(
|
||||
clean_type_str("Sequence[int, int]"), "Sequence[tuple[int, int]]"
|
||||
@@ -340,7 +368,8 @@ class TestRstOnlyParams(unittest.TestCase):
|
||||
".. method:: foreach_get(seq)\n\nFast access to array data."
|
||||
)
|
||||
result = introspect_callable(func, "foreach_get")
|
||||
assert result is not None
|
||||
self.assertIsNotNone(result)
|
||||
result = cast(FunctionData, result)
|
||||
self.assertEqual(len(result["params"]), 1)
|
||||
self.assertEqual(result["params"][0]["name"], "seq")
|
||||
self.assertIsNone(result["params"][0]["type"])
|
||||
@@ -349,7 +378,8 @@ class TestRstOnlyParams(unittest.TestCase):
|
||||
"""RST params without :type: are added after typed params."""
|
||||
func = _NoSigCallable(".. method:: foo(a, b)\n\n:type a: str")
|
||||
result = introspect_callable(func, "foo")
|
||||
assert result is not None
|
||||
self.assertIsNotNone(result)
|
||||
result = cast(FunctionData, result)
|
||||
self.assertEqual(len(result["params"]), 2)
|
||||
self.assertEqual(result["params"][0]["name"], "a")
|
||||
self.assertEqual(result["params"][0]["type"], "str")
|
||||
@@ -367,7 +397,8 @@ class TestParamNameMismatch(unittest.TestCase):
|
||||
return ""
|
||||
|
||||
result = introspect_callable(fake_func, "escape_identifier")
|
||||
assert result is not None
|
||||
self.assertIsNotNone(result)
|
||||
result = cast(FunctionData, result)
|
||||
self.assertEqual(result["params"][0]["name"], "string")
|
||||
self.assertEqual(result["params"][0]["type"], "str")
|
||||
|
||||
@@ -378,7 +409,8 @@ class TestParamNameMismatch(unittest.TestCase):
|
||||
return ""
|
||||
|
||||
result = introspect_callable(fake_func, "basename")
|
||||
assert result is not None
|
||||
self.assertIsNotNone(result)
|
||||
result = cast(FunctionData, result)
|
||||
self.assertEqual(result["params"][0]["name"], "path")
|
||||
self.assertEqual(result["params"][0]["type"], "str")
|
||||
|
||||
@@ -527,5 +559,71 @@ class TestInferGetterReturnTypes(unittest.TestCase):
|
||||
self.assertIsNone(functions[0]["return_type"])
|
||||
|
||||
|
||||
class _ContextWithRaisingMember:
|
||||
ok = 7
|
||||
|
||||
def __dir__(self) -> list[str]:
|
||||
return ["ok", "broken", "callable_member", "rna_type"]
|
||||
|
||||
@property
|
||||
def broken(self) -> object:
|
||||
raise RuntimeError("cannot access in this context")
|
||||
|
||||
def callable_member(self) -> None:
|
||||
return None
|
||||
|
||||
|
||||
class _OpsNoCallableSubmodule:
|
||||
non_callable = 123
|
||||
|
||||
def __dir__(self) -> list[str]:
|
||||
return ["non_callable"]
|
||||
|
||||
|
||||
class _OpsRootNoCallable:
|
||||
mesh = _OpsNoCallableSubmodule()
|
||||
|
||||
def __dir__(self) -> list[str]:
|
||||
return ["mesh"]
|
||||
|
||||
|
||||
class _OpsRootEmpty:
|
||||
def __dir__(self) -> list[str]:
|
||||
return []
|
||||
|
||||
|
||||
class TestRuntimeEdgeCases(unittest.TestCase):
|
||||
def test_context_member_discovery_skips_raising_attributes(self) -> None:
|
||||
fake_bpy = SimpleNamespace(context=_ContextWithRaisingMember())
|
||||
with patch("introspect.importlib.import_module", return_value=fake_bpy):
|
||||
props = introspect_screen_context_members(set())
|
||||
|
||||
by_name = {p["name"]: p for p in props}
|
||||
self.assertIn("ok", by_name)
|
||||
self.assertEqual(by_name["ok"]["type"], "int | None")
|
||||
self.assertNotIn("broken", by_name)
|
||||
self.assertNotIn("callable_member", by_name)
|
||||
|
||||
def test_ops_introspection_falls_back_when_no_callable_operator(self) -> None:
|
||||
fake_bpy = SimpleNamespace(ops=_OpsRootNoCallable())
|
||||
with patch("introspect.importlib.import_module", return_value=fake_bpy):
|
||||
data = introspect_ops_module()
|
||||
|
||||
self.assertEqual(data["module"], "bpy.ops")
|
||||
self.assertEqual(data["structs"], [])
|
||||
self.assertEqual(
|
||||
data["variables"], [{"name": "mesh", "type": "object", "value": "..."}]
|
||||
)
|
||||
|
||||
def test_ops_introspection_falls_back_when_no_submodules(self) -> None:
|
||||
fake_bpy = SimpleNamespace(ops=_OpsRootEmpty())
|
||||
with patch("introspect.importlib.import_module", return_value=fake_bpy):
|
||||
data = introspect_ops_module()
|
||||
|
||||
self.assertEqual(data["module"], "bpy.ops")
|
||||
self.assertEqual(data["structs"], [])
|
||||
self.assertEqual(data["variables"], [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user