Merge branch '2620-fix-prototype-loading' of https://github.com/ChrisLR/evennia into ChrisLR-2620-fix-prototype-loading

This commit is contained in:
Griatch 2022-01-19 21:58:25 +01:00
commit ad06d97d5b
5 changed files with 16 additions and 9 deletions

View file

@ -1405,6 +1405,7 @@ class TestBuilding(EvenniaCommandTest):
"Could not find 'Obj'.| (Objects to destroy "
"must either be local or specified with a unique #dbref.)",
)
settings.DEFAULT_HOME = f"#{self.room1.dbid}"
self.call(
building.CmdDestroy(), settings.DEFAULT_HOME, "You are trying to delete"
) # DEFAULT_HOME should not be deleted

View file

@ -654,7 +654,7 @@ class TestCraftSword(BaseEvenniaTestCase):
@mock.patch("evennia.contrib.game_systems.crafting.crafting._load_recipes", new=mock.MagicMock())
@mock.patch("evennia.contrib.game_systems.crafting.crafting._RECIPE_CLASSES", new={"testrecipe": _MockRecipe})
@override_settings(CRAFT_RECIPE_MODULES=[], DEFAULT_HOME="#999999")
@override_settings(CRAFT_RECIPE_MODULES=[])
class TestCraftCommand(EvenniaCommandTest):
"""Test the crafting command"""

View file

@ -676,15 +676,19 @@ class ObjectDBManager(TypedObjectManager):
location = dbid_to_obj(location, self.model)
destination = dbid_to_obj(destination, self.model)
home = dbid_to_obj(home, self.model)
if not home:
if home:
home = dbid_to_obj(home, self.model)
if not nohome and not home:
try:
home = dbid_to_obj(settings.DEFAULT_HOME, self.model) if not nohome else None
except self.model_ObjectDB.DoesNotExist:
home = dbid_to_obj(settings.DEFAULT_HOME, self.model)
except self.model.DoesNotExist:
raise self.model.DoesNotExist(
"settings.DEFAULT_HOME (= '%s') does not exist, or the setting is malformed."
% settings.DEFAULT_HOME
)
elif nohome and not home:
home = None
# create new instance
new_object = typeclass(

View file

@ -31,7 +31,6 @@ from evennia.utils.funcparser import FuncParser
from evennia.utils import dbserialize
from evennia.utils.evtable import EvTable
_MODULE_PROTOTYPE_MODULES = {}
_MODULE_PROTOTYPES = {}
_PROTOTYPE_META_NAMES = (
@ -516,6 +515,10 @@ def search_prototype(key=None, tags=None, require_single=False, return_iterators
be found as a match.
"""
# This will load the prototypes the first time they are searched
if not _MODULE_PROTOTYPE_MODULES:
load_module_prototypes()
# prototype keys are always in lowecase
if key:
key = key.lower()

View file

@ -152,13 +152,12 @@ class EvenniaTestMixin:
if hasattr(self, "account2"):
self.account2.delete()
# Set up fake prototype module for allowing tests to use named prototypes.
@override_settings(PROTOTYPE_MODULES=["evennia.utils.tests.data.prototypes_example"], DEFAULT_HOME="#1")
def create_rooms(self):
self.room1 = create.create_object(self.room_typeclass, key="Room", nohome=True)
self.room1.db.desc = "room_desc"
settings.DEFAULT_HOME = "#%i" % self.room1.id # we must have a default home
# Set up fake prototype module for allowing tests to use named prototypes.
settings.PROTOTYPE_MODULES = "evennia.utils.tests.data.prototypes_example"
self.room2 = create.create_object(self.room_typeclass, key="Room2")
self.exit = create.create_object(
self.exit_typeclass, key="out", location=self.room1, destination=self.room2