Commit b7871b36 authored by Laurent Belcour's avatar Laurent Belcour

[CI] Adding python tests when the interface is built

parent 7f97c5c2
......@@ -79,6 +79,18 @@ function(alta_test)
PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins")
endfunction(alta_test)
function(alta_test_python)
set(options OPTIONAL)
set(oneValueArgs NAME)
set(multiValueArgs COMMAND)
cmake_parse_arguments(TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_test(NAME ${TEST_NAME} COMMAND ${TEST_COMMAND}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
set_tests_properties("${TEST_NAME}"
PROPERTIES ENVIRONMENT "ALTA_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins;PYTHONPATH=${CMAKE_BINARY_DIR}/python")
endfunction(alta_test_function)
function(alta_test_unit name sources)
add_executable(${name} sources/tests/${sources})
target_link_libraries(${name} core)
......@@ -297,6 +309,17 @@ foreach(fitter IN ITEMS ${nonlinear_fitters})
"--func" "[nonlinear_function_diffuse, nonlinear_function_blinn]")
endforeach()
if(PYTHONLIBS_FOUND AND PYBIND_FOUND)
alta_test_python(NAME "python_test_arguments"
COMMAND "python3" "${CMAKE_SOURCE_DIR}/sources/tests/python/test-arguments.py")
alta_test_python(NAME "python_test_vec"
COMMAND "python3" "${CMAKE_SOURCE_DIR}/sources/tests/python/test-vec.py")
alta_test_python(NAME "python_test_function"
COMMAND "python3" "${CMAKE_SOURCE_DIR}/sources/tests/python/test-python-function.py")
endif()
# add a target to generate API documentation with Doxygen
if(DOXYGEN_FOUND)
add_custom_target(doc
......
......@@ -63,7 +63,7 @@ inline void register_vec(py::module& m) {
}))
.def("__add__", &vec_add)
.def("__sub__", &vec_sub)
// .def("__len__", &vec::size)
.def("__len__", &vec::size)
.def("__getitem__", [](const vec &s, unsigned int i) {
if (i >= s.size()) throw py::index_error();
return s[i];
......
......@@ -13,8 +13,8 @@ if args['param'] != 'STARK_2D':
fail = True
if fail:
print "Testing python 'arguments' interface failed!"
print("Testing python 'arguments' interface failed!")
exit(1)
else:
print "Testing python 'arguments' interface passed!"
print("Testing python 'arguments' interface passed!")
exit(0)
......@@ -3,22 +3,22 @@ import sys
# Test a nonlinear_function
# Open a function plugin, then save the function and load it again
print 'Loading a nonlinear_function plugin and testing saving/loading'
print('Loading a nonlinear_function plugin and testing saving/loading')
f1 = alta.get_function('nonlinear_function_diffuse',
alta.parameters(3, 3,
alta.input_parametrization.RUSIN_TH_PH_TD,
alta.output_parametrization.RGB_COLOR))
print "f1 = ", f1
print("f1 = ", f1)
f1.save('test-diffuse.func')
# Test a rational_function
# Open a function plugin, then save the function and load it again
print 'Loading a rational_function plugin and testing saving/loading'
print('Loading a rational_function plugin and testing saving/loading')
f2 = alta.get_function('rational_function_legendre',
alta.parameters(3, 3,
alta.input_parametrization.RUSIN_TH_PH_TD,
alta.output_parametrization.RGB_COLOR))
print "f2 = ", f2
print("f2 = ", f2)
f2.save('test-rat.func')
sys.exit(0)
......@@ -21,7 +21,7 @@ if y[0] != 2.0 and z[0] != 0.0:
fail += 1
# Testing str(vec)
print "Testing 'str' method on variable 'y': " + str(y)
print("Testing 'str' method on variable 'y': " + str(y))
# Testing the length of the vector
if len(y) != 3:
......@@ -44,8 +44,8 @@ for i in range(0,len(y)):
# Print the test result
if fail > 0:
print "Testing python 'vec' interface failed!"
print("Testing python 'vec' interface failed!")
exit(1)
else:
print "Testing python 'vec' interface passed!"
print("Testing python 'vec' interface passed!")
exit(0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment