Skip to content

Commit 1f134c7

Browse files
committed
test(python): expand ImageInput testsuite coverage
Signed-off-by: Aleksandr Motsjonov <soswow@gmail.com>
1 parent 36a1b54 commit 1f134c7

7 files changed

Lines changed: 278 additions & 0 deletions

File tree

testsuite/python-imageinput/ref/out-alt.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,39 @@ Testing write and read of TIFF CMYK with auto RGB translation:
205205
[0.24705884 0.49803925 0.49803925]]
206206

207207

208+
Testing ImageInput.create:
209+
create succeeded: True
210+
format_name is tiff: True
211+
create invalid returns None: True
212+
213+
Testing valid_file and supports:
214+
valid_file good: True
215+
valid_file bad: True
216+
supports returns numeric: True
217+
grid supports mipmap: True
218+
219+
Testing seek_subimage state:
220+
initial sub/mip: 0 0
221+
seek mip 2: True
222+
after seek sub/mip: 0 2
223+
spec(0,2) width: 256
224+
read_image sub/mip/ch ndim: 3
225+
226+
Testing read_native_deep_image:
227+
deep file: True
228+
read_native_deep_image ok: True
229+
deep pixels: 19200 channels: 2
230+
231+
Testing get_thumbnail:
232+
get_thumbnail returns ImageBuf: True
233+
thumbnail initialized: False
234+
235+
Testing has_error/geterror:
236+
scanline on tiled None: True
237+
has_error: True
238+
geterror persists: True
239+
has_error after clear: False
240+
208241
is_imageio_format_name('tiff') = True
209242
is_imageio_format_name('txff') = False
210243
Done.

testsuite/python-imageinput/ref/out-alt2.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,39 @@ Testing write and read of TIFF CMYK with auto RGB translation:
205205
[0.24705884 0.49803925 0.49803925]]
206206

207207

208+
Testing ImageInput.create:
209+
create succeeded: True
210+
format_name is tiff: True
211+
create invalid returns None: True
212+
213+
Testing valid_file and supports:
214+
valid_file good: True
215+
valid_file bad: True
216+
supports returns numeric: True
217+
grid supports mipmap: True
218+
219+
Testing seek_subimage state:
220+
initial sub/mip: 0 0
221+
seek mip 2: True
222+
after seek sub/mip: 0 2
223+
spec(0,2) width: 256
224+
read_image sub/mip/ch ndim: 3
225+
226+
Testing read_native_deep_image:
227+
deep file: True
228+
read_native_deep_image ok: True
229+
deep pixels: 19200 channels: 2
230+
231+
Testing get_thumbnail:
232+
get_thumbnail returns ImageBuf: True
233+
thumbnail initialized: False
234+
235+
Testing has_error/geterror:
236+
scanline on tiled None: True
237+
has_error: True
238+
geterror persists: True
239+
has_error after clear: False
240+
208241
is_imageio_format_name('tiff') = True
209242
is_imageio_format_name('txff') = False
210243
Done.

testsuite/python-imageinput/ref/out-py37-jpeg9d.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,39 @@ Testing write and read of TIFF CMYK with auto RGB translation:
205205
[0.24705884 0.49803925 0.49803925]]
206206

207207

208+
Testing ImageInput.create:
209+
create succeeded: True
210+
format_name is tiff: True
211+
create invalid returns None: True
212+
213+
Testing valid_file and supports:
214+
valid_file good: True
215+
valid_file bad: True
216+
supports returns numeric: True
217+
grid supports mipmap: True
218+
219+
Testing seek_subimage state:
220+
initial sub/mip: 0 0
221+
seek mip 2: True
222+
after seek sub/mip: 0 2
223+
spec(0,2) width: 256
224+
read_image sub/mip/ch ndim: 3
225+
226+
Testing read_native_deep_image:
227+
deep file: True
228+
read_native_deep_image ok: True
229+
deep pixels: 19200 channels: 2
230+
231+
Testing get_thumbnail:
232+
get_thumbnail returns ImageBuf: True
233+
thumbnail initialized: False
234+
235+
Testing has_error/geterror:
236+
scanline on tiled None: True
237+
has_error: True
238+
geterror persists: True
239+
has_error after clear: False
240+
208241
is_imageio_format_name('tiff') = True
209242
is_imageio_format_name('txff') = False
210243
Done.

testsuite/python-imageinput/ref/out-python3-win-2.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,39 @@ Testing write and read of TIFF CMYK with auto RGB translation:
205205
[0.24705884 0.49803925 0.49803925]]
206206

207207

208+
Testing ImageInput.create:
209+
create succeeded: True
210+
format_name is tiff: True
211+
create invalid returns None: True
212+
213+
Testing valid_file and supports:
214+
valid_file good: True
215+
valid_file bad: True
216+
supports returns numeric: True
217+
grid supports mipmap: True
218+
219+
Testing seek_subimage state:
220+
initial sub/mip: 0 0
221+
seek mip 2: True
222+
after seek sub/mip: 0 2
223+
spec(0,2) width: 256
224+
read_image sub/mip/ch ndim: 3
225+
226+
Testing read_native_deep_image:
227+
deep file: True
228+
read_native_deep_image ok: True
229+
deep pixels: 19200 channels: 2
230+
231+
Testing get_thumbnail:
232+
get_thumbnail returns ImageBuf: True
233+
thumbnail initialized: False
234+
235+
Testing has_error/geterror:
236+
scanline on tiled None: True
237+
has_error: True
238+
geterror persists: True
239+
has_error after clear: False
240+
208241
is_imageio_format_name('tiff') = True
209242
is_imageio_format_name('txff') = False
210243
Done.

testsuite/python-imageinput/ref/out-python3-win.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,39 @@ Testing write and read of TIFF CMYK with auto RGB translation:
205205
[0.24705884 0.49803925 0.49803925]]
206206

207207

208+
Testing ImageInput.create:
209+
create succeeded: True
210+
format_name is tiff: True
211+
create invalid returns None: True
212+
213+
Testing valid_file and supports:
214+
valid_file good: True
215+
valid_file bad: True
216+
supports returns numeric: True
217+
grid supports mipmap: True
218+
219+
Testing seek_subimage state:
220+
initial sub/mip: 0 0
221+
seek mip 2: True
222+
after seek sub/mip: 0 2
223+
spec(0,2) width: 256
224+
read_image sub/mip/ch ndim: 3
225+
226+
Testing read_native_deep_image:
227+
deep file: True
228+
read_native_deep_image ok: True
229+
deep pixels: 19200 channels: 2
230+
231+
Testing get_thumbnail:
232+
get_thumbnail returns ImageBuf: True
233+
thumbnail initialized: False
234+
235+
Testing has_error/geterror:
236+
scanline on tiled None: True
237+
has_error: True
238+
geterror persists: True
239+
has_error after clear: False
240+
208241
is_imageio_format_name('tiff') = True
209242
is_imageio_format_name('txff') = False
210243
Done.

testsuite/python-imageinput/ref/out.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,39 @@ Testing write and read of TIFF CMYK with auto RGB translation:
205205
[0.24705884 0.49803925 0.49803925]]
206206

207207

208+
Testing ImageInput.create:
209+
create succeeded: True
210+
format_name is tiff: True
211+
create invalid returns None: True
212+
213+
Testing valid_file and supports:
214+
valid_file good: True
215+
valid_file bad: True
216+
supports returns numeric: True
217+
grid supports mipmap: True
218+
219+
Testing seek_subimage state:
220+
initial sub/mip: 0 0
221+
seek mip 2: True
222+
after seek sub/mip: 0 2
223+
spec(0,2) width: 256
224+
read_image sub/mip/ch ndim: 3
225+
226+
Testing read_native_deep_image:
227+
deep file: True
228+
read_native_deep_image ok: True
229+
deep pixels: 19200 channels: 2
230+
231+
Testing get_thumbnail:
232+
get_thumbnail returns ImageBuf: True
233+
thumbnail initialized: False
234+
235+
Testing has_error/geterror:
236+
scanline on tiled None: True
237+
has_error: True
238+
geterror persists: True
239+
has_error after clear: False
240+
208241
is_imageio_format_name('tiff') = True
209242
is_imageio_format_name('txff') = False
210243
Done.

testsuite/python-imageinput/src/test_imageinput.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
OIIO_TESTSUITE_IMAGEDIR = os.getenv('OIIO_TESTSUITE_IMAGEDIR',
1414
'../oiio-images')
15+
OIIO_TESTSUITE_ROOT = os.getenv('OIIO_TESTSUITE_ROOT', '')
1516

1617
# Print the contents of an ImageSpec
1718
def print_imagespec (spec: oiio.ImageSpec, subimage=0, mip=0, msg="") :
@@ -257,6 +258,83 @@ def test_tiff_cmyk() :
257258

258259

259260

261+
def test_imageinput_api () :
262+
print ("Testing ImageInput.create:")
263+
probe = oiio.ImageInput.create ("testu16.tif")
264+
print (" create succeeded:", probe is not None)
265+
if probe :
266+
print (" format_name is tiff:", probe.format_name() == "tiff")
267+
invalid = oiio.ImageInput.create ("no_such_format.zzz")
268+
print (" create invalid returns None:", invalid is None)
269+
oiio.geterror() # clear global error from failed create
270+
print ("")
271+
272+
print ("Testing valid_file and supports:")
273+
tahoe = OIIO_TESTSUITE_IMAGEDIR + "/tahoe-gps.jpg"
274+
ii = oiio.ImageInput.open (tahoe)
275+
assert ii is not None
276+
print (" valid_file good:", ii.valid_file (tahoe))
277+
print (" valid_file bad:", not ii.valid_file ("badname.tif"))
278+
print (" supports returns numeric:",
279+
isinstance (ii.supports ("mipmap"), (int, bool)))
280+
ii.close ()
281+
ii = oiio.ImageInput.open ("grid.tx")
282+
assert ii is not None
283+
print (" grid supports mipmap:", bool (ii.supports ("mipmap")))
284+
ii.close ()
285+
print ("")
286+
287+
print ("Testing seek_subimage state:")
288+
ii = oiio.ImageInput.open ("grid.tx")
289+
assert ii is not None
290+
print (" initial sub/mip:", ii.current_subimage(), ii.current_miplevel())
291+
ok = ii.seek_subimage (0, 2)
292+
print (" seek mip 2:", ok)
293+
print (" after seek sub/mip:", ii.current_subimage(), ii.current_miplevel())
294+
spec_m2 = ii.spec (0, 2)
295+
print (" spec(0,2) width:", spec_m2.width)
296+
data = ii.read_image (0, 2, 0, 2, oiio.UINT8)
297+
print (" read_image sub/mip/ch ndim:",
298+
data.ndim if data is not None else -1)
299+
ii.close ()
300+
print ("")
301+
302+
print ("Testing read_native_deep_image:")
303+
deep_path = OIIO_TESTSUITE_ROOT + "/oiiotool-deep/src/deepalpha.exr"
304+
ii = oiio.ImageInput.open (deep_path)
305+
assert ii is not None
306+
print (" deep file:", ii.spec().deep)
307+
dd = ii.read_native_deep_image ()
308+
print (" read_native_deep_image ok:", dd is not None)
309+
if dd :
310+
print (" deep pixels:", dd.pixels, "channels:", dd.channels)
311+
ii.close ()
312+
print ("")
313+
314+
print ("Testing get_thumbnail:")
315+
ii = oiio.ImageInput.open (OIIO_TESTSUITE_IMAGEDIR + "/tahoe-gps.jpg")
316+
assert ii is not None
317+
thumb = ii.get_thumbnail ()
318+
print (" get_thumbnail returns ImageBuf:", isinstance (thumb, oiio.ImageBuf))
319+
print (" thumbnail initialized:", thumb.initialized)
320+
ii.close ()
321+
print ("")
322+
323+
print ("Testing has_error/geterror:")
324+
ii = oiio.ImageInput.open ("grid.tx")
325+
assert ii is not None
326+
data = ii.read_scanline (0, 0, oiio.UINT8)
327+
print (" scanline on tiled None:", data is None)
328+
print (" has_error:", ii.has_error)
329+
err1 = ii.geterror (clear=False)
330+
err2 = ii.geterror (clear=False)
331+
print (" geterror persists:", len (err1) > 0 and err1 == err2)
332+
ii.geterror (clear=True)
333+
print (" has_error after clear:", ii.has_error)
334+
ii.close ()
335+
print ("")
336+
337+
260338

261339
######################################################################
262340
# main test starts here
@@ -321,6 +399,8 @@ def test_tiff_cmyk() :
321399
test_tiff_remembering_config()
322400
test_tiff_cmyk()
323401

402+
test_imageinput_api ()
403+
324404
# Test is_imageio_format_name
325405
print ("is_imageio_format_name('tiff') =", oiio.is_imageio_format_name('tiff'))
326406
print ("is_imageio_format_name('txff') =", oiio.is_imageio_format_name('txff'))

0 commit comments

Comments
 (0)