From 4946b0f65d56da15f13604f29921c0daebb6efc7 Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Thu, 18 Oct 2018 17:52:25 -0500 Subject: [PATCH 1/9] Tests for @spawn/edit and @spawn/examine --- evennia/commands/default/tests.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index a3be98984a..cbae47866d 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -372,6 +372,17 @@ class TestBuilding(CommandTest): self.call(building.CmdSpawn(), \ "'NO_EXIST'", "No prototype named 'NO_EXIST'") + # @span/edit + self.call( + building.CmdSpawn(), + '/edit', + 'spawn: Extra switch "/edit" ignored') + + # @span/examine + self.call( + '/examine', + building.CmdSpawn(), 'spawn: Extra switch "/examine" ignored') + class TestComms(CommandTest): @@ -446,4 +457,4 @@ class TestUnconnectedCommand(CommandTest): settings.SERVERNAME, datetime.datetime.fromtimestamp(gametime.SERVER_START_TIME).ctime(), SESSIONS.account_count(), utils.get_evennia_version()) - self.call(unloggedin.CmdUnconnectedInfo(), "", expected) \ No newline at end of file + self.call(unloggedin.CmdUnconnectedInfo(), "", expected) From ca81d35e1c5f5ff84c2b7a6c9d82651e8ca7f96c Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Fri, 19 Oct 2018 18:44:45 -0500 Subject: [PATCH 2/9] Baseline tests: assert current behavior (disregarding requirements) --- evennia/commands/default/tests.py | 36 +++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 691e1e63cb..be47a06aac 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -460,16 +460,44 @@ class TestBuilding(CommandTest): # Test listing commands self.call(building.CmdSpawn(), "/list", "Key ") - # @span/edit + # @span/edit (missing prototype) self.call( building.CmdSpawn(), '/edit', - 'spawn: Extra switch "/edit" ignored') + '@spawn: Extra switch "/edit" ignored.|Usage: @spawn or {key: value, ...}\n (2 existing prototypes. Use /list to inspect)') + # assert 'Prototype wizard' in msg - # @span/examine + # @spawn/edit with valid prototype + # with self.assertRaises(AttributeError): self.call( + building.CmdSpawn(), + '/edit BALL', + '@spawn: Extra switch "/edit" ignored.|Spawned Ball(#13).') + + # @spawn/edit with invalid prototype + #`with self.assertRaises(AttributeError): + self.call( + building.CmdSpawn(), + '/edit NO_EXISTS', + '@spawn: Extra switch "/edit" ignored.|No prototype named \'NO_EXISTS\'.') + + # @spawn/examine (missing prototype) + self.call( + building.CmdSpawn(), '/examine', - building.CmdSpawn(), 'spawn: Extra switch "/examine" ignored') + '@spawn: Extra switch "/examine" ignored.|Usage: @spawn or {key: value, ...}\n (2 existing prototypes. Use /list to inspect)') + + # @spawn/examine with valid prototype + self.call( + building.CmdSpawn(), + '/examine BALL', + '@spawn: Extra switch "/examine" ignored.|Spawned Ball(#14).') + + # @spawn/examine with invalid prototype + self.call( + building.CmdSpawn(), + '/examine NO_EXISTS', + '@spawn: Extra switch "/examine" ignored.|No prototype named \'NO_EXISTS\'.') class TestComms(CommandTest): From d3ddeda7c9e13fc1e79adf47966c18016188fbe7 Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Fri, 19 Oct 2018 19:01:27 -0500 Subject: [PATCH 3/9] @spawn/edit is equivalent to @spawn/olc and @olc --- evennia/commands/default/building.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index f0ae108f00..ad613609ba 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -2856,7 +2856,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): key = "@spawn" aliases = ["olc"] - switch_options = ("noloc", "search", "list", "show", "save", "delete", "menu", "olc", "update") + switch_options = ("noloc", "search", "list", "show", "save", "delete", "menu", "olc", "update", "edit") locks = "cmd:perm(spawn) or perm(Builder)" help_category = "Building" @@ -2907,7 +2907,8 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): caller = self.caller - if self.cmdstring == "olc" or 'menu' in self.switches or 'olc' in self.switches: + if self.cmdstring == "olc" or 'menu' in self.switches \ + or 'olc' in self.switches or 'edit' in self.switches: # OLC menu mode prototype = None if self.lhs: From ff6deb90c1bd2cc0087d2012b72364db6a827789 Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Fri, 19 Oct 2018 19:16:02 -0500 Subject: [PATCH 4/9] Modify tests so they pass. Some new tests throw exceptions --- evennia/commands/default/tests.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index be47a06aac..0007a84e07 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -461,25 +461,25 @@ class TestBuilding(CommandTest): self.call(building.CmdSpawn(), "/list", "Key ") # @span/edit (missing prototype) - self.call( + msg = self.call( building.CmdSpawn(), - '/edit', - '@spawn: Extra switch "/edit" ignored.|Usage: @spawn or {key: value, ...}\n (2 existing prototypes. Use /list to inspect)') - # assert 'Prototype wizard' in msg + '/edit') + # '@spawn: Extra switch "/edit" ignored.|Usage: @spawn or {key: value, ...}\n (2 existing prototypes. Use /list to inspect)') + assert 'Prototype wizard' in msg # @spawn/edit with valid prototype - # with self.assertRaises(AttributeError): - self.call( - building.CmdSpawn(), - '/edit BALL', - '@spawn: Extra switch "/edit" ignored.|Spawned Ball(#13).') + with self.assertRaises(AttributeError): + self.call( + building.CmdSpawn(), + '/edit BALL', + '@spawn: Extra switch "/edit" ignored.|Spawned Ball(#13).') # @spawn/edit with invalid prototype - #`with self.assertRaises(AttributeError): - self.call( - building.CmdSpawn(), - '/edit NO_EXISTS', - '@spawn: Extra switch "/edit" ignored.|No prototype named \'NO_EXISTS\'.') + with self.assertRaises(AttributeError): + self.call( + building.CmdSpawn(), + '/edit NO_EXISTS', + '@spawn: Extra switch "/edit" ignored.|No prototype named \'NO_EXISTS\'.') # @spawn/examine (missing prototype) self.call( @@ -491,7 +491,8 @@ class TestBuilding(CommandTest): self.call( building.CmdSpawn(), '/examine BALL', - '@spawn: Extra switch "/examine" ignored.|Spawned Ball(#14).') + # '@spawn: Extra switch "/examine" ignored.|Spawned Ball(#14).') + '@spawn: Extra switch "/examine" ignored.|Spawned Ball(#13).') # @spawn/examine with invalid prototype self.call( From 931290a7a0a8710afd8128b7962996efb2c21b12 Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Sat, 20 Oct 2018 20:11:41 -0500 Subject: [PATCH 5/9] Handle '@spawn/edit ' (no prototype key given) brings OLC menu. Handle '@spawn/edit testball' brings OLC menu. Handle '@spawn/edit NO_EXISTS' that returns error --- evennia/commands/default/building.py | 6 +++++- evennia/commands/default/tests.py | 27 +++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index ed6f6d273f..65fedaf5c2 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -2913,7 +2913,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): prototype = None if self.lhs: key = self.lhs - prototype = spawner.search_prototype(key=key, return_meta=True) + prototype = protlib.search_prototype(key=key) if len(prototype) > 1: caller.msg("More than one match for {}:\n{}".format( key, "\n".join(proto.get('prototype_key', '') for proto in prototype))) @@ -2921,6 +2921,10 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): elif prototype: # one match prototype = prototype[0] + else: + # no match + caller.msg("No prototype '{}' was found.".format(key)) + return olc_menus.start_olc(caller, session=self.session, prototype=prototype) return diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 59fdc7db69..1cbb81b090 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -479,25 +479,28 @@ class TestBuilding(CommandTest): self.call(building.CmdSpawn(), "/list", "Key ") # @span/edit (missing prototype) + # brings up olc menu msg = self.call( building.CmdSpawn(), '/edit') - # '@spawn: Extra switch "/edit" ignored.|Usage: @spawn or {key: value, ...}\n (2 existing prototypes. Use /list to inspect)') - assert 'Prototype wizard' in msg + assert msg.startswith('______________________________________________________________________________\n\n --- Prototype wizard --- \n\n') # @spawn/edit with valid prototype - with self.assertRaises(AttributeError): - self.call( - building.CmdSpawn(), - '/edit BALL', - '@spawn: Extra switch "/edit" ignored.|Spawned Ball(#13).') + self.call( + building.CmdSpawn(), + '/edit testball') + # TODO: OLC menu comes up but it gives no + # indication of testball prototype being + # edited ... Is this correct? + # On top of OCL being shown, msg is preceded + # by Room(#1)... + assert 'Prototype wizard' in msg # @spawn/edit with invalid prototype - with self.assertRaises(AttributeError): - self.call( - building.CmdSpawn(), - '/edit NO_EXISTS', - '@spawn: Extra switch "/edit" ignored.|No prototype named \'NO_EXISTS\'.') + msg = self.call( + building.CmdSpawn(), + '/edit NO_EXISTS', + "No prototype 'NO_EXISTS' was found.") # @spawn/examine (missing prototype) self.call( From 9f26d4b728d1cc98e71f3207a429bdb5245c5f94 Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Sat, 20 Oct 2018 20:12:55 -0500 Subject: [PATCH 6/9] code cleanup --- evennia/commands/default/tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 1cbb81b090..d8657a7113 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -512,7 +512,6 @@ class TestBuilding(CommandTest): self.call( building.CmdSpawn(), '/examine BALL', - # '@spawn: Extra switch "/examine" ignored.|Spawned Ball(#14).') '@spawn: Extra switch "/examine" ignored.|Spawned Ball(#13).') # @spawn/examine with invalid prototype From f70fa467f5d0845ef0cf9e413413d06eb70f23b4 Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Sat, 20 Oct 2018 20:22:11 -0500 Subject: [PATCH 7/9] Test @spawn/edit BALL (synonym) --- evennia/commands/default/tests.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index d8657a7113..8dce5ccc46 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -486,7 +486,7 @@ class TestBuilding(CommandTest): assert msg.startswith('______________________________________________________________________________\n\n --- Prototype wizard --- \n\n') # @spawn/edit with valid prototype - self.call( + msg = self.call( building.CmdSpawn(), '/edit testball') # TODO: OLC menu comes up but it gives no @@ -496,6 +496,12 @@ class TestBuilding(CommandTest): # by Room(#1)... assert 'Prototype wizard' in msg + # @spawn/edit with valid prototype (synomym) + msg = self.call( + building.CmdSpawn(), + '/edit BALL') + assert 'Prototype wizard' in msg + # @spawn/edit with invalid prototype msg = self.call( building.CmdSpawn(), From 1cbbdf5410e82309669edfa9eaf42cc3f07ecbcd Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Sun, 21 Oct 2018 13:43:36 -0500 Subject: [PATCH 8/9] Harden test '@spawn/edit ' by asserting that olc_menu has been loaded with valid-prototype.UX Enhancement to OLC menu. Underneath the title, display 'Editing: key(prototype_key)' of the prototype being edited. If none, show blank line --- evennia/commands/default/tests.py | 20 +++++++++++++------- evennia/prototypes/menus.py | 12 ++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 8dce5ccc46..f285cc9614 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -478,29 +478,33 @@ class TestBuilding(CommandTest): # Test listing commands self.call(building.CmdSpawn(), "/list", "Key ") - # @span/edit (missing prototype) + # @spawn/edit (missing prototype) # brings up olc menu msg = self.call( building.CmdSpawn(), '/edit') - assert msg.startswith('______________________________________________________________________________\n\n --- Prototype wizard --- \n\n') + assert 'Prototype wizard' in msg # @spawn/edit with valid prototype + # brings up olc menu loaded with prototype msg = self.call( building.CmdSpawn(), '/edit testball') - # TODO: OLC menu comes up but it gives no - # indication of testball prototype being - # edited ... Is this correct? - # On top of OCL being shown, msg is preceded - # by Room(#1)... assert 'Prototype wizard' in msg + assert hasattr(self.char1.ndb._menutree, "olc_prototype") + assert dict == type(self.char1.ndb._menutree.olc_prototype) \ + and 'prototype_key' in self.char1.ndb._menutree.olc_prototype \ + and 'key' in self.char1.ndb._menutree.olc_prototype \ + and 'testball' == self.char1.ndb._menutree.olc_prototype['prototype_key'] \ + and 'Ball' == self.char1.ndb._menutree.olc_prototype['key'] + assert 'Ball' in msg and 'testball' in msg # @spawn/edit with valid prototype (synomym) msg = self.call( building.CmdSpawn(), '/edit BALL') assert 'Prototype wizard' in msg + assert 'Ball' in msg and 'testball' in msg # @spawn/edit with invalid prototype msg = self.call( @@ -518,6 +522,8 @@ class TestBuilding(CommandTest): self.call( building.CmdSpawn(), '/examine BALL', + # FIXME: should this print the existing prototype + # instead of spawning it? '@spawn: Extra switch "/examine" ignored.|Spawned Ball(#13).') # @spawn/examine with invalid prototype diff --git a/evennia/prototypes/menus.py b/evennia/prototypes/menus.py index 9605ea1a8f..c10f32429f 100644 --- a/evennia/prototypes/menus.py +++ b/evennia/prototypes/menus.py @@ -562,6 +562,7 @@ def node_index(caller): text = """ |c --- Prototype wizard --- |n + %s A |cprototype|n is a 'template' for |wspawning|n an in-game entity. A field of the prototype can either be hard-coded, left empty or scripted using |w$protfuncs|n - for example to @@ -599,6 +600,17 @@ def node_index(caller): {pfuncs} """.format(pfuncs=_format_protfuncs()) + # If a prototype is being edited, show its key and + # prototype_key under the title + loaded_prototype = '' + if 'prototype_key' in prototype \ + or 'key' in prototype: + loaded_prototype = ' --- Editing: |y{}({})|n --- '.format( + prototype.get('key', ''), + prototype.get('prototype_key', '') + ) + text = text % (loaded_prototype) + text = (text, helptxt) options = [] From e956bcf3be4c9a6cae51b01c4f04e4e9f8dbe31b Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Sun, 21 Oct 2018 14:15:34 -0500 Subject: [PATCH 9/9] Add 'examine' as valid switch alias for 'show' with its corresponding tests --- evennia/commands/default/building.py | 2 +- evennia/commands/default/tests.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index 65fedaf5c2..503a9c15e9 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -2856,7 +2856,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): key = "@spawn" aliases = ["olc"] - switch_options = ("noloc", "search", "list", "show", "save", "delete", "menu", "olc", "update", "edit") + switch_options = ("noloc", "search", "list", "show", "examine", "save", "delete", "menu", "olc", "update", "edit") locks = "cmd:perm(spawn) or perm(Builder)" help_category = "Building" diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index f285cc9614..7b2c78951b 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -513,24 +513,25 @@ class TestBuilding(CommandTest): "No prototype 'NO_EXISTS' was found.") # @spawn/examine (missing prototype) - self.call( + # lists all prototypes that exist + msg = self.call( building.CmdSpawn(), - '/examine', - '@spawn: Extra switch "/examine" ignored.|Usage: @spawn or {key: value, ...}\n (2 existing prototypes. Use /list to inspect)') + '/examine') + assert 'testball' in msg and 'testprot' in msg # @spawn/examine with valid prototype - self.call( + # prints the prototype + msg = self.call( building.CmdSpawn(), - '/examine BALL', - # FIXME: should this print the existing prototype - # instead of spawning it? - '@spawn: Extra switch "/examine" ignored.|Spawned Ball(#13).') + '/examine BALL') + assert 'Ball' in msg and 'testball' in msg # @spawn/examine with invalid prototype + # shows error self.call( building.CmdSpawn(), '/examine NO_EXISTS', - '@spawn: Extra switch "/examine" ignored.|No prototype named \'NO_EXISTS\'.') + "No prototype 'NO_EXISTS' was found.") class TestComms(CommandTest):