From 8312d246009a535d971efacdf774d9562b2fca96 Mon Sep 17 00:00:00 2001 From: Henddher Pedroza Date: Thu, 13 Sep 2018 20:00:50 -0500 Subject: [PATCH] Revamp _bad_recipe() helper function and fix @puzzle command empty name --- evennia/commands/default/muxcommand.py | 5 +++++ evennia/contrib/puzzles.py | 3 +++ evennia/contrib/tests.py | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/evennia/commands/default/muxcommand.py b/evennia/commands/default/muxcommand.py index 5d8d4b2890..d2d2c65986 100644 --- a/evennia/commands/default/muxcommand.py +++ b/evennia/commands/default/muxcommand.py @@ -118,6 +118,11 @@ class MuxCommand(Command): lhs, rhs = [arg.strip() for arg in args.split('=', 1)] lhslist = [arg.strip() for arg in lhs.split(',')] rhslist = [arg.strip() for arg in rhs.split(',')] + # eliminate all empty-strings + # if len(lhslist) > 0: + # lhslist = list(filter(lambda i: len(i) > 0, lhslist)) + # if len(rhslist) > 0: + # rhslist = list(filter(lambda i: len(i) > 0, rhslist)) # save to object properties: self.raw = raw diff --git a/evennia/contrib/puzzles.py b/evennia/contrib/puzzles.py index 0a2a4cb447..9fd71d4ed9 100644 --- a/evennia/contrib/puzzles.py +++ b/evennia/contrib/puzzles.py @@ -167,6 +167,9 @@ class CmdCreatePuzzleRecipe(MuxCommand): return puzzle_name = self.lhslist[0] + if len(puzzle_name) == 0: + caller.msg('Invalid puzzle name %r.' % puzzle_name) + return def is_valid_obj_location(obj): valid = True diff --git a/evennia/contrib/tests.py b/evennia/contrib/tests.py index c85180efee..7adf8b9dcf 100644 --- a/evennia/contrib/tests.py +++ b/evennia/contrib/tests.py @@ -1233,8 +1233,8 @@ class TestPuzzles(CommandTest): cmdstr, caller=self.char1 ) - matches = self._assert_msg_matched(msg, regexs, re_flags=re.MULTILINE | re.DOTALL) recipe_dbref = self._assert_recipe(name, parts, results, and_destroy_it) + matches = self._assert_msg_matched(msg, regexs, re_flags=re.MULTILINE | re.DOTALL) return recipe_dbref def _arm(self, recipe_dbref, name, parts): @@ -1272,7 +1272,7 @@ class TestPuzzles(CommandTest): _bad_syntax(',nothing') _bad_syntax('name, nothing') _bad_syntax('name, nothing =') - # _bad_syntax(', = ,') # FIXME: got: Could not find ''. + # _bad_syntax(', = ,') # FIXME: MuxCommand issue? self._assert_no_recipes() @@ -1282,13 +1282,19 @@ class TestPuzzles(CommandTest): # bad recipes def _bad_recipe(name, parts, results, fail_regex): - with self.assertRaisesRegexp(AssertionError, fail_regex): - self._good_recipe(name, parts, results) - self.assert_no_recipes() + cmdstr = ','.join([name] + parts) \ + + '=' + ','.join(results) + msg = self.call( + puzzles.CmdCreatePuzzleRecipe(), + cmdstr, + caller=self.char1 + ) + self._assert_no_recipes() + self.assertIsNotNone(re.match(fail_regex, msg), msg) _bad_recipe('name', ['nothing'], ['neither'], r"Could not find 'nothing'.") _bad_recipe('name', ['stone'], ['nothing'], r"Could not find 'nothing'.") - # _bad_recipe('', ['stone', 'fire'], ['stone', 'fire'], '') # FIXME: no name becomes '' #N(#N) + _bad_recipe('', ['stone', 'fire'], ['stone', 'fire'], r"^Invalid puzzle name ''.") self._assert_no_recipes()