OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
828 stars 301 forks source link

grass.gunittest: Fix SIM115 using context managers to open files #4338

Closed echoix closed 1 week ago

echoix commented 1 week ago

Fixes all SIM115 issues in gunittest, except for two where I couldn't find a way to address with enough confidence for use in our own testing (one is not resolvable with context managers, as the opened file descriptor is assigned to the class in one function, and expected to be closed by another call at the end of the execution).

Only in two functions I had to resort to indent the most of the function since there were usages of the file descriptor throughout the function, and was used inside and outside a loop.

Otherwise, I tried to keep the amount of lines needing an indentation to a minimum, by moving down the variables needing to be within the with closer to that construct (in other words, placing variables assignments out the with further up, that ends up being understood by git as no changes except deleting the existing opening of file/writing of file, and some new code underneath with a smaller with context manager).

Adresses ResourceWarnings like (CI on Windows): image image image image