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

Added tests for mouse.set_pos() #1824

Merged
merged 4 commits into from May 21, 2020

Conversation

Graphcalibur
Copy link
Contributor

Addresses #1764.

Copy link
Contributor

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

Looks like set_pos is a bit tricky. Perhaps try something like this?

import pygame

pygame.display.init()

# window has to be one pixel larger than mouse positions
window = pygame.display.set_mode((1000, 1000))

expected_pos = ((1, 1), (1, 400), (912, 566), (999, 999), (999, 0), (0, 999))
for x, y in expected_pos:
    pygame.event.get()  # clear all startup events off the event queue

    pygame.mouse.set_pos(x, y)
    ready_to_test = False
    while not ready_to_test:
        # need to process the event queue to move the mouse
        for event in pygame.event.get():
            if event.type == pygame.MOUSEMOTION:
                ready_to_test = True

    pygame.display.update()
    found_pos = pygame.mouse.get_pos()
    self.assertTrue(found_pos, (x, y))

@Graphcalibur
Copy link
Contributor Author

Thank you for the help! I think this commit should get it to work properly.

test/mouse_test.py Show resolved Hide resolved
@MyreMylar
Copy link
Contributor

All looks good 👍 🎉

@MyreMylar MyreMylar merged commit 8eaf011 into pygame:master May 21, 2020
@illume illume added the mouse pygame.mouse label May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mouse pygame.mouse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants