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
766 stars 120 forks source link

Fix failing tests based on numpy v2 #2934

Closed ankith26 closed 1 week ago

ankith26 commented 1 week ago

Using the ruff plugin suggested in NumPy 2.0 migration guide

(base_env) ankith@AnkithLaptop:~/mount/gitstuff/personal/pygame-community/pygame-ce$ ruff check . --select NPY201
test/pixelcopy_test.py:548:25: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/pixelcopy_test.py:556:25: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/pixelcopy_test.py:566:25: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/sndarray_test.py:31:25: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/sndarray_test.py:74:25: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/sndarray_test.py:113:25: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/surfarray_test.py:238:33: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/surfarray_test.py:246:17: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/surfarray_test.py:260:21: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/surfarray_test.py:265:21: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
test/surfarray_test.py:293:29: NPY201 [*] `np.alltrue` will be removed in NumPy 2.0. Use `all` instead.
Found 11 errors.
[*] 11 fixable with the `--fix` option.

Fixed all these issues by replacing the alltrue import with the all import, now aliased to np_all to prevent name collision with python's builtin all.

Also fixed a few incorrect sndarray testcases and added a skip for a failing surfarray test (we will deal with it in the future)

PS: the numpy.all function is numpy v1 API, so now our tests can run on both numpy v1 and numpy v2