From a6940fca90b05aeff4a385db0103094135c8be15 Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 24 Feb 2020 08:32:49 +0100 Subject: [PATCH] Add unittest for typeclass/prototype, some cleanup --- evennia/commands/default/building.py | 12 ++++-------- evennia/commands/default/tests.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index bbbfe42b7f..44a9350c52 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -1913,8 +1913,8 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS): Usage: typeclass[/switch] [= typeclass.path] - type '' - parent '' + typeclass/prototype = prototype_key + typeclass/list/show [typeclass.path] swap - this is a shorthand for using /force/reset flags. 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 += "\nAre you sure you want to apply these changes [yes]/no?" answer = yield (prompt) - answer = "yes" if answer == "" else answer - if answer and answer not in ("yes", "y", "no", "n"): + if answer and answer in ("no", "n"): caller.msg( - "Canceled: Either accept the default by pressing return or specify yes/no." + "Canceled: No changes were applied." ) return - elif answer.strip().lower() in ("n", "no"): - caller.msg("Canceled: No object was modified.") - return # we let this raise exception if needed obj.swap_typeclass( diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index a250166530..0dd76f8d6f 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -991,6 +991,27 @@ class TestBuilding(CommandTest): "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): self.call(building.CmdLock(), "", "Usage: ") self.call(building.CmdLock(), "Obj = test:all()", "Added lock 'test:all()' to Obj.")