Skip to content

Commit

Permalink
Add deprecated image python API tests back
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Jul 10, 2023
1 parent ca5f525 commit 0c0b191
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ list(APPEND pyf3dTests_list
TestPythonUtils.py
)

if(NOT F3D_EXCLUDE_DEPRECATED)
list(APPEND pyf3dTests_list
TestPythonImageDataDeprecated.py)
endif()

if(NOT F3D_MACOS_BUNDLE)
list(APPEND pyf3dTests_list
TestPythonPlugins.py
Expand Down
55 changes: 55 additions & 0 deletions python/testing/TestPythonImageDataDeprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import sys
if sys.platform.startswith('win32'):
import os
os.add_dll_directory(sys.argv[1])

import f3d

engine = f3d.engine(f3d.window.NATIVE_OFFSCREEN)
window = engine.getWindow()
window.setSize(300, 200)


'''with background -> RGB image'''

img = window.renderToImage()
width = img.getWidth()
height = img.getHeight()
depth = img.getChannelCount()
data = img.getData()

assert width == window.getWidth()
assert height == window.getHeight()
assert depth == 3
assert isinstance(data, (bytes, bytearray))
assert len(data) == depth * width * height


'''without background -> RGBA image'''

img = window.renderToImage(True)
width = img.getWidth()
height = img.getHeight()
depth = img.getChannelCount()
data = img.getData()

assert width == window.getWidth()
assert height == window.getHeight()
assert depth == 4
assert isinstance(data, (bytes, bytearray))
assert len(data) == depth * width * height


'''set data back'''

img.setData(data)
assert img.getData() == data


'''attempt to set partial data back'''

try:
img.setData(data[:-1])
assert False, 'expected exception'
except ValueError:
assert True

0 comments on commit 0c0b191

Please sign in to comment.