From 4c1927049e2f3c4befb38c33496ccca1e18b5bbf Mon Sep 17 00:00:00 2001 From: Francois Keith <keith@lirmm.fr> Date: Tue, 18 Mar 2014 00:08:30 +0100 Subject: [PATCH] Add a working python file to test the interpreter. --- unitTesting/CMakeLists.txt | 2 ++ unitTesting/interpreter-test-runfile.cc | 29 ++++++++++++++++++++++++- unitTesting/test_python_ok.py | 10 +++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 unitTesting/test_python_ok.py diff --git a/unitTesting/CMakeLists.txt b/unitTesting/CMakeLists.txt index 8c7d082..79a32e5 100644 --- a/unitTesting/CMakeLists.txt +++ b/unitTesting/CMakeLists.txt @@ -38,6 +38,8 @@ TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} dynamic-graph-python) ADD_TEST(${EXECUTABLE_NAME} ${EXECUTABLE_NAME}) ADD_CUSTOM_COMMAND(TARGET interpreter-test-runfile POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python_ok.py + ${CMAKE_BINARY_DIR}/unitTesting COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/unitTesting/test_python_error.py ${CMAKE_BINARY_DIR}/unitTesting ) diff --git a/unitTesting/interpreter-test-runfile.cc b/unitTesting/interpreter-test-runfile.cc index 87d5162..e1e5082 100644 --- a/unitTesting/interpreter-test-runfile.cc +++ b/unitTesting/interpreter-test-runfile.cc @@ -1,6 +1,10 @@ // The purpose of this unit test is to check the interpreter::runPythonFile method +#include <cstring> +#include <iostream> + #include "dynamic-graph/python/interpreter.hh" + int main(int argc, char ** argv) { // execute numerous time the same file. @@ -10,11 +14,34 @@ int main(int argc, char ** argv) if (argc > 1) numTest = atoi(argv[1]); + std::string empty_err = ""; dynamicgraph::python::Interpreter interp; for (int i=0; i<numTest; ++i) { - interp.runPythonFile("test_python_error.py"); + interp.runPythonFile("test_python_ok.py", empty_err); + if (empty_err != "") + { + std::cerr << "At iteration " << i << ", the error was not empty:" << std::endl; + std::cerr << " err " << empty_err << std::endl; + return -1; + } + } + + // check that the error remains the same, despite of the number of executions + std::string old_err; + interp.runPythonFile("test_python_error.py", old_err); + std::string new_err = old_err; + for (int i=0; i<numTest; ++i) + { + interp.runPythonFile("test_python_error.py", new_err); + if (old_err != new_err) + { + std::cerr << "At iteration " << i << ", the error changed:" << std::endl; + std::cerr << " old " << old_err << std::endl; + std::cerr << " new " << new_err << std::endl; + return -1; + } } return 0; diff --git a/unitTesting/test_python_ok.py b/unitTesting/test_python_ok.py new file mode 100644 index 0000000..665398b --- /dev/null +++ b/unitTesting/test_python_ok.py @@ -0,0 +1,10 @@ +import sys, os +import re + +pkgConfigPath = os.environ.get("PKG_CONFIG_PATH") +if pkgConfigPath == None: + pkgConfigPath = '' +pathList = re.split(':', pkgConfigPath) + +print pathList + -- GitLab