From 2ec97f102d21fe4552055882fab56ca55e2345ed Mon Sep 17 00:00:00 2001 From: Chiizujin Date: Fri, 29 Mar 2024 20:40:46 +1100 Subject: [PATCH] Fix aliases not being shown for disambiguation in utils.at_search_result() Also correct misplaced 'if' used to avoid '[]' in the case of no aliases and update unit tests. --- evennia/contrib/rpg/rpsystem/tests.py | 16 +++++++++++++--- evennia/utils/utils.py | 6 +++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/evennia/contrib/rpg/rpsystem/tests.py b/evennia/contrib/rpg/rpsystem/tests.py index 155af26672..04d4ef49de 100644 --- a/evennia/contrib/rpg/rpsystem/tests.py +++ b/evennia/contrib/rpg/rpsystem/tests.py @@ -6,6 +6,7 @@ import time from anything import Anything from evennia import DefaultObject, create_object, default_cmds +from evennia.commands.default import building from evennia.commands.default.tests import BaseEvenniaCommandTest from evennia.utils.test_resources import BaseEvenniaTest @@ -413,10 +414,9 @@ class TestRPSystemCommands(BaseEvenniaCommandTest): expected_first_call = [ "More than one match for 'Mushroom' (please narrow target):", - f" Mushroom-1 []", - f" Mushroom-2 []", + f" Mushroom-1", + f" Mushroom-2", ] - self.call(default_cmds.CmdLook(), "Mushroom", "\n".join(expected_first_call)) # PASSES expected_second_call = f"Mushroom(#{mushroom1.id})\nThe first mushroom is brown." @@ -424,3 +424,13 @@ class TestRPSystemCommands(BaseEvenniaCommandTest): expected_third_call = f"Mushroom(#{mushroom2.id})\nThe second mushroom is red." self.call(default_cmds.CmdLook(), "Mushroom-2", expected_third_call) # FAILS + + expected_fourth_call = "Alias(es) for 'Mushroom' set to 'fungus'." + self.call(building.CmdSetObjAlias(), "Mushroom-1 = fungus", expected_fourth_call) #PASSES + + expected_fifth_call = [ + "More than one match for 'Mushroom' (please narrow target):", + f" Mushroom-1 [fungus]", + f" Mushroom-2", + ] + self.call(default_cmds.CmdLook(), "Mushroom", "\n".join(expected_fifth_call)) # PASSES diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index a3e3633a94..6748d606f7 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -2403,9 +2403,9 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs): aliases = result.aliases.all(return_objs=True) # remove pluralization aliases aliases = [ - alias + alias.db_key for alias in aliases - if hasattr(alias, "category") and alias.category not in ("plural_key",) + if alias.db_category != "plural_key" ] else: # result is likely a Command, where `.aliases` is a list of strings. @@ -2416,7 +2416,7 @@ def at_search_result(matches, caller, query="", quiet=False, **kwargs): name=result.get_display_name(caller) if hasattr(result, "get_display_name") else query, - aliases=" [{alias}]".format(alias=";".join(aliases) if aliases else ""), + aliases=" [{alias}]".format(alias=";".join(aliases)) if aliases else "", info=result.get_extra_info(caller), ) matches = None