jonescompneurolab / hnn-core

Simulation and optimization of neural circuits for MEG/EEG source estimates
https://jonescompneurolab.github.io/hnn-core/
BSD 3-Clause "New" or "Revised" License
50 stars 50 forks source link

[MAINT] Fixing Unit Tests for Python 3.11 and 3.12 support #800

Closed kmilo9999 closed 1 week ago

kmilo9999 commented 2 weeks ago

For now we decided to test the 2 latest versions and oldest supported version of python on mac, Linux, and windows for all PRs. A full-matrix test of all supported python versions performed at a longer frequency is still being considered.

This PR is aimed to fix incompatibilities found in the tests against python 3.11 and 3.12

kmilo9999 commented 2 weeks ago

@gtdang @ntolley @jasmainak @dylansdaniels I found two problems that are making the tests fail in python 3.11+:

  1. hnn_core/tests/test_drives.py

The code is looking to raise a ValueErrorexception and match the error message against a specific string:

with pytest.raises(ValueError,
                           match=r'Burst duration (?s).* cannot be greater than'):

It seems that the regex rules changed in python 3.11+. It is enforced that global flags like (?s) need to be placed at the begging of the pattern. Moving the flag to the indicated position fixes the test case.

  1. hnn_core/tests/test_extracellular.py

Similar to the fist point, The code is looking to raise an AttributeError exception and match the error message against a specific string:

with pytest.raises(AttributeError, match="can't set attribute"):
        rec_arr.times = [1, 2, 3]

In this case, pythom 3.11+ changed the message of the AttributeError exception to "property X of object Y has no setter", thus the test fails matching the two strings. I couldnt find this change in the python changelog, but I found the PR that applied it.

Looking forwards for your comments.

jasmainak commented 2 weeks ago

I'm not a regular expression expert but I trust your judgement. Can you run the CIs so I can see that they get fixed?

kmilo9999 commented 2 weeks ago

I'm not a regular expression expert but I trust your judgement. Can you run the CIs so I can see that they get fixed?

Do you mean the CI in the master branch? or in this PR?

kmilo9999 commented 1 week ago

@ntolley @gtdang It seems the unit tests are working now for python 3.11 and 3.12

gtdang commented 1 week ago

@ntolley The branch protections need to be updated for the versions we are testing. It's still looking for 3.9, which is no longer in the matrix. 3.11 and 3.12 should be added.

ntolley commented 1 week ago

All set! Thanks @kmilo9999 we're all breathing much easier with the return of the green checkmarks :smile:

dylansdaniels commented 1 week ago

✅ 🥳 ✅ 🥳 ✅