pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
840 stars 140 forks source link

Write a unit test that builds a simple pygame program with pyinstaller, then runs that application - to eventually run on CI (2136) #1125

Open GalacticEmperor1 opened 1 year ago

GalacticEmperor1 commented 1 year ago

Issue №2136 opened by illume at 2020-10-04 11:14:08

Now that pyinstaller has per package hooks, it makes sense to test it ourselves.


Comments

*ankith26 commented at 2020-10-04 13:26:10*

I found a useful link (I havent done much research myself, but the link looks useful for this case): https://github.com/pyinstaller/hooksample

Continuing from my last message in the PR linked, let me clearly explain this time.

Here is how I would launch the "aliens" example that comes with pygame.

import pygame.examples.aliens
pygame.examples.aliens.main()

I save this bit of code into a python file, and when I run it, it loads the nice game.

Now I use pyinstaller on this file, and when I run the exe, it crashes. This crash is intentional, you can try it out.

This is happenning because pyinstaller has not bundled any data files needed by aliens to work. Neither will any other examples work if they are used this way.

Now for tests/pyinstaller_test.py, it means that the test code we are writing must not rely on any external resource, because pyinstaller is not going to bundle it automatically for us. If it does rely on any image/font/audio file, then we would have to write a spec file for it


*illume commented at 2022-01-22 21:10:35*

I guess there could be a way to hunt data files. If not, then specify them.


*illume commented at 2022-01-22 21:14:13*

I guess there are examples without data files where we could start.

It would be handy to be able to quit the examples via environment variable. Otherwise perhaps one of the command line examples would be fine for this pyinstaller test… because they should exit with a suitable return code that can be checked.

StanCDev commented 1 month ago

Hey, while executing the following

import pygame.examples.aliens
pygame.examples.aliens.main()

I get weird behaviour. The game works perfectly fine but as soon as player dies it freezes. I must force quit the application to exit it. I am using pygame-ce 2.5.1 (SDL 2.30.6, Python 3.12.4)

oddbookworm commented 1 month ago

@StanCDev you're not supposed to run the main function of an example directly. Just do python -m pygame.examples.aliens