diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 41b9b5928958ae31799c396a8d77fd7cff557905..957c20bcf603f2f264b4658f63ac0eec438f12b1 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -403,3 +403,16 @@ function(py_proto_compile TARGET_NAME) protobuf_generate_python(py_srcs ${py_proto_compile_SRCS}) add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs}) endfunction() + +function(py_test TARGET_NAME) + if(WITH_TESTING) + set(options STATIC static SHARED shared) + set(oneValueArgs "") + set(multiValueArgs SRCS DEPS) + cmake_parse_arguments(py_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + add_test(NAME ${TARGET_NAME} + COMMAND env PYTHONPATH=${PADDLE_PYTHON_PACKAGE_DIR} + python2 ${py_test_SRCS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + endif() +endfunction() diff --git a/paddle/api/test/CMakeLists.txt b/paddle/api/test/CMakeLists.txt index f3b1c2c4d438b5d3e776ef27ce8f8b78f710f2ab..761aeb5b174105edece8880a9f5012c13a63fd11 100644 --- a/paddle/api/test/CMakeLists.txt +++ b/paddle/api/test/CMakeLists.txt @@ -1,2 +1,6 @@ -add_python_test(test_swig_api - testArguments.py testGradientMachine.py testMatrix.py testVector.py testTrain.py testTrainer.py) +py_test(testTrain SRCS testTrain.py) +py_test(testMatrix SRCS testMatrix.py) +py_test(testVector SRCS testVector.py) +py_test(testTrainer SRCS testTrainer.py) +py_test(testArguments SRCS testArguments.py) +py_test(testGradientMachine SRCS testGradientMachine.py) diff --git a/python/paddle/v2/framework/tests/CMakeLists.txt b/python/paddle/v2/framework/tests/CMakeLists.txt index e66197030e2dd9e113e4564aaacb1c5dab25771b..7eec37678815587b451008eef587b23bcb9beeaf 100644 --- a/python/paddle/v2/framework/tests/CMakeLists.txt +++ b/python/paddle/v2/framework/tests/CMakeLists.txt @@ -1,17 +1,23 @@ -add_python_test(test_framework - test_protobuf.py - test_scope.py - test_default_scope_funcs.py - test_op_creation_methods.py - test_net.py - test_tensor.py - test_fc_op.py - test_add_two_op.py - test_sgd_op.py - test_mul_op.py - test_mean_op.py - test_sigmoid_op.py - test_softmax_op.py - test_rowwise_add_op.py - test_network.py - gradient_checker.py) +py_test(test_net SRCS test_net.py) + +py_test(test_fc_op SRCS test_fc_op.py) +py_test(test_scope SRCS test_scope.py) + +py_test(test_tensor SRCS test_tensor.py) +py_test(test_mul_op SRCS test_mul_op.py) + +py_test(test_network SRCS test_network.py) +py_test(test_mean_op SRCS test_mean_op.py) + +py_test(test_protobuf SRCS test_protobuf.py) + +py_test(test_add_two_op SRCS test_add_two_op.py) +py_test(test_sigmoid_op SRCS test_sigmoid_op.py) +py_test(test_softmax_op SRCS test_softmax_op.py) + +py_test(gradient_checker SRCS gradient_checker.py) + +py_test(test_rowwise_add_op SRCS test_rowwise_add_op.py) + +py_test(test_default_scope_funcs SRCS test_default_scope_funcs.py) +py_test(test_op_creation_methods SRCS test_op_creation_methods.py) diff --git a/python/paddle/v2/plot/tests/CMakeLists.txt b/python/paddle/v2/plot/tests/CMakeLists.txt index da5cd764889b48a3af8461a2793d948aa609d6c1..4b6c1c80969182ccf6e0189b18bade8758bbbc30 100644 --- a/python/paddle/v2/plot/tests/CMakeLists.txt +++ b/python/paddle/v2/plot/tests/CMakeLists.txt @@ -1,5 +1,5 @@ if (NOT APPLE) # The Mac OS X backend will not be able to function correctly if Python is # not installed as a framework. - add_python_test(test_ploter test_ploter.py) + py_test(test_ploter SRCS test_ploter.py) endif() diff --git a/python/paddle/v2/reader/tests/CMakeLists.txt b/python/paddle/v2/reader/tests/CMakeLists.txt index 6a1d337b232c7a849a8793894bf16d26d609d3dd..107d5912e1567e0c8721987a281272c7feb51e63 100644 --- a/python/paddle/v2/reader/tests/CMakeLists.txt +++ b/python/paddle/v2/reader/tests/CMakeLists.txt @@ -1 +1,2 @@ -add_python_test(reader_tests creator_test.py decorator_test.py) +py_test(creator_test SRCS creator_test.py) +py_test(decorator_test SRCS decorator_test.py) diff --git a/python/paddle/v2/tests/CMakeLists.txt b/python/paddle/v2/tests/CMakeLists.txt index 058f22befd0657d06ff130ace55fe7322148213d..b7791559594321a85f41b508b69efeb077d69595 100644 --- a/python/paddle/v2/tests/CMakeLists.txt +++ b/python/paddle/v2/tests/CMakeLists.txt @@ -1,2 +1,7 @@ -add_python_test(test_v2_api test_data_feeder.py test_op.py test_parameters.py -test_layer.py test_rnn_layer.py test_topology.py test_image.py) +py_test(test_op SRCS test_op.py) +py_test(test_image SRCS test_image.py) +py_test(test_layer SRCS test_layer.py) +py_test(test_topology SRCS test_topology.py) +py_test(test_rnn_layer SRCS test_rnn_layer.py) +py_test(test_parameters SRCS test_parameters.py) +py_test(test_data_feeder SRCS test_data_feeder.py)