RNA: Expose ID type identifier in ID structs, add coherence test.
Expose the ID type identifier as defined by the `rna_enum_id_type_items` enum items as `ID.id_type` in RNA. Add some test to `id_management` ensuring that all ID types exposed in `bpy.data` have a valid `id_type` value, i.e. that they have a matching entry in `rna_enum_id_type_items`. This will hopefully prevent future cases like #115151 .
This commit is contained in:
parent
c0b8773a2b
commit
9b08352b21
|
@ -327,6 +327,12 @@ int rna_ID_name_full_length(PointerRNA *ptr)
|
|||
return strlen(name);
|
||||
}
|
||||
|
||||
static int rna_ID_type_get(PointerRNA *ptr)
|
||||
{
|
||||
ID *id = static_cast<ID *>(ptr->data);
|
||||
return GS(id->name);
|
||||
}
|
||||
|
||||
static bool rna_ID_is_evaluated_get(PointerRNA *ptr)
|
||||
{
|
||||
ID *id = (ID *)ptr->data;
|
||||
|
@ -2176,7 +2182,8 @@ static void rna_def_ID(BlenderRNA *brna)
|
|||
RNA_def_struct_idprops_func(srna, "rna_ID_idprops");
|
||||
|
||||
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
|
||||
RNA_def_property_ui_text(prop, "Name", "Unique data-block ID name");
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Name", "Unique data-block ID name (within a same type and library)");
|
||||
RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set");
|
||||
RNA_def_property_string_maxlength(prop, MAX_ID_NAME - 2);
|
||||
RNA_def_property_editable_func(prop, "rna_ID_name_editable");
|
||||
|
@ -2191,6 +2198,13 @@ static void rna_def_ID(BlenderRNA *brna)
|
|||
RNA_def_property_string_maxlength(prop, MAX_ID_FULL_NAME);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
|
||||
prop = RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_ui_text(prop, "Type", "Type identifier of this data-block");
|
||||
RNA_def_property_enum_items(prop, rna_enum_id_type_items);
|
||||
RNA_def_property_enum_funcs(prop, "rna_ID_type_get", nullptr, nullptr);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
|
||||
|
||||
prop = RNA_def_property(srna, "is_evaluated", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
|
|
|
@ -8,6 +8,36 @@ import unittest
|
|||
import random
|
||||
|
||||
|
||||
class TestRNAIDTypes(unittest.TestCase):
|
||||
data_container_id = 'meshes'
|
||||
default_name = "Mesh"
|
||||
|
||||
def test_rna_idtypes(self):
|
||||
# This test the coherence between ID types exposed in `bpy.data`, and these listed in `rna_enum_id_type_items`.
|
||||
new_args_extra = {
|
||||
"curves": {'type': 'CURVE'},
|
||||
"lightprobes": {'type': 'SPHERE'},
|
||||
"node_groups": {'type': 'CompositorNodeTree'},
|
||||
"textures": {'type': 'NONE'},
|
||||
}
|
||||
for container_id in dir(bpy.data):
|
||||
if container_id.startswith("rna") or container_id.startswith("__") or container_id.startswith("version"):
|
||||
continue
|
||||
container = getattr(bpy.data, container_id)
|
||||
if callable(container):
|
||||
continue
|
||||
if not hasattr(container, "__len__"):
|
||||
continue
|
||||
if len(container) == 0:
|
||||
if not hasattr(container, "new"):
|
||||
continue
|
||||
if container_id in new_args_extra:
|
||||
container.new("TestData", **new_args_extra[container_id])
|
||||
else:
|
||||
container.new("TestData")
|
||||
self.assertIsNot(container[0].id_type, "")
|
||||
|
||||
|
||||
class TestHelper:
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue