8000 unit test for image.load_extended() by kristofszentes · Pull Request #2324 · pygame/pygame · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

unit test for image.load_extended() #2324

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

8000
Merged
merged 4 commits into from
Nov 13, 2020
Merged

unit test for image.load_extended() #2324

merged 4 commits into from
Nov 13, 2020

Conversation

kristofszentes
Copy link
Contributor

I added a unit test for image.load_extended(), and some small images (smaller than 32x32 pixels) in the example/data folder to be able to test all the following formats: BMP, PNG, JPG, GIF (non-animated), TGA (uncompressed), TIF, XPM, PPM, PGM, as it was asked in this previous attempt of a such unit test.
Here is the issue related to this unit test.

#We test loading the following file types: bmp, png, jpg, gif (non-animated), tga (uncompressed), tif, xpm, ppm, pgm
#All the loaded images are smaller than 32 x 32 pixels

#test loading a bmp
Copy link
Member

Choose a reason for hiding this comment

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

We only recently added support for using subTest inside the pygame test suite, but they're excellent! With them you can make the messages better if something fails. Also it allows the further parts to be tested if something at the top of the test fails (for example if the png loading fails all the subTests after that will run). Have a look at the docs for subTest: https://docs.python.org/3/library/unittest.html#subtests

Something similar to this... (untested):

with self.subTest("test loading a bmp", filename=filename, expected_color=(...)):
    surf = pygame.image.load_extended(example_path(filename))
    self.assertEqual(surf.get_at((0,0)), expected_color)

It's also possible to loop over a data structure of [[filename, expected_color], ...]

Copy link
Member
@illume illume 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 :) It's great to have tests for all those file formats now.

We could merge this in if you're happy with it. I left a note about subTest, which you may want to look into. Another minor thing is that the spacing in the colors could be improved to be pep8 friendly.

@kristofszentes
Copy link
Contributor Author

Thank you for your advice!
I changed spacing for colors, added the use of subTest and a for loop going through all the tests.

@illume
Copy link
Member
illume commented Nov 13, 2020

Brilliant. Thanks again.

@illume illume merged commit 16fddef into pygame:main Nov 13, 2020
@illume illume changed the title adding unit test for image.load_extended() unit test for image.load_extended() Dec 23, 2020
@illume illume added the image pygame.image label Dec 23, 2020
@illume illume added this to the 2.0.1 milestone Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
image pygame.image
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0