Add unittest for typeclass/prototype, some cleanup
This commit is contained in:
parent
9743275f80
commit
2d3f28822b
2 changed files with 25 additions and 8 deletions
|
|
@ -1913,8 +1913,8 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
typeclass[/switch] <object> [= typeclass.path]
|
typeclass[/switch] <object> [= typeclass.path]
|
||||||
type ''
|
typeclass/prototype <object> = prototype_key
|
||||||
parent ''
|
|
||||||
typeclass/list/show [typeclass.path]
|
typeclass/list/show [typeclass.path]
|
||||||
swap - this is a shorthand for using /force/reset flags.
|
swap - this is a shorthand for using /force/reset flags.
|
||||||
update - this is a shorthand for using the /force/reload flag.
|
update - this is a shorthand for using the /force/reload flag.
|
||||||
|
|
@ -2110,15 +2110,11 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
|
||||||
prompt += "\n|yWARNING:|n Use the /reset switch to apply the prototype over a blank state."
|
prompt += "\n|yWARNING:|n Use the /reset switch to apply the prototype over a blank state."
|
||||||
prompt += "\nAre you sure you want to apply these changes [yes]/no?"
|
prompt += "\nAre you sure you want to apply these changes [yes]/no?"
|
||||||
answer = yield (prompt)
|
answer = yield (prompt)
|
||||||
answer = "yes" if answer == "" else answer
|
if answer and answer in ("no", "n"):
|
||||||
if answer and answer not in ("yes", "y", "no", "n"):
|
|
||||||
caller.msg(
|
caller.msg(
|
||||||
"Canceled: Either accept the default by pressing return or specify yes/no."
|
"Canceled: No changes were applied."
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
elif answer.strip().lower() in ("n", "no"):
|
|
||||||
caller.msg("Canceled: No object was modified.")
|
|
||||||
return
|
|
||||||
|
|
||||||
# we let this raise exception if needed
|
# we let this raise exception if needed
|
||||||
obj.swap_typeclass(
|
obj.swap_typeclass(
|
||||||
|
|
|
||||||
|
|
@ -991,6 +991,27 @@ class TestBuilding(CommandTest):
|
||||||
"All object creation hooks were run. All old attributes where deleted before the swap.",
|
"All object creation hooks were run. All old attributes where deleted before the swap.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from evennia.prototypes.prototypes import homogenize_prototype
|
||||||
|
test_prototype = [homogenize_prototype(
|
||||||
|
{"prototype_key": "testkey",
|
||||||
|
"prototype_tags": [],
|
||||||
|
"typeclass": "typeclasses.objects.Object",
|
||||||
|
"key":"replaced_obj",
|
||||||
|
"attrs": [("foo", "bar", None, ""),
|
||||||
|
("desc", "protdesc", None, "")]})]
|
||||||
|
with mock.patch("evennia.commands.default.building.protlib.search_prototype",
|
||||||
|
new=mock.MagicMock(return_value=test_prototype)) as mprot:
|
||||||
|
self.call(
|
||||||
|
building.CmdTypeclass(),
|
||||||
|
"/prototype Obj=testkey",
|
||||||
|
"replaced_obj changed typeclass from "
|
||||||
|
"evennia.objects.objects.DefaultObject to "
|
||||||
|
"typeclasses.objects.Object.\nAll object creation hooks were "
|
||||||
|
"run. Attributes set before swap were not removed. Prototype "
|
||||||
|
"'replaced_obj' was successfully applied over the object type."
|
||||||
|
)
|
||||||
|
assert self.obj1.db.desc == "protdesc"
|
||||||
|
|
||||||
def test_lock(self):
|
def test_lock(self):
|
||||||
self.call(building.CmdLock(), "", "Usage: ")
|
self.call(building.CmdLock(), "", "Usage: ")
|
||||||
self.call(building.CmdLock(), "Obj = test:all()", "Added lock 'test:all()' to Obj.")
|
self.call(building.CmdLock(), "Obj = test:all()", "Added lock 'test:all()' to Obj.")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue