Upgrade the test suite mocks
NOTE
This issue is here because the work has already been done for my own project here, but enough changes have been made to the point where I think it may be useful for pydis to reap the benefits as well.
Description
Initially, I took the mocks for my own project, and added a few mocks that I needed, but while working through them, I noticed some shortcomings. Those shortcomings are addressed in the file change I made.
A short list of changes are as follows:
- add discord.Thread mock
- make mocks NonCallable mocks since you cannot call a message (or any) instance
- ensure mock returns return the correct type, eg channel.send() will return a MockMessage
The most important part of the changes is the final change. This uses the typing information provided by discord.py in order to mock all functions that are mockable to return the correct mock type when they are called. This means that message.create_thread() will return a MockThread, or channel.send() will return a MockMessage. This is all done by utilising the typing system, and the fact that the public api of dpy 2 is typed.
Original discussion here
I stumbled across this as I was looking for test suites. Just an idea... Would it make sense to extract those Mocks into a lib?
Yeah a discord.py mock library is a nice idea, but it's not something we're likely to pursue at the moment. Our approach to the mocks (and tests in general) is "good enough", but maintaining a high-quality library would require significantly more work, especially if we try to cover all of discord.py instead of just the parts we need.
Yes, true. That would require a lot more of work. Covering everything would be nice, yes.. but starting off small and, if someone needs a mock, adding it step by step would also work. I myself just started to dig into testing, so I can't really help in that way :/
I think it's fine to only extend our mocks as needed.