From: Sergey BELASH Date: Fri, 18 Jul 2014 09:42:41 +0000 (+0400) Subject: Simplify creation of the unit tests, rename example files according to the style... X-Git-Tag: V_0.4.4~168^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3fca4ad38c2a2567db3b70af06c60b3299682ffe;p=modules%2Fshaper.git Simplify creation of the unit tests, rename example files according to the style guide. --- diff --git a/CMakeCommon/UnitTest.cmake b/CMakeCommon/UnitTest.cmake new file mode 100644 index 000000000..b401edece --- /dev/null +++ b/CMakeCommon/UnitTest.cmake @@ -0,0 +1,47 @@ +# +# NewGeom unit test system +# How to use: +# INCLUDE(UnitTest) +# ... +# ADD_UNIT_TESTS(TestUndoRedo.py +# TestResultBody.py) +# or +# SET(PROJECT_UNIT_TESTS +# TestUndoRedo.py +# TestWhatever.py +# ) +# ADD_UNIT_TESTS(${PROJECT_UNIT_TESTS}) +# +# Where "TestUndoRedo.py" and "TestResultBody.py" are names +# of python test scripts in the "./Test" directory. +# This macro will add "Subproject_" as prefix and +# remove ".py" for the test name automaticaly. +# +# Start building of the "RUN_TESTS" project in the Visual studio +# or run "make test" on linux stations to start the testing procedure. +# + +ENABLE_TESTING() + +MACRO(ADD_UNIT_TESTS) + foreach(eachFileName ${ARGN}) + # Strip the ".py" suffix + GET_FILENAME_COMPONENT(aTestName ${eachFileName} NAME_WE) + + # Add "SubprojectName_" prefix + GET_FILENAME_COMPONENT(aSubprojectName ${CMAKE_CURRENT_SOURCE_DIR} NAME) + SET(aTestName "${aSubprojectName}_${aTestName}") + + # Full path to the python test file beeing executed + SET(aTestFileName "${CMAKE_CURRENT_SOURCE_DIR}/Test/${eachFileName}") + IF(EXISTS ${aTestFileName}) + ADD_TEST(NAME ${aTestName} + COMMAND ${PYTHON_EXECUTABLE} ${aTestFileName}) + # Debug output... + #MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFileName}") + ELSE(EXISTS ${aTestFileName}) + MESSAGE(WARNING "Can not find the test file: ${aTestFileName}") + ENDIF(EXISTS ${aTestFileName}) + endforeach(eachFileName ${ARGN}) +ENDMACRO(ADD_UNIT_TESTS) + diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index 3b4970095..4f632cbc3 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -1,4 +1,5 @@ INCLUDE(Common) +INCLUDE(UnitTest) SET(PROJECT_HEADERS ConstructionPlugin.h @@ -29,5 +30,5 @@ SET(XML_RESOURCES INSTALL(TARGETS ConstructionPlugin DESTINATION plugins) INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) -ENABLE_TESTING() -ADD_SUBDIRECTORY(Test) +ADD_UNIT_TESTS(TestPointName.py + ) diff --git a/src/ConstructionPlugin/Test/CMakeLists.txt b/src/ConstructionPlugin/Test/CMakeLists.txt deleted file mode 100644 index 2fbb8fca7..000000000 --- a/src/ConstructionPlugin/Test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -INCLUDE(Common) - -ENABLE_TESTING() -ADD_TEST(ModelAPITest - ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_point_name.py) diff --git a/src/ConstructionPlugin/Test/TestPointName.py b/src/ConstructionPlugin/Test/TestPointName.py new file mode 100644 index 000000000..06e70e64f --- /dev/null +++ b/src/ConstructionPlugin/Test/TestPointName.py @@ -0,0 +1,11 @@ +from ModelAPI import * +p = ModelAPI_PluginManager.get() +f = p.rootDocument().addFeature("Point") +f_name = f.data().name() +f.execute() + +doc = p.rootDocument() +f1 = doc.object("Construction", 0) +f1_name = f1.data().name() + +assert (f_name == f1_name) diff --git a/src/ConstructionPlugin/Test/test_point_name.py b/src/ConstructionPlugin/Test/test_point_name.py deleted file mode 100644 index 06e70e64f..000000000 --- a/src/ConstructionPlugin/Test/test_point_name.py +++ /dev/null @@ -1,11 +0,0 @@ -from ModelAPI import * -p = ModelAPI_PluginManager.get() -f = p.rootDocument().addFeature("Point") -f_name = f.data().name() -f.execute() - -doc = p.rootDocument() -f1 = doc.object("Construction", 0) -f1_name = f1.data().name() - -assert (f_name == f1_name) diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 883288049..8f02b77ab 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -1,6 +1,7 @@ FIND_PACKAGE(SWIG REQUIRED) INCLUDE(${SWIG_USE_FILE}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE(UnitTest) SET(PROJECT_HEADERS ModelAPI.h @@ -73,5 +74,5 @@ INSTALL(TARGETS _ModelAPI DESTINATION swig) INSTALL(TARGETS ModelAPI DESTINATION bin) INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig) -ENABLE_TESTING() -ADD_SUBDIRECTORY(Test) +ADD_UNIT_TESTS(TestUndoRedo.py + ) diff --git a/src/ModelAPI/Test/CMakeLists.txt b/src/ModelAPI/Test/CMakeLists.txt deleted file mode 100644 index bbab60ee9..000000000 --- a/src/ModelAPI/Test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -INCLUDE(Common) - -ENABLE_TESTING() -ADD_TEST(ModelAPITest - ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_undo.py) diff --git a/src/ModelAPI/Test/TestUndoRedo.py b/src/ModelAPI/Test/TestUndoRedo.py new file mode 100644 index 000000000..74a1315cd --- /dev/null +++ b/src/ModelAPI/Test/TestUndoRedo.py @@ -0,0 +1,26 @@ +from ModelAPI import * +plugin_manager = ModelAPI_PluginManager.get() +doc = plugin_manager.rootDocument() +assert(not doc.canUndo()) +assert(not doc.canRedo()) + +doc.startOperation() +feature = doc.addFeature("Point") +feature_name = feature.data().name() +assert(feature_name == "Point_1") + +feature.execute() +doc.finishOperation(); +assert(doc.size("Construction") == 1) +assert(doc.canUndo()) +assert(not doc.canRedo()) + +doc.undo() +assert(doc.size("Construction") == 0) +assert(not doc.canUndo()) +assert(doc.canRedo()) + +doc.redo() +assert(doc.size("Construction") == 1) +assert(doc.canUndo()) +assert(not doc.canRedo()) diff --git a/src/ModelAPI/Test/test_undo.py b/src/ModelAPI/Test/test_undo.py deleted file mode 100644 index 74a1315cd..000000000 --- a/src/ModelAPI/Test/test_undo.py +++ /dev/null @@ -1,26 +0,0 @@ -from ModelAPI import * -plugin_manager = ModelAPI_PluginManager.get() -doc = plugin_manager.rootDocument() -assert(not doc.canUndo()) -assert(not doc.canRedo()) - -doc.startOperation() -feature = doc.addFeature("Point") -feature_name = feature.data().name() -assert(feature_name == "Point_1") - -feature.execute() -doc.finishOperation(); -assert(doc.size("Construction") == 1) -assert(doc.canUndo()) -assert(not doc.canRedo()) - -doc.undo() -assert(doc.size("Construction") == 0) -assert(not doc.canUndo()) -assert(doc.canRedo()) - -doc.redo() -assert(doc.size("Construction") == 1) -assert(doc.canUndo()) -assert(not doc.canRedo())