From 7ecdf6ad9321a00ca469f827839e03eb44df8367 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 7 Aug 2017 11:26:28 +0800 Subject: [PATCH] Add py_test --- cmake/generic.cmake | 13 ++++++ paddle/api/test/CMakeLists.txt | 8 +++- .../paddle/v2/framework/tests/CMakeLists.txt | 40 +++++++++++-------- python/paddle/v2/plot/tests/CMakeLists.txt | 2 +- python/paddle/v2/reader/tests/CMakeLists.txt | 3 +- python/paddle/v2/tests/CMakeLists.txt | 9 ++++- 6 files changed, 52 insertions(+), 23 deletions(-) diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 41b9b59289..957c20bcf6 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 f3b1c2c4d4..761aeb5b17 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 e66197030e..7eec376788 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 da5cd76488..4b6c1c8096 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 6a1d337b23..107d5912e1 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 058f22befd..b779155959 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) -- GitLab