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

tests: simplify createcopy test #11137

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 127 additions & 140 deletions autotest/gcore/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,61 +281,20 @@ def misc_6_internal(datatype, nBands, setDriversDone):
drv = gdal.GetDriver(i)
md = drv.GetMetadata()
if ("DCAP_CREATECOPY" in md or "DCAP_CREATE" in md) and "DCAP_RASTER" in md:
# print ('drv = %s, nBands = %d, datatype = %s' % (drv.ShortName, nBands, gdal.GetDataTypeName(datatype)))

skip = False
# FIXME: A few cases that crashes and should be investigated
if drv.ShortName == "JPEG2000":
if (nBands == 2 or nBands >= 5) or not (
datatype == gdal.GDT_Byte
or datatype == gdal.GDT_Int16
or datatype == gdal.GDT_UInt16
):
skip = True
if skip is False:
dirname = "tmp/tmp/tmp_%s_%d_%s" % (
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
)
try:
os.mkdir(dirname)
except OSError:
try:
os.stat(dirname)
# Hum the directory already exists... Not expected, but let's try to go on
except OSError:
reason = (
"Cannot create %s before drv = %s, nBands = %d, datatype = %s"
% (
dirname,
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
)
)
pytest.fail(reason)

filename = get_filename(drv, dirname)

dst_ds = drv.CreateCopy(filename, ds)
has_succeeded = dst_ds is not None
if dst_ds:
# check that domain == None doesn't crash
dst_ds.GetMetadata(None)
dst_ds.GetMetadataItem("", None)
dst_ds = None

size = 0
stat = gdal.VSIStatL(filename)
if stat is not None:
size = stat.size

dirname = "tmp/tmp/tmp_%s_%d_%s" % (
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
)
try:
os.mkdir(dirname)
except OSError:
try:
shutil.rmtree(dirname)
os.stat(dirname)
# Hum the directory already exists... Not expected, but let's try to go on
except OSError:
reason = (
"Cannot remove %s after drv = %s, nBands = %d, datatype = %s"
"Cannot create %s before drv = %s, nBands = %d, datatype = %s"
% (
dirname,
drv.ShortName,
Expand All @@ -345,114 +304,142 @@ def misc_6_internal(datatype, nBands, setDriversDone):
)
pytest.fail(reason)

if has_succeeded and drv.ShortName not in setDriversDone and nBands > 0:
setDriversDone.add(drv.ShortName)
filename = get_filename(drv, dirname)

# The first list of drivers fail to detect short writing
# The second one is because they are verbose in stderr
if (
"DCAP_VIRTUALIO" in md
and size != 0
and drv.ShortName
not in [
"JPEG2000",
"KMLSUPEROVERLAY",
"HF2",
"ZMap",
"DDS",
"TileDB",
]
and drv.ShortName not in ["GIF", "JP2ECW", "JP2Lura"]
):
dst_ds = drv.CreateCopy(filename, ds)
has_succeeded = dst_ds is not None
if dst_ds:
# check that domain == None doesn't crash
dst_ds.GetMetadata(None)
dst_ds.GetMetadataItem("", None)
dst_ds = None

for j in range(10):
truncated_size = (size * j) / 10
vsimem_filename = (
"/vsimem/test_truncate/||maxlength=%d||"
% truncated_size
) + get_filename(drv, "")[1:]
# print('drv = %s, nBands = %d, datatype = %s, truncated_size = %d' % (drv.ShortName, nBands, gdal.GetDataTypeName(datatype), truncated_size))
dst_ds = drv.CreateCopy(vsimem_filename, ds)
error_detected = False
if dst_ds is None:
error_detected = True
else:
gdal.ErrorReset()
dst_ds = None
if gdal.GetLastErrorMsg() != "":
error_detected = True
if not error_detected:
msg = (
"write error not detected with with drv = %s, nBands = %d, datatype = %s, truncated_size = %d"
% (
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
truncated_size,
)
)
print(msg)
size = 0
stat = gdal.VSIStatL(filename)
if stat is not None:
size = stat.size

fl = gdal.ReadDirRecursive("/vsimem/test_truncate")
if fl is not None:
for myf in fl:
gdal.Unlink("/vsimem/test_truncate/" + myf)
fl = gdal.ReadDirRecursive("/vsimem/test_truncate")
if fl is not None:
print(fl)

if drv.ShortName not in [
"ECW",
"JP2ECW",
"VRT",
"XPM",
try:
shutil.rmtree(dirname)
except OSError:
reason = (
"Cannot remove %s after drv = %s, nBands = %d, datatype = %s"
% (
dirname,
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
)
)
pytest.fail(reason)

if has_succeeded and drv.ShortName not in setDriversDone and nBands > 0:
setDriversDone.add(drv.ShortName)

# The first list of drivers fail to detect short writing
# The second one is because they are verbose in stderr
if (
"DCAP_VIRTUALIO" in md
and size != 0
and drv.ShortName
not in [
"JPEG2000",
"FIT",
"RST",
"INGR",
"USGSDEM",
"KMLSUPEROVERLAY",
"GMT",
]:
dst_ds = drv.CreateCopy(
filename, ds, callback=misc_6_interrupt_callback_class().cbk
)
if dst_ds is not None:
dst_ds = None

try:
shutil.rmtree(dirname)
except OSError:
pass
"HF2",
"ZMap",
"DDS",
"TileDB",
]
and drv.ShortName not in ["GIF", "JP2ECW", "JP2Lura"]
):

pytest.fail(
"interruption did not work with drv = %s, nBands = %d, datatype = %s"
for j in range(10):
truncated_size = (size * j) / 10
vsimem_filename = (
"/vsimem/test_truncate/||maxlength=%d||" % truncated_size
) + get_filename(drv, "")[1:]
# print('drv = %s, nBands = %d, datatype = %s, truncated_size = %d' % (drv.ShortName, nBands, gdal.GetDataTypeName(datatype), truncated_size))
dst_ds = drv.CreateCopy(vsimem_filename, ds)
error_detected = False
if dst_ds is None:
error_detected = True
else:
gdal.ErrorReset()
dst_ds = None
if gdal.GetLastErrorMsg() != "":
error_detected = True
if not error_detected:
msg = (
"write error not detected with with drv = %s, nBands = %d, datatype = %s, truncated_size = %d"
% (
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
truncated_size,
)
)
print(msg)

fl = gdal.ReadDirRecursive("/vsimem/test_truncate")
if fl is not None:
for myf in fl:
gdal.Unlink("/vsimem/test_truncate/" + myf)
fl = gdal.ReadDirRecursive("/vsimem/test_truncate")
if fl is not None:
print(fl)

if drv.ShortName not in [
"ECW",
"JP2ECW",
"VRT",
"XPM",
"JPEG2000",
"FIT",
"RST",
"INGR",
"USGSDEM",
"KMLSUPEROVERLAY",
"GMT",
]:
dst_ds = drv.CreateCopy(
filename, ds, callback=misc_6_interrupt_callback_class().cbk
)
if dst_ds is not None:
dst_ds = None

try:
shutil.rmtree(dirname)
except OSError:
pass
try:
os.mkdir(dirname)
except OSError:
reason = (
"Cannot create %s before drv = %s, nBands = %d, datatype = %s"
% (
dirname,
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
)

pytest.fail(
"interruption did not work with drv = %s, nBands = %d, datatype = %s"
% (
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
)
pytest.fail(reason)
)

dst_ds = None

try:
shutil.rmtree(dirname)
except OSError:
pass
try:
os.mkdir(dirname)
except OSError:
reason = (
"Cannot create %s before drv = %s, nBands = %d, datatype = %s"
% (
dirname,
drv.ShortName,
nBands,
gdal.GetDataTypeName(datatype),
)
)
pytest.fail(reason)
ds = None


Expand Down
Loading