Skip to content

Commit

Permalink
TEST: More complete tests, including geoTransform, Proj and Checksum …
Browse files Browse the repository at this point in the history
…tests (from PR review)
  • Loading branch information
jmichel-otb committed Jul 8, 2016
1 parent e1c072a commit d96cf59
Showing 1 changed file with 68 additions and 5 deletions.
73 changes: 68 additions & 5 deletions autotest/gdrivers/derived.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@
# Test opening a L1C product


def derived_test():
def derived_test1():
filename = "data/cfloat64.tif"
gdal.ErrorReset()
ds = gdal.Open(filename)
if ds is None or gdal.GetLastErrorMsg() != '':
gdaltest.post_reason('fail')
return 'fail'
got_dsds = ds.GetMetadata('DERIVED_SUBDATASETS')

expected_gt = ds.GetGeoTransform()
expected_prj = ds.GetProjection()
expected_dsds = {'DERIVED_SUBDATASET_0_NAME' : 'DERIVED_SUBDATASET:AMPLITUDE:data/cfloat64.tif',
'DERIVED_SUBDATASET_0_DESC' : 'Amplitude of input bands from data/cfloat64.tif',
'DERIVED_SUBDATASET_1_NAME' : 'DERIVED_SUBDATASET:PHASE:data/cfloat64.tif',
Expand All @@ -69,19 +70,81 @@ def derived_test():
pprint.pprint(got_dsds)
return 'fail'


for (key,val) in expected_dsds.iteritems():
if key.endswith('_NAME'):
ds = gdal.Open(val)
if ds is None or gdal.GetLastErrorMsg() != '':
gdaltest.post_reason('fail')
return 'fail'

gt = ds.GetGeoTransform()
if gt != expected_gt:
gdaltest.post_reason('fail')
import pprint
pprint.pprint("Expected geotransform: "+str(expected_gt)+", got "+str(gt))
return 'fail'
prj = ds.GetProjection()
if prj != expected_prj:
gdaltest.post_reason('fail')
import pprint
pprint.pprint("Expected projection: "+str(expected_prj)+", got: "+str(gt))
return 'fail'
return 'success'

def derived_test2():
filename = "data/cint_sar.tif"
gdal.ErrorReset()
ds = gdal.Open(filename)
if ds is None or gdal.GetLastErrorMsg() != '':
gdaltest.post_reason('fail')
return 'fail'
got_dsds = ds.GetMetadata('DERIVED_SUBDATASETS')
expected_dsds = {'DERIVED_SUBDATASET_0_NAME' : 'DERIVED_SUBDATASET:AMPLITUDE:data/cint_sar.tif',
'DERIVED_SUBDATASET_0_DESC' : 'Amplitude of input bands from data/cint_sar.tif',
'DERIVED_SUBDATASET_1_NAME' : 'DERIVED_SUBDATASET:PHASE:data/cint_sar.tif',
'DERIVED_SUBDATASET_1_DESC' : 'Phase of input bands from data/cint_sar.tif',
'DERIVED_SUBDATASET_2_NAME' : 'DERIVED_SUBDATASET:REAL:data/cint_sar.tif',
'DERIVED_SUBDATASET_2_DESC' : 'Real part of input bands from data/cint_sar.tif',
'DERIVED_SUBDATASET_3_NAME' : 'DERIVED_SUBDATASET:IMAG:data/cint_sar.tif',
'DERIVED_SUBDATASET_3_DESC' : 'Imaginary part of input bands from data/cint_sar.tif',
'DERIVED_SUBDATASET_4_NAME' : 'DERIVED_SUBDATASET:CONJ:data/cint_sar.tif',
'DERIVED_SUBDATASET_4_DESC' : 'Conjugate of input bands from data/cint_sar.tif',
'DERIVED_SUBDATASET_5_NAME' : 'DERIVED_SUBDATASET:INTENSITY:data/cint_sar.tif',
'DERIVED_SUBDATASET_5_DESC' : 'Intensity (squared amplitude) of input bands from data/cint_sar.tif',
'DERIVED_SUBDATASET_6_NAME' : 'DERIVED_SUBDATASET:LOGAMPLITUDE:data/cint_sar.tif',
'DERIVED_SUBDATASET_6_DESC' : 'log10 of amplitude of input bands from data/cint_sar.tif'}

expected_cs = { 'DERIVED_SUBDATASET_0_NAME' : 345,
'DERIVED_SUBDATASET_5_NAME' : 314,
'DERIVED_SUBDATASET_3_NAME' : 142,
'DERIVED_SUBDATASET_1_NAME' : 10,
'DERIVED_SUBDATASET_6_NAME' : 99,
'DERIVED_SUBDATASET_4_NAME' : 110,
'DERIVED_SUBDATASET_2_NAME' : 159}

if got_dsds != expected_dsds:
gdaltest.post_reason('fail')
import pprint
pprint.pprint(got_dsds)
return 'fail'

for (key,val) in expected_dsds.iteritems():
if key.endswith('_NAME'):
ds = gdal.Open(val)
if ds is None or gdal.GetLastErrorMsg() != '':
gdaltest.post_reason('fail')
return 'fail'
cs = ds.GetRasterBand(1).Checksum()
if expected_cs[key] != cs:
gdaltest.post_reason('fail')
import pprint
pprint.pprint("Expected checksum "+str(expected_cs[key])+", got "+str(cs))
return 'fail'

return 'success'

gdaltest_list = [
derived_test
derived_test1,
derived_test2
]

if __name__ == '__main__':
Expand Down

0 comments on commit d96cf59

Please sign in to comment.