pytest-cmake 0.5.1__tar.gz → 0.8.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,11 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pytest-cmake
3
- Version: 0.5.1
3
+ Version: 0.8.4
4
4
  Summary: Provide CMake module for Pytest
5
+ Project-URL: Documentation, https://python-cmake.github.io/pytest-cmake
6
+ Project-URL: Repository, https://github.com/python-cmake/pytest-cmake
7
+ Project-URL: Issues, https://github.com/python-cmake/pytest-cmake/issues
8
+ Project-URL: Changelog, https://python-cmake.github.io/pytest-cmake/release/release_notes.html
5
9
  Author-email: Jeremy Retailleau <jeremy.retailleau@gmail.com>
6
10
  License: MIT License
7
11
 
@@ -45,9 +49,8 @@ Description-Content-Type: text/markdown
45
49
  # Pytest CMake
46
50
 
47
51
  [![PyPi version](https://img.shields.io/pypi/v/pytest-cmake.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.python.org/pypi/pytest-cmake)
48
- [![CMake](https://img.shields.io/badge/CMake-3.20...3.29-blue.svg?logo=CMake&logoColor=blue)](https://cmake.org)
49
- [![Documentation](https://readthedocs.org/projects/pytest-cmake/badge/?version=stable)](https://pytest-cmake.readthedocs.io/en/stable/)
50
- [![Test](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml)
52
+ [![CMake](https://img.shields.io/badge/CMake-3.20...3.30-blue.svg?logo=CMake&logoColor=blue)](https://cmake.org)
53
+ [![Test](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml)
51
54
  [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
52
55
 
53
56
  This project provides convenient ways to use [Pytest](https://docs.pytest.org/)
@@ -57,12 +60,12 @@ versions on Linux, macOS or Windows using the
57
60
  function:
58
61
 
59
62
  ```cmake
60
- find_package(Pytest 4.6.11 REQUIRED)
63
+ find_package(Pytest 8.2.1 REQUIRED)
61
64
  ```
62
65
 
63
66
  A ``pytest_discover_tests`` function is provided to simplify automatic
64
67
  testing for C++ projects with Python bindings. It can create CTest tests
65
- for each Python test collected within a correct environment:
68
+ for each Python test collected within a controlled environment:
66
69
 
67
70
  ```cmake
68
71
  pytest_discover_tests(
@@ -92,4 +95,4 @@ Running the tests will display the status for each test collected as follows:
92
95
  ## Documentation
93
96
 
94
97
  Full documentation, including installation and setup guides, can be found at
95
- https://pytest-cmake.readthedocs.io/en/stable/
98
+ https://python-cmake.github.io/pytest-cmake/
@@ -1,9 +1,8 @@
1
1
  # Pytest CMake
2
2
 
3
3
  [![PyPi version](https://img.shields.io/pypi/v/pytest-cmake.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.python.org/pypi/pytest-cmake)
4
- [![CMake](https://img.shields.io/badge/CMake-3.20...3.29-blue.svg?logo=CMake&logoColor=blue)](https://cmake.org)
5
- [![Documentation](https://readthedocs.org/projects/pytest-cmake/badge/?version=stable)](https://pytest-cmake.readthedocs.io/en/stable/)
6
- [![Test](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml)
4
+ [![CMake](https://img.shields.io/badge/CMake-3.20...3.30-blue.svg?logo=CMake&logoColor=blue)](https://cmake.org)
5
+ [![Test](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml)
7
6
  [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
7
 
9
8
  This project provides convenient ways to use [Pytest](https://docs.pytest.org/)
@@ -13,12 +12,12 @@ versions on Linux, macOS or Windows using the
13
12
  function:
14
13
 
15
14
  ```cmake
16
- find_package(Pytest 4.6.11 REQUIRED)
15
+ find_package(Pytest 8.2.1 REQUIRED)
17
16
  ```
18
17
 
19
18
  A ``pytest_discover_tests`` function is provided to simplify automatic
20
19
  testing for C++ projects with Python bindings. It can create CTest tests
21
- for each Python test collected within a correct environment:
20
+ for each Python test collected within a controlled environment:
22
21
 
23
22
  ```cmake
24
23
  pytest_discover_tests(
@@ -48,4 +47,4 @@ Running the tests will display the status for each test collected as follows:
48
47
  ## Documentation
49
48
 
50
49
  Full documentation, including installation and setup guides, can be found at
51
- https://pytest-cmake.readthedocs.io/en/stable/
50
+ https://python-cmake.github.io/pytest-cmake/
@@ -17,7 +17,7 @@
17
17
  # prepend a custom search path.
18
18
  # (https://cmake.org/cmake/help/latest/policy/CMP0074.html)
19
19
 
20
- cmake_minimum_required(VERSION 3.20...3.29)
20
+ cmake_minimum_required(VERSION 3.20...3.30)
21
21
 
22
22
  include(FindPackageHandleStandardArgs)
23
23
 
@@ -60,50 +60,55 @@ if (Pytest_FOUND AND NOT TARGET Pytest::Pytest)
60
60
  "LIBRARY_PATH_PREPEND;PYTHON_PATH_PREPEND;ENVIRONMENT;DEPENDS"
61
61
  )
62
62
 
63
- # Set library path depending on the platform.
63
+ # Identify library path environment name depending on the platform.
64
64
  if (CMAKE_SYSTEM_NAME STREQUAL Windows)
65
- set(LIB_ENV_PATH PATH)
66
- set(_env_sep "\\\;")
65
+ set(LIBRARY_ENV_NAME PATH)
67
66
  elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
68
- set(LIB_ENV_PATH DYLD_LIBRARY_PATH)
69
- set(_env_sep ":")
67
+ set(LIBRARY_ENV_NAME DYLD_LIBRARY_PATH)
70
68
  else()
71
- set(LIB_ENV_PATH LD_LIBRARY_PATH)
72
- set(_env_sep ":")
69
+ set(LIBRARY_ENV_NAME LD_LIBRARY_PATH)
73
70
  endif()
74
71
 
75
- # Convert all paths into cmake paths.
76
- cmake_path(CONVERT "$ENV{${LIB_ENV_PATH}}" TO_CMAKE_PATH_LIST libpath)
77
- cmake_path(CONVERT "$ENV{PYTHONPATH}" TO_CMAKE_PATH_LIST pythonpath)
72
+ # Sanitize all paths for CMake.
73
+ cmake_path(CONVERT "$ENV{${LIBRARY_ENV_NAME}}" TO_CMAKE_PATH_LIST LIBRARY_PATH)
74
+ cmake_path(CONVERT "$ENV{PYTHONPATH}" TO_CMAKE_PATH_LIST PYTHON_PATH)
78
75
 
79
- # Prepend input path to environment variables
76
+ # Prepend input path to environment variables.
80
77
  if (_LIBRARY_PATH_PREPEND)
81
78
  list(REVERSE _LIBRARY_PATH_PREPEND)
82
79
  foreach (_path ${_LIBRARY_PATH_PREPEND})
83
- set(libpath "${_path}" "${libpath}")
80
+ set(LIBRARY_PATH "${_path}" "${LIBRARY_PATH}")
84
81
  endforeach()
85
82
  endif()
86
83
 
87
84
  if (_PYTHON_PATH_PREPEND)
88
85
  list(REVERSE _PYTHON_PATH_PREPEND)
89
86
  foreach (_path ${_PYTHON_PATH_PREPEND})
90
- set(pythonpath "${_path}" "${pythonpath}")
87
+ set(PYTHON_PATH "${_path}" "${PYTHON_PATH}")
91
88
  endforeach()
92
89
  endif()
93
90
 
94
- # Convert list into string.
95
- list(JOIN libpath "${_env_sep}" libpath)
96
- list(JOIN pythonpath "${_env_sep}" pythonpath)
97
-
91
+ # Default working directory to current build path if none is provided.
98
92
  if (NOT _WORKING_DIRECTORY)
99
93
  set(_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
100
94
  endif()
101
95
 
96
+ get_filename_component(_WORKING_DIRECTORY "${_WORKING_DIRECTORY}" REALPATH)
97
+
102
98
  # Override option by environment variable if available.
103
99
  if (DEFINED ENV{BUNDLE_PYTHON_TESTS})
104
100
  set(_BUNDLE_TESTS $ENV{BUNDLE_PYTHON_TESTS})
105
101
  endif()
106
102
 
103
+ # Serialize environment if necessary.
104
+ set(ENCODED_ENVIRONMENT "")
105
+ foreach(env ${_ENVIRONMENT})
106
+ string(REPLACE [[\]] [\\]] env ${env})
107
+ string(REPLACE [[;]] [\\;]] env ${env})
108
+ list(APPEND ENCODED_ENVIRONMENT ${env})
109
+ endforeach()
110
+
111
+ set(_include_file "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_include.cmake")
107
112
  set(_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_tests.cmake")
108
113
 
109
114
  add_custom_target(
@@ -114,19 +119,27 @@ if (Pytest_FOUND AND NOT TARGET Pytest::Pytest)
114
119
  -D "PYTEST_EXECUTABLE=${PYTEST_EXECUTABLE}"
115
120
  -D "TEST_GROUP_NAME=${NAME}"
116
121
  -D "BUNDLE_TESTS=${_BUNDLE_TESTS}"
117
- -D "LIB_ENV_PATH=${LIB_ENV_PATH}"
118
- -D "LIBRARY_PATH=${libpath}"
119
- -D "PYTHON_PATH=${pythonpath}"
122
+ -D "LIBRARY_ENV_NAME=${LIBRARY_ENV_NAME}"
123
+ -D "LIBRARY_PATH=${LIBRARY_PATH}"
124
+ -D "PYTHON_PATH=${PYTHON_PATH}"
120
125
  -D "TRIM_FROM_NAME=${_TRIM_FROM_NAME}"
121
126
  -D "WORKING_DIRECTORY=${_WORKING_DIRECTORY}"
122
- -D "ENVIRONMENT=${_ENVIRONMENT}"
127
+ -D "ENVIRONMENT=${ENCODED_ENVIRONMENT}"
123
128
  -D "PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}"
124
129
  -D "CTEST_FILE=${_tests_file}"
125
130
  -P "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PytestAddTests.cmake")
126
131
 
132
+ file(WRITE "${_include_file}"
133
+ "if(EXISTS \"${_tests_file}\")\n"
134
+ " include(\"${_tests_file}\")\n"
135
+ "else()\n"
136
+ " add_test(${NAME}_NOT_BUILT ${NAME}_NOT_BUILT)\n"
137
+ "endif()\n"
138
+ )
139
+
127
140
  # Add discovered tests to directory TEST_INCLUDE_FILES
128
141
  set_property(DIRECTORY
129
- APPEND PROPERTY TEST_INCLUDE_FILES "${_tests_file}")
142
+ APPEND PROPERTY TEST_INCLUDE_FILES "${_include_file}")
130
143
 
131
144
  endfunction()
132
145
 
@@ -1,25 +1,32 @@
1
1
  # Wrapper used to create individual CTest tests from Pytest tests.
2
- cmake_minimum_required(VERSION 3.20...3.29)
2
+ cmake_minimum_required(VERSION 3.20...3.30)
3
3
 
4
4
  if(CMAKE_SCRIPT_MODE_FILE)
5
5
 
6
6
  # Set Cmake test file to execute each test.
7
7
  set(_content "")
8
8
 
9
- # Ensure that list environment variables are
10
- # represented as a string on Windows.
11
- string(REPLACE [[;]] [[\;]] LIBRARY_PATH "${LIBRARY_PATH}")
12
- string(REPLACE [[;]] [[\;]] PYTHON_PATH "${PYTHON_PATH}")
9
+ cmake_path(CONVERT "${LIBRARY_PATH}" TO_NATIVE_PATH_LIST LIBRARY_PATH)
10
+ cmake_path(CONVERT "${PYTHON_PATH}" TO_NATIVE_PATH_LIST PYTHON_PATH)
11
+
12
+ # Serialize path values separated by semicolons (required on Windows).
13
+ macro(encode_value VARIABLE_NAME)
14
+ string(REPLACE [[\]] [[\\]] ${VARIABLE_NAME} "${${VARIABLE_NAME}}")
15
+ string(REPLACE [[;]] [[\\;]] ${VARIABLE_NAME} "${${VARIABLE_NAME}}")
16
+ endmacro()
17
+
18
+ encode_value(LIBRARY_PATH)
19
+ encode_value(PYTHON_PATH)
13
20
 
14
21
  if (BUNDLE_TESTS)
15
22
  string(APPEND _content
16
23
  "add_test(\n"
17
24
  " \"${TEST_GROUP_NAME}\"\n"
18
- " ${PYTEST_EXECUTABLE} \"${WORKING_DIRECTORY}\"\n"
25
+ " \"${PYTEST_EXECUTABLE}\" \"${WORKING_DIRECTORY}\"\n"
19
26
  ")\n"
20
27
  "set_tests_properties(\n"
21
28
  " \"${TEST_GROUP_NAME}\" PROPERTIES\n"
22
- " ENVIRONMENT \"${LIB_ENV_PATH}=${LIBRARY_PATH}\"\n"
29
+ " ENVIRONMENT \"${LIBRARY_ENV_NAME}=${LIBRARY_PATH}\"\n"
23
30
  ")\n"
24
31
  "set_tests_properties(\n"
25
32
  " \"${TEST_GROUP_NAME}\"\n"
@@ -40,7 +47,7 @@ if(CMAKE_SCRIPT_MODE_FILE)
40
47
 
41
48
  else()
42
49
  # Set environment for collecting tests.
43
- set(ENV{${LIB_ENV_PATH}} "${LIBRARY_PATH}")
50
+ set(ENV{${LIBRARY_ENV_NAME}} "${LIBRARY_PATH}")
44
51
  set(ENV{PYTHONPATH} "${PYTHON_PATH}")
45
52
  set(ENV{PYTHONWARNINGS} "ignore")
46
53
 
@@ -78,28 +85,29 @@ if(CMAKE_SCRIPT_MODE_FILE)
78
85
  set(_class ${CMAKE_MATCH_3})
79
86
  set(_func ${CMAKE_MATCH_4})
80
87
 
88
+ if (TRIM_FROM_NAME)
89
+ set(pattern "${TRIM_FROM_NAME}")
90
+ string(REGEX REPLACE "${pattern}" "" _class "${_class}")
91
+ string(REGEX REPLACE "${pattern}" "" _func "${_func}")
92
+ endif()
93
+
81
94
  if (_class)
82
95
  set(test_name "${_class}.${_func}")
83
96
  else()
84
97
  set(test_name "${_func}")
85
98
  endif()
86
99
 
87
- if (TRIM_FROM_NAME)
88
- string(REGEX REPLACE
89
- "${TRIM_FROM_NAME}" "" test_name "${test_name}")
90
- endif()
91
-
92
100
  set(test_name "${TEST_GROUP_NAME}.${test_name}")
93
101
  set(test_case "${WORKING_DIRECTORY}/${line}")
94
102
 
95
103
  string(APPEND _content
96
104
  "add_test(\n"
97
105
  " \"${test_name}\"\n"
98
- " ${PYTEST_EXECUTABLE} \"${test_case}\"\n"
106
+ " \"${PYTEST_EXECUTABLE}\" \"${test_case}\"\n"
99
107
  ")\n"
100
108
  "set_tests_properties(\n"
101
109
  " \"${test_name}\" PROPERTIES\n"
102
- " ENVIRONMENT \"${LIB_ENV_PATH}=${LIBRARY_PATH}\"\n"
110
+ " ENVIRONMENT \"${LIBRARY_ENV_NAME}=${LIBRARY_PATH}\"\n"
103
111
  ")\n"
104
112
  "set_tests_properties(\n"
105
113
  " \"${test_name}\"\n"
@@ -2,14 +2,14 @@
2
2
  requires = [
3
3
  "hatchling >= 1.4; python_version >= '3'",
4
4
  "setuptools >= 44; python_version < '3'",
5
- "cmake >= 3.20, < 3.30"
5
+ "cmake >= 3.20, < 3.31"
6
6
  ]
7
7
  build-backend = "build_backend"
8
8
  backend-path = ["."]
9
9
 
10
10
  [project]
11
11
  name = "pytest-cmake"
12
- version = "0.5.1"
12
+ version = "0.8.4"
13
13
  description = "Provide CMake module for Pytest"
14
14
  readme = "README.md"
15
15
  requires-python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4"
@@ -36,6 +36,12 @@ classifiers = [
36
36
  "Programming Language :: Python :: 3.12",
37
37
  ]
38
38
 
39
+ [project.urls]
40
+ Documentation = "https://python-cmake.github.io/pytest-cmake"
41
+ Repository = "https://github.com/python-cmake/pytest-cmake"
42
+ Issues = "https://github.com/python-cmake/pytest-cmake/issues"
43
+ Changelog = "https://python-cmake.github.io/pytest-cmake/release/release_notes.html"
44
+
39
45
  [tool.hatch.build.hooks.custom]
40
46
  require-runtime-dependencies = true
41
47
  path = "build_config.py"
@@ -60,7 +60,7 @@ class CreateCmakeConfig(install):
60
60
 
61
61
  setup(
62
62
  name="pytest-cmake",
63
- version="0.5.1",
63
+ version="0.8.4",
64
64
  data_files=[
65
65
  (
66
66
  "share/Pytest/cmake",
File without changes
File without changes