jfowkes / pycutest

Python interface to CUTEst
https://jfowkes.github.io/pycutest/
GNU General Public License v3.0
28 stars 11 forks source link

Restore current working directory on failure #55

Closed jfowkes closed 1 year ago

jfowkes commented 1 year ago

Resolves #54

We were rather sloppy in our directory handling and were not restoring the current working directory on errors when building various parts of the interface. This PR simply restores the current working directory before raising errors.

I have also taken the opportunity to remove some ancient Python 2 stuff from build_interface as we are now Python 3 only, namely unicode (which was renamed to str) and the FileNotFoundError definition.

To test, use the minimal working example from #54

import os, pycutest

try:
    prob = pycutest.import_problem('SCURLY20', sifParams={'N': 10})
except RuntimeError:
    print("Loading failed.")
print(os.getcwd())

this should now pass as expected (at least it does for me).

jfowkes commented 1 year ago

@ragonneau could you please test and verify that these fixes work for you?

@lindonroberts would be grateful if you could review this when you have time, should be trivial :)

ragonneau commented 1 year ago

@ragonneau could you please test and verify that these fixes work for you?

@lindonroberts would be grateful if you could review this when you have time, should be trivial :)

Hi @jfowkes,

I tested it on my side and it worked perfectly!

Regards, Tom.

jfowkes commented 1 year ago

@lindonroberts good point, will add a unit test and merge.