Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autotest: update tests for gdal_calc #11667

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

dbaston
Copy link
Member

@dbaston dbaston commented Jan 16, 2025

  • simplify generation of temporary file names, since they'll be cleaned up automatically
  • separate independent tests into separate functions
  • add tests for untested arguments
  • avoid copying input dataset for every test function
  • use vsimem where possible

@coveralls
Copy link
Collaborator

coveralls commented Jan 16, 2025

Coverage Status

coverage: 70.074% (+0.01%) from 70.061%
when pulling 174e822 on dbaston:gdal-calc-tidy
into f41af17 on OSGeo:master.

@dbaston
Copy link
Member Author

dbaston commented Jan 16, 2025

Should the @optfile syntax work in Windows CMD? The way the test was written previously, it passed even though the call to gdal_calc failed. I'm trying to figure out if it should succeed. When I call gdal_calc from CMD (outside of the test framework), it appears to strip all of the \ characters from the optfile, causing gdal_calc to fail because it can't find the input dataset.

@rouault
Copy link
Member

rouault commented Jan 16, 2025

Should the @optfile syntax work in Windows CMD?

I've no idea. If that's an annoyance, just skip the test on Windows

@jratike80
Copy link
Collaborator

jratike80 commented Jan 16, 2025

Should the @optfile syntax work in Windows CMD?

gdal_calc @optfile.txt
0...10...20...30...40...50...60...70...80...90...100 - done.

Maybe the optfile itself does not work on Windows? Like having \ as newlines, while it maybe should be ^.
I tested with a simple optfile.txt
-A input1.tif -B input2.tif --outfile=result.tif --calc="(A+B)/2"

And if the trouble was caused by the file paths, Windows supports also forward slashes
-A C:/data/000/00/input1.tif -B C:/data/000/00/input2.tif --outfile=C:/data/000/00/result.tif --calc="(A+B)/2"

@dbaston
Copy link
Member Author

dbaston commented Jan 17, 2025

Here are the optfile contents:

-A C:\Users\dbaston\AppData\Local\Temp\pytest-of-dbaston\pytest-5\gdal_calc0\stefan_full_rgba.tif --calc=A --overwrite --outfile C:\Users\dbaston\AppData\Local\Temp\pytest-of-dbaston\pytest-5\test_gdal_calc_py_7a___0\out.tif

Calling gdal_calc with --optfile is successful:

C:\dev\gdal\build>python swig\python\osgeo_utils\gdal_calc.py --optfile C:\Users\dbaston\AppData\Local\Temp\pytest-of-dbaston\pytest-5\test_gdal_calc_py_7a___0\opt
0...10...20...30...40...50...60...70...80...90...100 - done.

Calling gdal_calc with @opt fails -- the \ characters appear to be stripped on reading:

C:\dev\gdal\build>python swig\python\osgeo_utils\gdal_calc.py @C:\Users\dbaston\AppData\Local\Temp\pytest-of-dbaston\pytest-5\test_gdal_calc_py_7a___0\opt
Could not open file "C:UsersdbastonAppDataLocalTemppytest-of-dbastonpytest-5gdal_calc0stefan_full_rgba.tif": No such file or directory

After editing the optfile to replace \ with /, it can be used with @:

C:\dev\gdal\build>python swig\python\osgeo_utils\gdal_calc.py @C:\Users\dbaston\AppData\Local\Temp\pytest-of-dbaston\pytest-5\test_gdal_calc_py_7a___0\opt2.txt
0...10...20...30...40...50...60...70...80...90...100 - done.

I'm going to skip the test on Windows for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants