Fix prototype attr-inheritance with mixed full/simple attrs. Resolve #2474.

This commit is contained in:
Griatch 2021-07-26 23:42:35 +02:00
parent e4efd7080b
commit 0129786c3d
2 changed files with 41 additions and 2 deletions

View file

@ -892,7 +892,7 @@ def spawn(*prototypes, caller=None, **kwargs):
for key, protparent in kwargs.get("prototype_parents", {}).items():
key = str(key).lower()
protparent["prototype_key"] = str(protparent.get("prototype_key", key)).lower()
protparents[key] = protparent
protparents[key] = protlib.homogenize_prototype(protparent)
if "return_parents" in kwargs:
# only return the parents

View file

@ -45,7 +45,6 @@ _PROTPARENTS = {
},
}
class TestSpawner(EvenniaTest):
def setUp(self):
super(TestSpawner, self).setUp()
@ -898,3 +897,43 @@ class PrototypeCrashTest(EvenniaTest):
# start_time = time()
self.char1.execute_cmd("spawn/list")
# print(f"Prototypes listed in {time()-start_time} seconds.")
class Test2474(EvenniaTest):
"""
Test bug #2474 (https://github.com/evennia/evennia/issues/2474),
where the prototype's attribute fails to take precedence over
that of its prototype_parent.
"""
prototypes = {
"WEAPON": {
"typeclass": "evennia.objects.objects.DefaultObject",
"key": "Weapon",
"desc": "A generic blade.",
"magic": False,
},
"STING": {
"prototype_parent": "WEAPON",
"key": "Sting",
"desc": "A dagger that shines with a cold light if Orcs are near.",
"magic": True,
},
}
def test_magic_spawn(self):
"""
Test magic is inherited.
"""
sting = spawner.spawn(self.prototypes["STING"], prototype_parents=self.prototypes)[0]
self.assertEqual(sting.db.magic, True)
def test_non_magic_spawn(self):
"""
Test inverse - no magic.
"""
sting = spawner.spawn(self.prototypes["WEAPON"], prototype_parents=self.prototypes)[0]
self.assertEqual(sting.db.magic, False)