Revamp _bad_recipe() helper function and fix @puzzle command empty name
This commit is contained in:
parent
8e7106806b
commit
434abe0aa6
3 changed files with 20 additions and 6 deletions
|
|
@ -118,6 +118,11 @@ class MuxCommand(Command):
|
||||||
lhs, rhs = [arg.strip() for arg in args.split('=', 1)]
|
lhs, rhs = [arg.strip() for arg in args.split('=', 1)]
|
||||||
lhslist = [arg.strip() for arg in lhs.split(',')]
|
lhslist = [arg.strip() for arg in lhs.split(',')]
|
||||||
rhslist = [arg.strip() for arg in rhs.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:
|
# save to object properties:
|
||||||
self.raw = raw
|
self.raw = raw
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,9 @@ class CmdCreatePuzzleRecipe(MuxCommand):
|
||||||
return
|
return
|
||||||
|
|
||||||
puzzle_name = self.lhslist[0]
|
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):
|
def is_valid_obj_location(obj):
|
||||||
valid = True
|
valid = True
|
||||||
|
|
|
||||||
|
|
@ -1233,8 +1233,8 @@ class TestPuzzles(CommandTest):
|
||||||
cmdstr,
|
cmdstr,
|
||||||
caller=self.char1
|
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)
|
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
|
return recipe_dbref
|
||||||
|
|
||||||
def _arm(self, recipe_dbref, name, parts):
|
def _arm(self, recipe_dbref, name, parts):
|
||||||
|
|
@ -1272,7 +1272,7 @@ class TestPuzzles(CommandTest):
|
||||||
_bad_syntax(',nothing')
|
_bad_syntax(',nothing')
|
||||||
_bad_syntax('name, nothing')
|
_bad_syntax('name, 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()
|
self._assert_no_recipes()
|
||||||
|
|
||||||
|
|
@ -1282,13 +1282,19 @@ class TestPuzzles(CommandTest):
|
||||||
|
|
||||||
# bad recipes
|
# bad recipes
|
||||||
def _bad_recipe(name, parts, results, fail_regex):
|
def _bad_recipe(name, parts, results, fail_regex):
|
||||||
with self.assertRaisesRegexp(AssertionError, fail_regex):
|
cmdstr = ','.join([name] + parts) \
|
||||||
self._good_recipe(name, parts, results)
|
+ '=' + ','.join(results)
|
||||||
self.assert_no_recipes()
|
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', ['nothing'], ['neither'], r"Could not find 'nothing'.")
|
||||||
_bad_recipe('name', ['stone'], ['nothing'], 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()
|
self._assert_no_recipes()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue