我想用单元测试来介绍on_text方法。我想用非unicode消息检查on_text,看看{}被调用了。在class MyTornadoClass(object):
@gen.coroutine
def on_text(self, message):
"""
User message controller
"""
id_ = message.message_id
chat = message.chat
text = message.text.strip().replace(" ", "-").replace("[()&?]", "")
if not self.is_ascii(text):
yield self.send_message(chat.id_, "Sorry, I didn't find anything according to you request. Try again!",
reply_to_message_id=id_)
else:
yield self.perform_search(text, id_, chat)
我的模拟测试是:
^{pr2}$
我收到例外:Traceback (most recent call last):
File "/home/sergei-rudenkov/PycharmProjects/python_tasks/bot_telegram/unit_tests/telezombie_api/starter_test.py", line 21, in test_app
1)
File "/usr/local/lib/python3.5/dist-packages/mock/mock.py", line 925, in assert_called_with
raise AssertionError('Expected call: %s\nNot called' % (expected,))
AssertionError: Expected call: send_message(227071993, "Sorry, I didn't find anything according to you request.\n Try again!", 1)
Not called
----------------------------------------------------------------------
Ran 1 test in 0.006s
FAILED (failures=1)
我不知道我做错了什么。请指出我的错误。在