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
Add mouse.set_cursor unit test #1967
Add mouse.set_cursor unit test #1967
Conversation
First of all thank you for your first contribution 🎉. You wrote really good tests that covers everything that should be covered. About MemoryError I don't think we check that anywhere (and it is not really that much important, nor easy to be tested). About height it is true it doesn't need to be the multiple of 8 (but you already check that here) so you don't need to edit anything more. For now I won't merge this yet, someone else may have more thoughts on this PR, but you did great job. |
@MightyJosip Thank you for checking my code and for the clarification. |
3a92f1a
to
f17913d
Compare
Sorry for accidentally closing this pull request. I had made a mistake on a commit, pushed it and wanted to undo it, but the instructions I followed reset the branch to before any commits and I ended up force pushing an empty branch. I redid the commits so the first commit will be the same as the original first commit and the second commit has the changes I actually wanted. |
I'm actually a bit surprised that this bit:
seems to run on SDL2 CI given that the last part of the test uses
and the SDL2 get cursor code looks like this:
Probably should figure out what is happening in there before approving this. Otherwise it looks pretty good :) As a related side note for anyone else reading this; I notice that SDL2 now lets you directly set a surface as a mouse pointer - might be a good extension to the mouse module rather than having surfaces following the mouse pointer position as is common now. |
Is there a way to get the cursor values without the use of |
Not as far as I can tell. SDL 2's
Whereas in SDL 1 it clearly has more data in it, as you can see from the pygame SDL1 get_cursor code here: Lines 299 to 308 in 7d3900d
It looks like SDL2 hands off cursor data to each platform and lets the platforms decide what data to store in the
I think you''l just have to check that set_cursor doesn't raise an SDL error on SDL2 and leave it at that. I'm not sure it's even possible to reliably screenshot the mouse pointer on all platforms to check it in that convoluted fashion, and if you could it wouldn't work on the CI anyway with the dummy video driver. I would just make an Lines 266 to 267 in 7d3900d
|
Would this be sufficient in the SDL2 branch?
|
I think you can probably simplify it down, something like:
Hopefully that makes sense. We want the test to fail if |
The CI checks are currently failing when there is no cursor present for SDL2 since it's being caught in the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking into this it looks like set_cursor()
works fine running locally, but fails out on SDL2 with the dummy video driver. It literally fails in the SDL2 code here:
if (!mouse->CreateCursor) {
SDL_SetError("Cursors are not currently supported");
return NULL;
}
So, I think at this point it is probably a good idea to split this into two tests.
-
An SDL2 test that tests everything the SDL1 version does - apart from that the expected successful result is equal to the result of
get_cursor()
. This test will be skipped when SDL1 is true, or when SDL_VIDEODRIVER is dummy. -
An SDL1 version that is the current test with the SDL2 bits removed. This test will be skipped if SDL1 is not True.
I would just call them test_set_cursor__sdl1()
and test_set_cursor__sdl2()
.
OK, that all looks good to me now. Runs locally and on CI under SDL1 and SDL2. |
I looked over my code again and realized that I changed the parameters for the calls to Besides the unused variable being removed, are the other changes alright? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that all seems fine. At some point (it's an ongoing project) we'll run all the test files through linting tools like pylint which will identify/clean up things like unused variables.
Gotcha. Thanks for the help and insight from everyone. |
This pull request is to add a unit test for
mouse.set_cursor
and addresses issue #1763.I think I got all of the test cases except for when there is no memory left to allocate either bit mask.
The code below is what I need an assert for, but I don't know how to test for a lack of memory since the amount RAM is different depending on the system running and I don't know of any methods to help me.
Does anyone have any ideas?
Also, for clarification, the documentation for
mouse.set_cursor
says that the width for the size of the cursor has to be a multiple of 8 but not for height. Is it safe to assume that the height does not need to be a multiple of 8?If there's anything I need to change or add, please feel free to let me know. Thank you.