diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index dbce2de736..5772ca8d76 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -1777,3 +1777,22 @@ macro(ocv_git_describe var_name path) set(${var_name} "unknown") endif() endmacro() + + +# ocv_update_file(filepath content [VERBOSE]) +# - write content to file +# - will not change modification time in case when file already exists and content has not changed +function(ocv_update_file filepath content) + if(EXISTS "${filepath}") + file(READ "${filepath}" actual_content) + else() + set(actual_content "") + endif() + if("${actual_content}" STREQUAL "${content}") + if(";${ARGN};" MATCHES ";VERBOSE;") + message(STATUS "${filepath} contains the same content") + endif() + else() + file(WRITE "${filepath}" "${content}") + endif() +endfunction() diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index ed94e46317..1619466be8 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -15,7 +15,7 @@ if(DOXYGEN_FOUND) # not documented modules list set(blacklist "${DOXYGEN_BLACKLIST}") - list(APPEND blacklist "ts" "java_bindings_generator" "java" "python_bindings_generator" "python2" "python3" "js" "world") + list(APPEND blacklist "ts" "world") unset(CMAKE_DOXYGEN_TUTORIAL_CONTRIB_ROOT) unset(CMAKE_DOXYGEN_TUTORIAL_JS_ROOT) @@ -32,7 +32,16 @@ if(DOXYGEN_FOUND) set(refs_extra) set(deps) foreach(m ${OPENCV_MODULES_MAIN} ${OPENCV_MODULES_EXTRA}) + set(the_module "${m}") + if(NOT the_module MATCHES "^opencv_") + set(the_module "opencv_${m}") + endif() list(FIND blacklist ${m} _pos) + if(NOT EXISTS "${OPENCV_MODULE_${the_module}_LOCATION}/include" + AND NOT EXISTS "${OPENCV_MODULE_${the_module}_LOCATION}/doc" + ) + set(_pos -2) # blacklist + endif() if(${_pos} EQUAL -1) list(APPEND CMAKE_DOXYGEN_ENABLED_SECTIONS "HAVE_opencv_${m}") # include folder diff --git a/modules/python/test/test_calibration.py b/modules/calib3d/misc/python/test/test_calibration.py similarity index 100% rename from modules/python/test/test_calibration.py rename to modules/calib3d/misc/python/test/test_calibration.py diff --git a/modules/python/test/test_dnn.py b/modules/dnn/misc/python/test/test_dnn.py similarity index 100% rename from modules/python/test/test_dnn.py rename to modules/dnn/misc/python/test/test_dnn.py diff --git a/modules/python/test/test_feature_homography.py b/modules/features2d/misc/python/test/test_feature_homography.py similarity index 100% rename from modules/python/test/test_feature_homography.py rename to modules/features2d/misc/python/test/test_feature_homography.py diff --git a/modules/python/test/test_digits.py b/modules/ml/misc/python/test/test_digits.py similarity index 100% rename from modules/python/test/test_digits.py rename to modules/ml/misc/python/test/test_digits.py diff --git a/modules/python/test/test_goodfeatures.py b/modules/ml/misc/python/test/test_goodfeatures.py similarity index 100% rename from modules/python/test/test_goodfeatures.py rename to modules/ml/misc/python/test/test_goodfeatures.py diff --git a/modules/python/test/test_letter_recog.py b/modules/ml/misc/python/test/test_letter_recog.py similarity index 100% rename from modules/python/test/test_letter_recog.py rename to modules/ml/misc/python/test/test_letter_recog.py diff --git a/modules/python/test/test_facedetect.py b/modules/objdetect/misc/python/test/test_facedetect.py similarity index 100% rename from modules/python/test/test_facedetect.py rename to modules/objdetect/misc/python/test/test_facedetect.py diff --git a/modules/python/test/test_peopledetect.py b/modules/objdetect/misc/python/test/test_peopledetect.py similarity index 100% rename from modules/python/test/test_peopledetect.py rename to modules/objdetect/misc/python/test/test_peopledetect.py diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index fbf01d6e82..616f500c95 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -18,6 +18,8 @@ endif() add_subdirectory(bindings) +add_subdirectory(test) + if(NOT OPENCV_SKIP_PYTHON_LOADER) include("./python_loader.cmake") message(STATUS "OpenCV Python: during development append to PYTHONPATH: ${CMAKE_BINARY_DIR}/python_loader") diff --git a/modules/python/test/CMakeLists.txt b/modules/python/test/CMakeLists.txt new file mode 100644 index 0000000000..eced4ecf77 --- /dev/null +++ b/modules/python/test/CMakeLists.txt @@ -0,0 +1,32 @@ +set(MODULE_NAME "python_tests") +set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE) +ocv_add_module(${MODULE_NAME} INTERNAL) + +set(OPENCV_PYTHON_TESTS_CONFIG_FILE_DIR "${OpenCV_BINARY_DIR}" CACHE INTERNAL "") +set(OPENCV_PYTHON_TESTS_CONFIG_FILE "${OPENCV_PYTHON_TESTS_CONFIG_FILE_DIR}/opencv_python_tests.cfg" CACHE INTERNAL "") + +# get list of modules to wrap +set(OPENCV_PYTHON_MODULES) +foreach(m ${OPENCV_MODULES_BUILD}) + if(";${OPENCV_MODULE_${m}_WRAPPERS};" MATCHES ";python.*;" AND HAVE_${m}) + list(APPEND OPENCV_PYTHON_MODULES ${m}) + #message(STATUS "\t${m}") + endif() +endforeach() + +file(RELATIVE_PATH __loc_relative "${OPENCV_PYTHON_TESTS_CONFIG_FILE_DIR}" "${CMAKE_CURRENT_LIST_DIR}") +set(opencv_tests_locations "${__loc_relative}") +foreach(m ${OPENCV_PYTHON_MODULES}) + set(__loc "${OPENCV_MODULE_${m}_LOCATION}/misc/python/test") + if(EXISTS "${__loc}") + file(RELATIVE_PATH __loc_relative "${OPENCV_PYTHON_TESTS_CONFIG_FILE_DIR}" "${__loc}") + list(APPEND opencv_tests_locations "${__loc_relative}") + endif() +endforeach(m) + +string(REPLACE ";" "\n" opencv_tests_locations_ "${opencv_tests_locations}") +ocv_update_file("${OPENCV_PYTHON_TESTS_CONFIG_FILE}" "${opencv_tests_locations_}") + +# +# TODO: Install rules (with test data?) +# diff --git a/modules/python/test/test.py b/modules/python/test/test.py index 249a354636..97c2144303 100755 --- a/modules/python/test/test.py +++ b/modules/python/test/test.py @@ -1,4 +1,9 @@ #!/usr/bin/env python +''' +Location of tests: +- /modules/python/test +- /modules//misc/python/test/ +''' from __future__ import print_function @@ -20,7 +25,35 @@ from tests_common import NewOpenCVTests basedir = os.path.abspath(os.path.dirname(__file__)) def load_tests(loader, tests, pattern): - tests.addTests(loader.discover(basedir, pattern=os.environ.get('OPENCV_PYTEST_FILTER', 'test_') + '*.py')) + cwd = os.getcwd() + config_file = 'opencv_python_tests.cfg' + locations = [cwd, basedir] + if os.path.exists(config_file): + with open(config_file, 'r') as f: + locations += [str(s).strip() for s in f.readlines()] + else: + print('WARNING: OpenCV tests config file ({}) is missing, running subset of tests'.format(config_file)) + + tests_pattern = os.environ.get('OPENCV_PYTEST_FILTER', 'test_') + '*.py' + if tests_pattern != 'test_*py': + print('Tests filter: {}'.format(tests_pattern)) + + processed = set() + for l in locations: + if not os.path.isabs(l): + l = os.path.normpath(os.path.join(cwd, l)) + if l in processed: + continue + processed.add(l) + print('Discovering python tests from: {}'.format(l)) + sys_path_modify = l not in sys.path + if sys_path_modify: + sys.path.append(l) # Hack python loader + discovered_tests = loader.discover(l, pattern=tests_pattern, top_level_dir=l) + print(' found {} tests'.format(discovered_tests.countTestCases())) + tests.addTests(loader.discover(l, pattern=tests_pattern)) + if sys_path_modify: + sys.path.remove(l) return tests if __name__ == '__main__': diff --git a/modules/python/test/test_shape.py b/modules/shape/misc/python/test/test_shape.py similarity index 100% rename from modules/python/test/test_shape.py rename to modules/shape/misc/python/test/test_shape.py diff --git a/modules/python/test/test_stitching.py b/modules/stitching/misc/python/test/test_stitching.py similarity index 100% rename from modules/python/test/test_stitching.py rename to modules/stitching/misc/python/test/test_stitching.py diff --git a/modules/python/test/test_lk_homography.py b/modules/video/misc/python/test/test_lk_homography.py similarity index 100% rename from modules/python/test/test_lk_homography.py rename to modules/video/misc/python/test/test_lk_homography.py diff --git a/modules/python/test/test_lk_track.py b/modules/video/misc/python/test/test_lk_track.py similarity index 100% rename from modules/python/test/test_lk_track.py rename to modules/video/misc/python/test/test_lk_track.py diff --git a/modules/python/test/test_videoio.py b/modules/videoio/misc/python/test/test_videoio.py similarity index 100% rename from modules/python/test/test_videoio.py rename to modules/videoio/misc/python/test/test_videoio.py