Merge pull request #3834 from count-infinity/bug-3824-prototype-funcs
Fix Unexpected keyword argument 'prototype' error when spawning
This commit is contained in:
commit
7c38b1cc76
2 changed files with 43 additions and 2 deletions
|
|
@ -1078,6 +1078,47 @@ class TestIssue2908(BaseEvenniaTest):
|
||||||
self.assertEqual(obj[0].location, self.room1)
|
self.assertEqual(obj[0].location, self.room1)
|
||||||
|
|
||||||
|
|
||||||
|
class TestIssue3824(BaseEvenniaTest):
|
||||||
|
"""
|
||||||
|
Test that $obj, $objlist, $search, and $dbref callables work correctly when spawning prototypes.
|
||||||
|
|
||||||
|
Regression test for bug where 'prototype' kwarg was passed to search functions causing TypeError.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_spawn_with_search_callables(self):
|
||||||
|
"""Test spawning prototype with $obj, $objlist, $search, and $dbref callables."""
|
||||||
|
# Setup: tag some objects for searching
|
||||||
|
self.room1.tags.add("test_location", category="zone")
|
||||||
|
self.room2.tags.add("test_location", category="zone")
|
||||||
|
self.obj1.tags.add("test_item", category="item_type")
|
||||||
|
|
||||||
|
# Create prototype using all search callables
|
||||||
|
prot = {
|
||||||
|
"prototype_key": "test_search_callables",
|
||||||
|
"typeclass": "evennia.objects.objects.DefaultObject",
|
||||||
|
"key": "test object",
|
||||||
|
"attr_obj": f"$obj({self.obj1.dbref})",
|
||||||
|
"attr_search": "$search(Char)",
|
||||||
|
"attr_objlist": "$objlist(test_location, category=zone, type=tag)",
|
||||||
|
"attr_dbref": f"$dbref({self.obj1.dbref})",
|
||||||
|
}
|
||||||
|
|
||||||
|
# This should not raise TypeError about 'prototype' kwarg
|
||||||
|
objs = spawner.spawn(prot, caller=self.char1)
|
||||||
|
|
||||||
|
self.assertEqual(len(objs), 1)
|
||||||
|
obj = objs[0]
|
||||||
|
|
||||||
|
# Verify all search callables worked correctly
|
||||||
|
self.assertEqual(obj.db.attr_obj, self.obj1)
|
||||||
|
self.assertEqual(obj.db.attr_search, self.char1)
|
||||||
|
self.assertEqual(obj.db.attr_dbref, self.obj1)
|
||||||
|
# attr_objlist should be a list or list-like object with 2 rooms
|
||||||
|
objlist = obj.db.attr_objlist
|
||||||
|
self.assertEqual(len(objlist), 2)
|
||||||
|
self.assertIn(self.room1, objlist)
|
||||||
|
self.assertIn(self.room2, objlist)
|
||||||
|
|
||||||
class TestIssue3101(EvenniaCommandTest):
|
class TestIssue3101(EvenniaCommandTest):
|
||||||
"""
|
"""
|
||||||
Spawning and using create_object should store the same `typeclass_path` if using
|
Spawning and using create_object should store the same `typeclass_path` if using
|
||||||
|
|
|
||||||
|
|
@ -1131,12 +1131,12 @@ def funcparser_callable_search(*args, caller=None, access="control", **kwargs):
|
||||||
- "$search(beach, category=outdoors, type=tag)
|
- "$search(beach, category=outdoors, type=tag)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# clean out funcparser-specific kwargs so we can use the kwargs for
|
# clean out funcparser and protfunc_parser-specific kwargs so we can use the kwargs for
|
||||||
# searching
|
# searching
|
||||||
search_kwargs = {
|
search_kwargs = {
|
||||||
key: value
|
key: value
|
||||||
for key, value in kwargs.items()
|
for key, value in kwargs.items()
|
||||||
if key not in ("funcparser", "raise_errors", "type", "return_list")
|
if key not in ("funcparser", "raise_errors", "type", "return_list", "prototype")
|
||||||
}
|
}
|
||||||
return_list = str(kwargs.pop("return_list", "false")).lower() == "true"
|
return_list = str(kwargs.pop("return_list", "false")).lower() == "true"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue