Fixed import module for windows and python 3.7
create unit test
This commit is contained in:
committed by
Renato Araujo Oliveira Filho
parent
15b3843172
commit
71e5d8cc31
@@ -39,3 +39,4 @@ set(${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX "${${PROJECT_NAME}_PYTHON_BIN
|
||||
|
||||
include(PySide${PYSIDE_MAJOR_VERSION}ModuleBuild)
|
||||
add_subdirectory(PyKDDockWidgets)
|
||||
add_subdirectory(tests)
|
||||
|
||||
@@ -84,14 +84,16 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.cmake ${CMAKE_CURRENT_BIN
|
||||
install(
|
||||
FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/__init__.py
|
||||
$<TARGET_LINKER_FILE:KDAB::kddockwidgets>
|
||||
$<TARGET_FILE:KDAB::kddockwidgets>
|
||||
DESTINATION
|
||||
${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}
|
||||
)
|
||||
if(NOT WIN32)
|
||||
install(
|
||||
FILES $<TARGET_SONAME_FILE:KDAB::kddockwidgets>
|
||||
DESTINATION ${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}
|
||||
FILES
|
||||
$<TARGET_LINKER_FILE:KDAB::kddockwidgets>
|
||||
$<TARGET_SONAME_FILE:KDAB::kddockwidgets>
|
||||
DESTINATION
|
||||
${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -16,8 +16,14 @@ __all__ = ['KDDockWidgets']
|
||||
|
||||
def setupLibraryPath():
|
||||
package_dir = os.path.abspath(os.path.dirname(__file__))
|
||||
if sys.platform == 'win32':
|
||||
if sys.platform != 'win32':
|
||||
return
|
||||
|
||||
if sys.version_info[0] == 3 and sys.version_info[1] >= 8:
|
||||
os.add_dll_directory(package_dir)
|
||||
return
|
||||
|
||||
os.environ['PATH'] = os.fspath(package_dir) + os.pathsep + os.environ['PATH']
|
||||
|
||||
# Preload PySide libraries to avoid missing libraries while loading KDDockWidgets
|
||||
try:
|
||||
@@ -30,3 +36,15 @@ except Exception:
|
||||
raise
|
||||
|
||||
setupLibraryPath()
|
||||
|
||||
|
||||
#
|
||||
# This file is part of KDDockWidgets.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020-2021 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
|
||||
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||
#
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
40
python/tests/CMakeLists.txt
Normal file
40
python/tests/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
#
|
||||
# This file is part of KDDockWidgets.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020-2021 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
|
||||
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||
#
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.py.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.py @ONLY)
|
||||
|
||||
set(TEST_PYTHONPATH
|
||||
${CMAKE_BINARY_DIR}/python
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
set(TEST_LIBRARYPATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
|
||||
if(WIN32)
|
||||
set(TEST_LIBRARY_VAR "PATH")
|
||||
string(REPLACE "\\" "/" TEST_PYTHONPATH "${TEST_PYTHONPATH}")
|
||||
string(REPLACE "\\" "/" TEST_LIBRARYPATH "${TEST_LIBRARYPATH}")
|
||||
list(JOIN TEST_PYTHONPATH "\\;" TEST_PYTHONPATH)
|
||||
list(JOIN TEST_LIBRARYPATH "\\;" TEST_LIBRARYPATH)
|
||||
else()
|
||||
set(TEST_LIBRARY_VAR "LD_LIBRARY_PATH")
|
||||
list(JOIN TEST_PYTHONPATH ":" TEST_PYTHONPATH)
|
||||
list(JOIN TEST_LIBRARYPATH ":" TEST_LIBRARYPATH)
|
||||
endif()
|
||||
|
||||
set(PYTHON_ENV_COMMON "PYTHONPATH=${TEST_PYTHONPATH};${TEST_LIBRARY_VAR}=${TEST_LIBRARYPATH}")
|
||||
|
||||
file(GLOB TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tst_*.py)
|
||||
foreach(test_file ${TEST_FILES})
|
||||
get_filename_component(test_name ${test_file} NAME_WE)
|
||||
add_test(${test_name} ${Python3_EXECUTABLE} ${test_file})
|
||||
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "${PYTHON_ENV_COMMON}")
|
||||
endforeach()
|
||||
|
||||
2
python/tests/config.py.cmake
Normal file
2
python/tests/config.py.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
class TstConfig(object):
|
||||
bindingsNamespace = "@PYTHON_BINDING_NAMESPACE@"
|
||||
19
python/tests/tst_importModule.py
Normal file
19
python/tests/tst_importModule.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import unittest
|
||||
import importlib
|
||||
import inspect
|
||||
|
||||
from config import TstConfig
|
||||
|
||||
class TestImportModules(unittest.TestCase):
|
||||
def test_importModules(self):
|
||||
m = importlib.import_module(TstConfig.bindingsNamespace + '.KDDockWidgets')
|
||||
moduleSymbols = []
|
||||
for t in inspect.getmembers(m):
|
||||
moduleSymbols.append(t[0])
|
||||
|
||||
symbols = ['MainWindow', 'DockWidget']
|
||||
for symbol in symbols:
|
||||
self.assertIn(symbol, moduleSymbols)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user