RNA enum properties support

This commit is contained in:
2026-09-21 11:18:10 +02:00
parent f575a84c13
commit f2efa629ba
8 changed files with 134 additions and 8 deletions
+11
View File
@@ -19,6 +19,17 @@ from blender_downloader import (
class TestGetDownloadUrl(unittest.TestCase):
def test_builds_correct_blender_5_2_url(self) -> None:
with patch("blender_downloader.get_platform_suffix", return_value="linux-x64"):
with patch(
"blender_downloader.get_archive_extension", return_value=".tar.xz"
):
url = get_download_url("5.2.0")
self.assertEqual(
url,
"https://download.blender.org/release/Blender5.2/blender-5.2.0-linux-x64.tar.xz",
)
def test_builds_correct_url(self) -> None:
with patch("blender_downloader.get_platform_suffix", return_value="linux-x64"):
with patch(
+35
View File
@@ -719,6 +719,41 @@ class TestCollectAllMethods(unittest.TestCase):
class TestGenerateTypesStub(unittest.TestCase):
def test_rna_enum_aliases_are_reusable(self) -> None:
structs = [
{
"name": "Panel",
"doc": "",
"base": "bpy_struct",
"properties": [
{
"name": "bl_space_type",
"type": 'Literal["EMPTY", "PROPERTIES"]',
"is_readonly": False,
"description": "",
},
{
"name": "bl_region_type",
"type": 'Literal["WINDOW", "HEADER"]',
"is_readonly": False,
"description": "",
},
],
"methods": [],
}
]
content = generate_types_stub(structs)
self.assertIn(
'SpaceType: TypeAlias = Literal["EMPTY", "PROPERTIES"]', content
)
self.assertIn(
'RegionType: TypeAlias = Literal["WINDOW", "HEADER"]', content
)
self.assertIn("bl_space_type: SpaceType", content)
self.assertIn("bl_region_type: RegionType", content)
def test_includes_header(self) -> None:
structs: list[StructData] = [
{
+26
View File
@@ -21,6 +21,7 @@ from introspect import (
parse_docstring_types,
python_type_name,
rna_property_to_type,
rna_enum_literal_type,
)
@@ -254,6 +255,31 @@ class TestParseDocstringTypes(unittest.TestCase):
self.assertEqual(clean_type_str("SettingsGroup"), "SettingsGroup")
class TestRnaEnumLiteralType(unittest.TestCase):
def test_reads_enum_identifiers_from_rna_metadata(self) -> None:
enum_property = SimpleNamespace(
type="ENUM",
enum_items=[
SimpleNamespace(identifier="EMPTY"),
SimpleNamespace(identifier="VIEW_3D"),
],
)
rna = SimpleNamespace(properties={"bl_space_type": enum_property})
cls = cast(type[object], SimpleNamespace(bl_rna=rna))
self.assertEqual(
rna_enum_literal_type(cls, "bl_space_type"),
'Literal["EMPTY", "VIEW_3D"]',
)
def test_returns_none_for_non_enum_properties(self) -> None:
prop = SimpleNamespace(type="STRING")
rna = SimpleNamespace(properties={"name": prop})
cls = cast(type[object], SimpleNamespace(bl_rna=rna))
self.assertIsNone(rna_enum_literal_type(cls, "name"))
class TestRefineTypesByContext(unittest.TestCase):
def test_bool_vector_default(self) -> None:
param_types = {"default": "Sequence"}