@jsmnbom Alright I've made the changes you requested and fixed the 4 pytest failures and flake8 error. Two points to note though:
-
I am not sure if i named the arguments correctly (maybe
jobneeds to be changed to something else?), so let me know what should be changed. -
I didn't include
context=contextonhandler.handle_updatebecause it failed one of the tests. I have included the log below:
_____________________________________________________________________ TestConversationHandler.test_conversation_handler_timeout_state ______________________________________________________________________
self = <tests.test_conversationhandler.TestConversationHandler object at 0x10b635048>, dp = <telegram.ext.dispatcher.Dispatcher object at 0x10b5ed7b8>, bot = <telegram.bot.Bot object at 0x10afa4f98>
user1 = <telegram.user.User object at 0x10b5f0320>
def test_conversation_handler_timeout_state(self, dp, bot, user1):
states = self.states
states.update({ConversationHandler.TIMEOUT: [
CommandHandler('brew', self.passout),
MessageHandler(~Filters.regex('oding'), self.passout2)
]})
handler = ConversationHandler(entry_points=self.entry_points, states=states,
fallbacks=self.fallbacks, conversation_timeout=0.5)
dp.add_handler(handler)
# CommandHandler timeout
message = Message(0, user1, None, self.group, text='/start',
entities=[MessageEntity(type=MessageEntity.BOT_COMMAND, offset=0,
length=len('/start'))],
bot=bot)
dp.process_update(Update(update_id=0, message=message))
message.text = '/brew'
message.entities[0].length = len('/brew')
dp.process_update(Update(update_id=0, message=message))
sleep(0.5)
dp.job_queue.tick()
> assert handler.conversations.get((self.group.id, user1.id)) is None
E assert 1 is None
E + where 1 = <built-in method get of dict object at 0x10b67f4c8>((0, 123))
E + where <built-in method get of dict object at 0x10b67f4c8> = {(0, 123): 1}.get
E + where {(0, 123): 1} = <telegram.ext.conversationhandler.ConversationHandler object at 0x10b635b38>.conversations
tests/test_conversationhandler.py:531: AssertionError
-------------------------------------------------------------------------------------------- Captured log call ---------------------------------------------------------------------------------------------
jobqueue.py 264 ERROR An uncaught error was raised while executing job _trigger_timeout
Traceback (most recent call last):
File ".../python-telegram-bot/telegram/ext/jobqueue.py", line 260, in tick
job.run(self._dispatcher)
File ".../python-telegram-bot/telegram/ext/jobqueue.py", line 390, in run
self.callback(dispatcher.bot, self)
File ".../python-telegram-bot/telegram/ext/conversationhandler.py", line 368, in _trigger_timeout
handler.handle_update(context.update, context.dispatcher, check, context=context)
File ".../python-telegram-bot/telegram/ext/handler.py", line 117, in handle_update
return self.callback(update, context)
File ".../python-telegram-bot/tests/test_conversationhandler.py", line 100, in passout
assert update.message.text == '/brew'
AttributeError: '_ConversationTimeoutContext' object has no attribute 'message'