Include execute_cmd in if statement, and add test
This commit is contained in:
parent
1d746db2dd
commit
8501c478a2
2 changed files with 25 additions and 11 deletions
|
|
@ -2263,3 +2263,16 @@ class TestSystemCommands(BaseEvenniaCommandTest):
|
||||||
multimatch.matches = matches
|
multimatch.matches = matches
|
||||||
|
|
||||||
self.call(multimatch, "look", "")
|
self.call(multimatch, "look", "")
|
||||||
|
|
||||||
|
class TestPreCmdOutputTestable(BaseEvenniaCommandTest):
|
||||||
|
def test_pre_cmd(self):
|
||||||
|
class CmdTest(Command):
|
||||||
|
def at_pre_cmd(self):
|
||||||
|
self.msg("This should be testable")
|
||||||
|
return True
|
||||||
|
|
||||||
|
def func(self):
|
||||||
|
self.msg("This should never be executed")
|
||||||
|
return
|
||||||
|
|
||||||
|
self.call(CmdTest(), "test", "This should be testable")
|
||||||
|
|
@ -452,12 +452,13 @@ class EvenniaCommandTestMixin:
|
||||||
unmocked_msg_methods[receiver] = receiver.msg
|
unmocked_msg_methods[receiver] = receiver.msg
|
||||||
# replace normal `.msg` with a mock
|
# replace normal `.msg` with a mock
|
||||||
receiver.msg = Mock()
|
receiver.msg = Mock()
|
||||||
|
|
||||||
# Run the methods of the Command. This mimics what happens in the
|
# Run the methods of the Command. This mimics what happens in the
|
||||||
# cmdhandler. This will have the mocked .msg be called as part of the
|
# cmdhandler. This will have the mocked .msg be called as part of the
|
||||||
# execution. Mocks remembers what was sent to them so we will be able
|
# execution. Mocks remembers what was sent to them so we will be able
|
||||||
# to retrieve what was sent later.
|
# to retrieve what was sent later.
|
||||||
try:
|
if not cmdobj.at_pre_cmd():
|
||||||
if not cmdobj.at_pre_cmd():
|
try:
|
||||||
cmdobj.parse()
|
cmdobj.parse()
|
||||||
ret = cmdobj.func()
|
ret = cmdobj.func()
|
||||||
# handle func's with yield in them (making them generators)
|
# handle func's with yield in them (making them generators)
|
||||||
|
|
@ -480,16 +481,16 @@ class EvenniaCommandTestMixin:
|
||||||
break
|
break
|
||||||
|
|
||||||
cmdobj.at_post_cmd()
|
cmdobj.at_post_cmd()
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
except InterruptCommand:
|
except InterruptCommand:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for inp in inputs:
|
for inp in inputs:
|
||||||
# if there are any inputs left, we may have a non-generator
|
# if there are any inputs left, we may have a non-generator
|
||||||
# input to handle (get_input/ask_yes_no that uses a separate
|
# input to handle (get_input/ask_yes_no that uses a separate
|
||||||
# cmdset rather than a yield
|
# cmdset rather than a yield
|
||||||
caller.execute_cmd(inp)
|
caller.execute_cmd(inp)
|
||||||
|
|
||||||
# At this point the mocked .msg methods on each receiver will have
|
# At this point the mocked .msg methods on each receiver will have
|
||||||
# stored all calls made to them (that's a basic function of the Mock
|
# stored all calls made to them (that's a basic function of the Mock
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue