Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncModule tests #17

Open
nim65s opened this issue Oct 31, 2015 · 1 comment
Open

AsyncModule tests #17

nim65s opened this issue Oct 31, 2015 · 1 comment

Comments

@nim65s
Copy link
Member

nim65s commented Oct 31, 2015

Is there a way to write unit tests for AsyncModules ?

@sleduc
Copy link
Member

sleduc commented Oct 31, 2015

Not really sure how to do it in the master branch, but it is quite easy in the python3 branch : see commit 50b3b73

The idea is that the bot_jabber module used to manage answers to messages by creating a thread for each message.
With commit a7e16c0 I moved the thread management from bot_jabber to the parent class bot, so the bot_jabber and the bot_test behave the same way.

In test mode, there is an output attribute to the bot, which is a python Queue. Each message is written in the Queue, even if it is done in a Thread. So even if you use an async module, all you have to do is create your module, and then in your test, just call the get() method of the Queue to retrieve messages.
Since get() is blocking, it will wait for your AsyncModule to do call bot.say to be unlocked, and you can verify the content of the message, the delay, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants