mirror of
https://github.com/evennia/evennia.git
synced 2026-03-17 05:16:31 +01:00
Merge pull request #2726 from owllex/attributeproperty
Only initialize AttributeProperty and TagProperty in init_evennia_properties
This commit is contained in:
commit
f67f55387d
2 changed files with 29 additions and 3 deletions
|
|
@ -232,20 +232,36 @@ class TestContentHandler(BaseEvenniaTest):
|
|||
self.assertEqual(self.room2.contents, [self.obj1, self.obj2])
|
||||
|
||||
|
||||
class SubAttributeProperty(AttributeProperty):
|
||||
pass
|
||||
|
||||
|
||||
class SubTagProperty(TagProperty):
|
||||
pass
|
||||
|
||||
|
||||
class TestObjectPropertiesClass(DefaultObject):
|
||||
attr1 = AttributeProperty(default="attr1")
|
||||
attr2 = AttributeProperty(default="attr2", category="attrcategory")
|
||||
attr3 = AttributeProperty(default="attr3", autocreate=False)
|
||||
attr4 = SubAttributeProperty(default="attr4")
|
||||
tag1 = TagProperty()
|
||||
tag2 = TagProperty(category="tagcategory")
|
||||
tag3 = SubTagProperty()
|
||||
testalias = AliasProperty()
|
||||
testperm = PermissionProperty()
|
||||
|
||||
@property
|
||||
def base_property(self):
|
||||
self.property_initialized = True
|
||||
|
||||
|
||||
class TestProperties(EvenniaTestCase):
|
||||
"""
|
||||
Test Properties.
|
||||
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.obj = create.create_object(TestObjectPropertiesClass, key="testobj")
|
||||
|
||||
|
|
@ -270,13 +286,22 @@ class TestProperties(EvenniaTestCase):
|
|||
self.assertFalse(obj.attributes.has("attr3"))
|
||||
self.assertEqual(obj.attr3, "attr3")
|
||||
|
||||
obj.attr3 = "attr3b" # stores it in db!
|
||||
self.assertEqual(obj.db.attr4, "attr4")
|
||||
self.assertEqual(obj.attributes.get("attr4"), "attr4")
|
||||
self.assertEqual(obj.attr4, "attr4")
|
||||
|
||||
obj.attr3 = "attr3b" # stores it in db!
|
||||
|
||||
self.assertEqual(obj.db.attr3, "attr3b")
|
||||
self.assertTrue(obj.attributes.has("attr3"))
|
||||
|
||||
self.assertTrue(obj.tags.has("tag1"))
|
||||
self.assertTrue(obj.tags.has("tag2", category="tagcategory"))
|
||||
self.assertTrue(obj.tags.has("tag3"))
|
||||
|
||||
self.assertTrue(obj.aliases.has("testalias"))
|
||||
self.assertTrue(obj.permissions.has("testperm"))
|
||||
|
||||
# Verify that regular properties do not get fetched in init_evennia_properties,
|
||||
# only Attribute or TagProperties.
|
||||
self.assertFalse(hasattr(obj, "property_initialized"))
|
||||
|
|
|
|||
|
|
@ -39,11 +39,12 @@ from django.utils.text import slugify
|
|||
from evennia.typeclasses.attributes import (
|
||||
Attribute,
|
||||
AttributeHandler,
|
||||
AttributeProperty,
|
||||
ModelAttributeBackend,
|
||||
InMemoryAttributeBackend,
|
||||
)
|
||||
from evennia.typeclasses.attributes import DbHolder
|
||||
from evennia.typeclasses.tags import Tag, TagHandler, AliasHandler, PermissionHandler
|
||||
from evennia.typeclasses.tags import Tag, TagHandler, AliasHandler, PermissionHandler, TagProperty
|
||||
|
||||
from evennia.utils.idmapper.models import SharedMemoryModel, SharedMemoryModelBase
|
||||
from evennia.server.signals import SIGNAL_TYPED_OBJECT_POST_RENAME
|
||||
|
|
@ -331,7 +332,7 @@ class TypedObject(SharedMemoryModel):
|
|||
by fetching them once.
|
||||
"""
|
||||
for propkey, prop in self.__class__.__dict__.items():
|
||||
if hasattr(prop, "__set_name__"):
|
||||
if isinstance(prop, (AttributeProperty, TagProperty)):
|
||||
try:
|
||||
getattr(self, propkey)
|
||||
except Exception:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue