Skip to content

Commit c48b6ba

Browse files
committed
Added basic python test for ImageConverter bindings
Signed-off-by: hyi18 <ayin@wetafx.co.nz>
1 parent bbb6200 commit c48b6ba

File tree

7 files changed

+103
-3
lines changed

7 files changed

+103
-3
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
shell: bash
6666
run: |
6767
sudo yum install --setopt=tsflags=nodocs -y eigen3-devel ceres-solver-devel json-devel
68-
sudo python -m pip install nanobind
68+
sudo python -m pip install nanobind pytest
6969
7070
- name: Configure CMake
7171
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
@@ -153,7 +153,7 @@ jobs:
153153
shell: bash
154154
run: |
155155
sudo yum install --setopt=tsflags=nodocs -y eigen3-devel ceres-solver-devel json-devel
156-
sudo python -m pip install nanobind
156+
sudo python -m pip install nanobind pytest
157157
158158
- name: Configure CMake
159159
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
build/
33
build-coverage/
4-
tests/materials/*.exr
4+
tests/materials/*.exr
5+
__pycache__/

build_scripts/install_deps_linux.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ time sudo apt-get -q -f install -y \
1010
libopencv-dev \
1111
openimageio-tools libopenimageio-dev \
1212
nanobind-dev
13+
14+
pip3 install pytest

build_scripts/install_deps_mac.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
set -ex
44

55
brew install ceres-solver nlohmann-json openimageio nanobind robin-map
6+
7+
python3 -m pip install --break-system-packages pytest

build_scripts/install_deps_windows.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ vcpkg install \
77
nlohmann-json:x64-windows \
88
openimageio:x64-windows \
99
nanobind:x64-windows
10+
11+
pip install pytest

tests/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,30 @@ target_link_libraries(
200200
setup_test_coverage(Test_ImageConverter)
201201
add_test ( NAME Test_ImageConverter COMMAND Test_ImageConverter )
202202

203+
################################################################################
204+
# Python tests
205+
if(RTA_BUILD_PYTHON_BINDINGS)
206+
if(Python_EXECUTABLE)
207+
add_test(
208+
NAME Test_Python_ImageConverter
209+
COMMAND ${Python_EXECUTABLE} -m pytest ${CMAKE_CURRENT_SOURCE_DIR}/python/test_image_converter.py -v
210+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
211+
)
212+
213+
# Set environment for Python test to find the compiled module
214+
# Handle both single-config (Linux/macOS) and multi-config (Windows) generators
215+
if(WIN32)
216+
set_tests_properties(Test_Python_ImageConverter PROPERTIES
217+
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/bindings/Release;${CMAKE_BINARY_DIR}/src/bindings;$ENV{PYTHONPATH}"
218+
)
219+
else()
220+
set_tests_properties(Test_Python_ImageConverter PROPERTIES
221+
ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/bindings:$ENV{PYTHONPATH}"
222+
)
223+
endif()
224+
endif()
225+
endif()
226+
203227
################################################################################
204228
# Coverage report generation
205229
if( ENABLE_COVERAGE AND COVERAGE_SUPPORTED )
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Copyright Contributors to the rawtoaces Project.
4+
5+
"""
6+
Unit tests for rawtoaces Python bindings - ImageConverter class
7+
"""
8+
9+
import pytest
10+
11+
# The PYTHONPATH should be set by CMake to find the compiled module
12+
# No need to manually add paths here as CMake handles this via environment variables
13+
14+
try:
15+
import rawtoaces
16+
except ImportError as e:
17+
pytest.skip(f"rawtoaces module not found. Build the Python bindings first: {e}", allow_module_level=True)
18+
19+
20+
class TestImageConverter:
21+
"""Test cases for the ImageConverter class"""
22+
23+
def test_converter_creation(self):
24+
"""Test that ImageConverter can be instantiated"""
25+
converter = rawtoaces.ImageConverter()
26+
assert converter is not None
27+
assert isinstance(converter, rawtoaces.ImageConverter)
28+
29+
def test_converter_has_settings(self):
30+
"""Test that ImageConverter has a settings attribute"""
31+
converter = rawtoaces.ImageConverter()
32+
assert hasattr(converter, "settings")
33+
assert converter.settings is not None
34+
35+
def test_converter_has_process_image_method(self):
36+
"""Test that ImageConverter has process_image method"""
37+
converter = rawtoaces.ImageConverter()
38+
assert hasattr(converter, "process_image")
39+
assert callable(converter.process_image)
40+
41+
def test_process_image_with_invalid_path(self):
42+
"""Test process_image with non-existent file returns False"""
43+
converter = rawtoaces.ImageConverter()
44+
result = converter.process_image("/nonexistent/file.txt")
45+
assert result is False
46+
47+
result = converter.process_image("")
48+
assert result is False
49+
50+
51+
class TestSettings:
52+
"""Test cases for the ImageConverter.Settings class"""
53+
54+
def test_settings_creation(self):
55+
"""Test that Settings can be instantiated"""
56+
converter = rawtoaces.ImageConverter()
57+
settings = converter.settings
58+
assert settings is not None
59+
assert isinstance(settings, rawtoaces.ImageConverter.Settings)
60+
61+
def test_settings_direct_creation(self):
62+
"""Test that Settings can be created directly"""
63+
settings = rawtoaces.ImageConverter.Settings()
64+
assert settings is not None
65+
assert isinstance(settings, rawtoaces.ImageConverter.Settings)
66+
67+
68+
if __name__ == "__main__":
69+
pytest.main([__file__])

0 commit comments

Comments
 (0)