2

I'm running GDAL 2.2.0 and have set up some unit tests to run using Jenkins CI (1.609.2). One of the tests fails every time, even though if I log on to the Jenkins box and run the test manually, everything runs ok.

Here's a simplified version of the code I'm testing (it's a raster checker QA tool):

def check_band_info(ds, expected_max_value=None):
for rc in xrange(1, ds.RasterCount + 1):
    rb = ds.GetRasterBand(rc)

    # more tests here

    if expected_max_value is not None:
        actual_max_value = rb.GetMaximum()
        if actual_max_value is None or actual_max_value > float(expected_max_value):
            print('Band {} Maximum value {}'.format(rc, actual_max_value))

Running gdalinfo on the raster shows band 5 does have a maximum value:

Band 5 Block=20x19 Type=Int32, ColorInterp=Undefined
Min=140.000 Max=654.000
Minimum=140.000, Maximum=654.000, Mean=378.645, StdDev=103.930
NoData Value=-2147483648
Metadata:
RETURN_PERIOD=1000
SCALE=0
STATISTICS_MAXIMUM=654
STATISTICS_MEAN=378.64473684211
STATISTICS_MINIMUM=140
STATISTICS_STDDEV=103.93007567684
UNITS=m

However, the test fails with:

======================================================================
FAIL: test_max_value_pass (autoqc.test.test_raster_checker.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/user/.jenkins/workspace/autoqc/test/test_raster_checker.py", line 120, in test_max_value_pass
    expected_max_value=expected_value)
  File "/home/user/.jenkins/workspace/autoqc/test/test_raster_checker.py", line 33, in _test_task
    self.assertEqual(result[-1][-1], message)
AssertionError: "Actual ['Band 5 Maximum value None']" != 'OK'

----------------------------------------------------------------------  

I've added a skip to get the build to pass, but I shouldn't need to as on every other machine, and when I run it manually this test passes.

Has anyone seen something similar? Is there a race condition that is making gdal return None, but only when running under CI?

1

You can try out following lines in your code:

.
.
.
band = dataset.GetRasterBand(1)
min = band.GetMinimum()
max = band.GetMaximum()
if not min or not max:
    (min,max) = band.ComputeRasterMinMax(True)
.
.
.
  • Is this mainly for rasters where statistics have not yet been calculated? This raster definitely has stats, as the gdalinfo output shows. – jon_two Nov 6 '17 at 16:29
  • No. In my case I solved this kind of problem with these instructions. – xunilk Nov 6 '17 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.