xcoll 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

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.

Potentially problematic release.


This version of xcoll might be problematic. Click here for more details.

Files changed (324) hide show
  1. xcoll/__init__.py +2 -1
  2. xcoll/beam_elements/__init__.py +7 -1
  3. xcoll/beam_elements/absorber.py +2 -2
  4. xcoll/beam_elements/base.py +105 -67
  5. xcoll/beam_elements/blowup.py +198 -0
  6. xcoll/beam_elements/{collimators_src → elements_src}/black_absorber.h +21 -3
  7. xcoll/beam_elements/{collimators_src → elements_src}/black_crystal.h +20 -2
  8. xcoll/beam_elements/elements_src/blowup.h +42 -0
  9. xcoll/beam_elements/elements_src/emittance_monitor.h +109 -0
  10. xcoll/beam_elements/{collimators_src → elements_src}/everest_block.h +19 -2
  11. xcoll/beam_elements/{collimators_src → elements_src}/everest_collimator.h +19 -3
  12. xcoll/beam_elements/{collimators_src → elements_src}/everest_crystal.h +30 -9
  13. xcoll/beam_elements/everest.py +5 -6
  14. xcoll/beam_elements/monitor.py +428 -0
  15. xcoll/colldb.py +103 -74
  16. xcoll/general.py +4 -4
  17. xcoll/initial_distribution.py +18 -6
  18. xcoll/install.py +3 -1
  19. xcoll/interaction_record/interaction_record.py +126 -80
  20. xcoll/interaction_record/interaction_record_src/interaction_record.h +43 -43
  21. xcoll/line_tools.py +8 -9
  22. xcoll/lossmap.py +48 -38
  23. xcoll/scattering_routines/everest/amorphous.h +4 -11
  24. xcoll/scattering_routines/everest/channeling.h +3 -8
  25. xcoll/scattering_routines/everest/everest.h +4 -1
  26. xcoll/scattering_routines/everest/jaw.h +4 -3
  27. xcoll/scattering_routines/everest/materials.py +35 -15
  28. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
  29. xcoll/scattering_routines/everest/nuclear_interaction.h +1 -1
  30. xcoll/scattering_routines/everest/properties.h +6 -1
  31. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  32. xcoll/scattering_routines/geant4/collimasim/.git +1 -0
  33. xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
  34. xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
  35. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
  36. xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
  37. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
  38. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
  39. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
  40. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
  41. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
  42. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
  43. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
  44. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
  45. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
  46. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
  47. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
  48. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
  49. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
  50. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
  51. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
  52. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
  53. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
  54. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
  55. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
  275. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
  276. xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
  277. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
  278. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
  279. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
  280. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
  281. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
  282. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
  283. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
  284. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
  285. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
  286. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
  287. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
  288. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
  289. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
  290. xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
  291. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
  292. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
  293. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
  294. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
  295. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
  296. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
  297. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
  298. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
  299. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
  300. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
  301. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
  302. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
  303. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
  304. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
  305. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
  306. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
  307. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
  308. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
  309. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
  310. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
  311. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
  312. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
  313. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
  314. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
  315. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
  316. xcoll/scattering_routines/geometry/collimator_geometry.h +9 -10
  317. xcoll/scattering_routines/geometry/crystal_geometry.h +9 -6
  318. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
  319. xcoll-0.5.0.dist-info/RECORD +413 -0
  320. xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
  321. xcoll-0.4.0.dist-info/RECORD +0 -126
  322. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
  323. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
  324. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,473 @@
1
+ # -*- coding: utf-8 -*-
2
+ import pytest
3
+
4
+ import env # noqa: F401
5
+ from pybind11_tests import ConstructorStats, UserType
6
+ from pybind11_tests import class_ as m
7
+
8
+
9
+ def test_repr():
10
+ # In Python 3.3+, repr() accesses __qualname__
11
+ assert "pybind11_type" in repr(type(UserType))
12
+ assert "UserType" in repr(UserType)
13
+
14
+
15
+ def test_instance(msg):
16
+ with pytest.raises(TypeError) as excinfo:
17
+ m.NoConstructor()
18
+ assert msg(excinfo.value) == "m.class_.NoConstructor: No constructor defined!"
19
+
20
+ instance = m.NoConstructor.new_instance()
21
+
22
+ cstats = ConstructorStats.get(m.NoConstructor)
23
+ assert cstats.alive() == 1
24
+ del instance
25
+ assert cstats.alive() == 0
26
+
27
+
28
+ def test_instance_new(msg):
29
+ instance = m.NoConstructorNew() # .__new__(m.NoConstructor.__class__)
30
+ cstats = ConstructorStats.get(m.NoConstructorNew)
31
+ assert cstats.alive() == 1
32
+ del instance
33
+ assert cstats.alive() == 0
34
+
35
+
36
+ def test_type():
37
+ assert m.check_type(1) == m.DerivedClass1
38
+ with pytest.raises(RuntimeError) as execinfo:
39
+ m.check_type(0)
40
+
41
+ assert "pybind11::detail::get_type_info: unable to find type info" in str(
42
+ execinfo.value
43
+ )
44
+ assert "Invalid" in str(execinfo.value)
45
+
46
+ # Currently not supported
47
+ # See https://github.com/pybind/pybind11/issues/2486
48
+ # assert m.check_type(2) == int
49
+
50
+
51
+ def test_type_of_py():
52
+ assert m.get_type_of(1) == int
53
+ assert m.get_type_of(m.DerivedClass1()) == m.DerivedClass1
54
+ assert m.get_type_of(int) == type
55
+
56
+
57
+ def test_type_of_classic():
58
+ assert m.get_type_classic(1) == int
59
+ assert m.get_type_classic(m.DerivedClass1()) == m.DerivedClass1
60
+ assert m.get_type_classic(int) == type
61
+
62
+
63
+ def test_type_of_py_nodelete():
64
+ # If the above test deleted the class, this will segfault
65
+ assert m.get_type_of(m.DerivedClass1()) == m.DerivedClass1
66
+
67
+
68
+ def test_as_type_py():
69
+ assert m.as_type(int) == int
70
+
71
+ with pytest.raises(TypeError):
72
+ assert m.as_type(1) == int
73
+
74
+ with pytest.raises(TypeError):
75
+ assert m.as_type(m.DerivedClass1()) == m.DerivedClass1
76
+
77
+
78
+ def test_docstrings(doc):
79
+ assert doc(UserType) == "A `py::class_` type for testing"
80
+ assert UserType.__name__ == "UserType"
81
+ assert UserType.__module__ == "pybind11_tests"
82
+ assert UserType.get_value.__name__ == "get_value"
83
+ assert UserType.get_value.__module__ == "pybind11_tests"
84
+
85
+ assert (
86
+ doc(UserType.get_value)
87
+ == """
88
+ get_value(self: m.UserType) -> int
89
+
90
+ Get value using a method
91
+ """
92
+ )
93
+ assert doc(UserType.value) == "Get/set value using a property"
94
+
95
+ assert (
96
+ doc(m.NoConstructor.new_instance)
97
+ == """
98
+ new_instance() -> m.class_.NoConstructor
99
+
100
+ Return an instance
101
+ """
102
+ )
103
+
104
+
105
+ def test_qualname(doc):
106
+ """Tests that a properly qualified name is set in __qualname__ (even in pre-3.3, where we
107
+ backport the attribute) and that generated docstrings properly use it and the module name"""
108
+ assert m.NestBase.__qualname__ == "NestBase"
109
+ assert m.NestBase.Nested.__qualname__ == "NestBase.Nested"
110
+
111
+ assert (
112
+ doc(m.NestBase.__init__)
113
+ == """
114
+ __init__(self: m.class_.NestBase) -> None
115
+ """
116
+ )
117
+ assert (
118
+ doc(m.NestBase.g)
119
+ == """
120
+ g(self: m.class_.NestBase, arg0: m.class_.NestBase.Nested) -> None
121
+ """
122
+ )
123
+ assert (
124
+ doc(m.NestBase.Nested.__init__)
125
+ == """
126
+ __init__(self: m.class_.NestBase.Nested) -> None
127
+ """
128
+ )
129
+ assert (
130
+ doc(m.NestBase.Nested.fn)
131
+ == """
132
+ fn(self: m.class_.NestBase.Nested, arg0: int, arg1: m.class_.NestBase, arg2: m.class_.NestBase.Nested) -> None
133
+ """ # noqa: E501 line too long
134
+ )
135
+ assert (
136
+ doc(m.NestBase.Nested.fa)
137
+ == """
138
+ fa(self: m.class_.NestBase.Nested, a: int, b: m.class_.NestBase, c: m.class_.NestBase.Nested) -> None
139
+ """ # noqa: E501 line too long
140
+ )
141
+ assert m.NestBase.__module__ == "pybind11_tests.class_"
142
+ assert m.NestBase.Nested.__module__ == "pybind11_tests.class_"
143
+
144
+
145
+ def test_inheritance(msg):
146
+ roger = m.Rabbit("Rabbit")
147
+ assert roger.name() + " is a " + roger.species() == "Rabbit is a parrot"
148
+ assert m.pet_name_species(roger) == "Rabbit is a parrot"
149
+
150
+ polly = m.Pet("Polly", "parrot")
151
+ assert polly.name() + " is a " + polly.species() == "Polly is a parrot"
152
+ assert m.pet_name_species(polly) == "Polly is a parrot"
153
+
154
+ molly = m.Dog("Molly")
155
+ assert molly.name() + " is a " + molly.species() == "Molly is a dog"
156
+ assert m.pet_name_species(molly) == "Molly is a dog"
157
+
158
+ fred = m.Hamster("Fred")
159
+ assert fred.name() + " is a " + fred.species() == "Fred is a rodent"
160
+
161
+ assert m.dog_bark(molly) == "Woof!"
162
+
163
+ with pytest.raises(TypeError) as excinfo:
164
+ m.dog_bark(polly)
165
+ assert (
166
+ msg(excinfo.value)
167
+ == """
168
+ dog_bark(): incompatible function arguments. The following argument types are supported:
169
+ 1. (arg0: m.class_.Dog) -> str
170
+
171
+ Invoked with: <m.class_.Pet object at 0>
172
+ """
173
+ )
174
+
175
+ with pytest.raises(TypeError) as excinfo:
176
+ m.Chimera("lion", "goat")
177
+ assert "No constructor defined!" in str(excinfo.value)
178
+
179
+
180
+ def test_inheritance_init(msg):
181
+
182
+ # Single base
183
+ class Python(m.Pet):
184
+ def __init__(self):
185
+ pass
186
+
187
+ with pytest.raises(TypeError) as exc_info:
188
+ Python()
189
+ expected = "m.class_.Pet.__init__() must be called when overriding __init__"
190
+ assert msg(exc_info.value) == expected
191
+
192
+ # Multiple bases
193
+ class RabbitHamster(m.Rabbit, m.Hamster):
194
+ def __init__(self):
195
+ m.Rabbit.__init__(self, "RabbitHamster")
196
+
197
+ with pytest.raises(TypeError) as exc_info:
198
+ RabbitHamster()
199
+ expected = "m.class_.Hamster.__init__() must be called when overriding __init__"
200
+ assert msg(exc_info.value) == expected
201
+
202
+
203
+ def test_automatic_upcasting():
204
+ assert type(m.return_class_1()).__name__ == "DerivedClass1"
205
+ assert type(m.return_class_2()).__name__ == "DerivedClass2"
206
+ assert type(m.return_none()).__name__ == "NoneType"
207
+ # Repeat these a few times in a random order to ensure no invalid caching is applied
208
+ assert type(m.return_class_n(1)).__name__ == "DerivedClass1"
209
+ assert type(m.return_class_n(2)).__name__ == "DerivedClass2"
210
+ assert type(m.return_class_n(0)).__name__ == "BaseClass"
211
+ assert type(m.return_class_n(2)).__name__ == "DerivedClass2"
212
+ assert type(m.return_class_n(2)).__name__ == "DerivedClass2"
213
+ assert type(m.return_class_n(0)).__name__ == "BaseClass"
214
+ assert type(m.return_class_n(1)).__name__ == "DerivedClass1"
215
+
216
+
217
+ def test_isinstance():
218
+ objects = [tuple(), dict(), m.Pet("Polly", "parrot")] + [m.Dog("Molly")] * 4
219
+ expected = (True, True, True, True, True, False, False)
220
+ assert m.check_instances(objects) == expected
221
+
222
+
223
+ def test_mismatched_holder():
224
+ import re
225
+
226
+ with pytest.raises(RuntimeError) as excinfo:
227
+ m.mismatched_holder_1()
228
+ assert re.match(
229
+ 'generic_type: type ".*MismatchDerived1" does not have a non-default '
230
+ 'holder type while its base ".*MismatchBase1" does',
231
+ str(excinfo.value),
232
+ )
233
+
234
+ with pytest.raises(RuntimeError) as excinfo:
235
+ m.mismatched_holder_2()
236
+ assert re.match(
237
+ 'generic_type: type ".*MismatchDerived2" has a non-default holder type '
238
+ 'while its base ".*MismatchBase2" does not',
239
+ str(excinfo.value),
240
+ )
241
+
242
+
243
+ def test_override_static():
244
+ """#511: problem with inheritance + overwritten def_static"""
245
+ b = m.MyBase.make()
246
+ d1 = m.MyDerived.make2()
247
+ d2 = m.MyDerived.make()
248
+
249
+ assert isinstance(b, m.MyBase)
250
+ assert isinstance(d1, m.MyDerived)
251
+ assert isinstance(d2, m.MyDerived)
252
+
253
+
254
+ def test_implicit_conversion_life_support():
255
+ """Ensure the lifetime of temporary objects created for implicit conversions"""
256
+ assert m.implicitly_convert_argument(UserType(5)) == 5
257
+ assert m.implicitly_convert_variable(UserType(5)) == 5
258
+
259
+ assert "outside a bound function" in m.implicitly_convert_variable_fail(UserType(5))
260
+
261
+
262
+ def test_operator_new_delete(capture):
263
+ """Tests that class-specific operator new/delete functions are invoked"""
264
+
265
+ class SubAliased(m.AliasedHasOpNewDelSize):
266
+ pass
267
+
268
+ with capture:
269
+ a = m.HasOpNewDel()
270
+ b = m.HasOpNewDelSize()
271
+ d = m.HasOpNewDelBoth()
272
+ assert (
273
+ capture
274
+ == """
275
+ A new 8
276
+ B new 4
277
+ D new 32
278
+ """
279
+ )
280
+ sz_alias = str(m.AliasedHasOpNewDelSize.size_alias)
281
+ sz_noalias = str(m.AliasedHasOpNewDelSize.size_noalias)
282
+ with capture:
283
+ c = m.AliasedHasOpNewDelSize()
284
+ c2 = SubAliased()
285
+ assert capture == ("C new " + sz_noalias + "\n" + "C new " + sz_alias + "\n")
286
+
287
+ with capture:
288
+ del a
289
+ pytest.gc_collect()
290
+ del b
291
+ pytest.gc_collect()
292
+ del d
293
+ pytest.gc_collect()
294
+ assert (
295
+ capture
296
+ == """
297
+ A delete
298
+ B delete 4
299
+ D delete
300
+ """
301
+ )
302
+
303
+ with capture:
304
+ del c
305
+ pytest.gc_collect()
306
+ del c2
307
+ pytest.gc_collect()
308
+ assert capture == ("C delete " + sz_noalias + "\n" + "C delete " + sz_alias + "\n")
309
+
310
+
311
+ def test_bind_protected_functions():
312
+ """Expose protected member functions to Python using a helper class"""
313
+ a = m.ProtectedA()
314
+ assert a.foo() == 42
315
+
316
+ b = m.ProtectedB()
317
+ assert b.foo() == 42
318
+
319
+ class C(m.ProtectedB):
320
+ def __init__(self):
321
+ m.ProtectedB.__init__(self)
322
+
323
+ def foo(self):
324
+ return 0
325
+
326
+ c = C()
327
+ assert c.foo() == 0
328
+
329
+
330
+ def test_brace_initialization():
331
+ """Tests that simple POD classes can be constructed using C++11 brace initialization"""
332
+ a = m.BraceInitialization(123, "test")
333
+ assert a.field1 == 123
334
+ assert a.field2 == "test"
335
+
336
+ # Tests that a non-simple class doesn't get brace initialization (if the
337
+ # class defines an initializer_list constructor, in particular, it would
338
+ # win over the expected constructor).
339
+ b = m.NoBraceInitialization([123, 456])
340
+ assert b.vec == [123, 456]
341
+
342
+
343
+ @pytest.mark.xfail("env.PYPY")
344
+ def test_class_refcount():
345
+ """Instances must correctly increase/decrease the reference count of their types (#1029)"""
346
+ from sys import getrefcount
347
+
348
+ class PyDog(m.Dog):
349
+ pass
350
+
351
+ for cls in m.Dog, PyDog:
352
+ refcount_1 = getrefcount(cls)
353
+ molly = [cls("Molly") for _ in range(10)]
354
+ refcount_2 = getrefcount(cls)
355
+
356
+ del molly
357
+ pytest.gc_collect()
358
+ refcount_3 = getrefcount(cls)
359
+
360
+ assert refcount_1 == refcount_3
361
+ assert refcount_2 > refcount_1
362
+
363
+
364
+ def test_reentrant_implicit_conversion_failure(msg):
365
+ # ensure that there is no runaway reentrant implicit conversion (#1035)
366
+ with pytest.raises(TypeError) as excinfo:
367
+ m.BogusImplicitConversion(0)
368
+ assert (
369
+ msg(excinfo.value)
370
+ == """
371
+ __init__(): incompatible constructor arguments. The following argument types are supported:
372
+ 1. m.class_.BogusImplicitConversion(arg0: m.class_.BogusImplicitConversion)
373
+
374
+ Invoked with: 0
375
+ """
376
+ )
377
+
378
+
379
+ def test_error_after_conversions():
380
+ with pytest.raises(TypeError) as exc_info:
381
+ m.test_error_after_conversions("hello")
382
+ assert str(exc_info.value).startswith(
383
+ "Unable to convert function return value to a Python type!"
384
+ )
385
+
386
+
387
+ def test_aligned():
388
+ if hasattr(m, "Aligned"):
389
+ p = m.Aligned().ptr()
390
+ assert p % 1024 == 0
391
+
392
+
393
+ # https://foss.heptapod.net/pypy/pypy/-/issues/2742
394
+ @pytest.mark.xfail("env.PYPY")
395
+ def test_final():
396
+ with pytest.raises(TypeError) as exc_info:
397
+
398
+ class PyFinalChild(m.IsFinal):
399
+ pass
400
+
401
+ assert str(exc_info.value).endswith("is not an acceptable base type")
402
+
403
+
404
+ # https://foss.heptapod.net/pypy/pypy/-/issues/2742
405
+ @pytest.mark.xfail("env.PYPY")
406
+ def test_non_final_final():
407
+ with pytest.raises(TypeError) as exc_info:
408
+
409
+ class PyNonFinalFinalChild(m.IsNonFinalFinal):
410
+ pass
411
+
412
+ assert str(exc_info.value).endswith("is not an acceptable base type")
413
+
414
+
415
+ # https://github.com/pybind/pybind11/issues/1878
416
+ def test_exception_rvalue_abort():
417
+ with pytest.raises(RuntimeError):
418
+ m.PyPrintDestructor().throw_something()
419
+
420
+
421
+ # https://github.com/pybind/pybind11/issues/1568
422
+ def test_multiple_instances_with_same_pointer(capture):
423
+ n = 100
424
+ instances = [m.SamePointer() for _ in range(n)]
425
+ for i in range(n):
426
+ # We need to reuse the same allocated memory for with a different type,
427
+ # to ensure the bug in `deregister_instance_impl` is detected. Otherwise
428
+ # `Py_TYPE(self) == Py_TYPE(it->second)` will still succeed, even though
429
+ # the `instance` is already deleted.
430
+ instances[i] = m.Empty()
431
+ # No assert: if this does not trigger the error
432
+ # pybind11_fail("pybind11_object_dealloc(): Tried to deallocate unregistered instance!");
433
+ # and just completes without crashing, we're good.
434
+
435
+
436
+ # https://github.com/pybind/pybind11/issues/1624
437
+ def test_base_and_derived_nested_scope():
438
+ assert issubclass(m.DerivedWithNested, m.BaseWithNested)
439
+ assert m.BaseWithNested.Nested != m.DerivedWithNested.Nested
440
+ assert m.BaseWithNested.Nested.get_name() == "BaseWithNested::Nested"
441
+ assert m.DerivedWithNested.Nested.get_name() == "DerivedWithNested::Nested"
442
+
443
+
444
+ def test_register_duplicate_class():
445
+ import types
446
+
447
+ module_scope = types.ModuleType("module_scope")
448
+ with pytest.raises(RuntimeError) as exc_info:
449
+ m.register_duplicate_class_name(module_scope)
450
+ expected = (
451
+ 'generic_type: cannot initialize type "Duplicate": '
452
+ "an object with that name is already defined"
453
+ )
454
+ assert str(exc_info.value) == expected
455
+ with pytest.raises(RuntimeError) as exc_info:
456
+ m.register_duplicate_class_type(module_scope)
457
+ expected = 'generic_type: type "YetAnotherDuplicate" is already registered!'
458
+ assert str(exc_info.value) == expected
459
+
460
+ class ClassScope:
461
+ pass
462
+
463
+ with pytest.raises(RuntimeError) as exc_info:
464
+ m.register_duplicate_nested_class_name(ClassScope)
465
+ expected = (
466
+ 'generic_type: cannot initialize type "DuplicateNested": '
467
+ "an object with that name is already defined"
468
+ )
469
+ assert str(exc_info.value) == expected
470
+ with pytest.raises(RuntimeError) as exc_info:
471
+ m.register_duplicate_nested_class_type(ClassScope)
472
+ expected = 'generic_type: type "YetAnotherDuplicateNested" is already registered!'
473
+ assert str(exc_info.value) == expected
@@ -0,0 +1,84 @@
1
+ # Built-in in CMake 3.5+
2
+ include(CMakeParseArguments)
3
+
4
+ add_custom_target(test_cmake_build)
5
+
6
+ function(pybind11_add_build_test name)
7
+ cmake_parse_arguments(ARG "INSTALL" "" "" ${ARGN})
8
+
9
+ set(build_options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
10
+
11
+ if(PYBIND11_FINDPYTHON)
12
+ list(APPEND build_options "-DPYBIND11_FINDPYTHON=${PYBIND11_FINDPYTHON}")
13
+
14
+ if(DEFINED Python_ROOT_DIR)
15
+ list(APPEND build_options "-DPython_ROOT_DIR=${Python_ROOT_DIR}")
16
+ endif()
17
+
18
+ list(APPEND build_options "-DPython_EXECUTABLE=${Python_EXECUTABLE}")
19
+ else()
20
+ list(APPEND build_options "-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")
21
+ endif()
22
+
23
+ if(DEFINED CMAKE_CXX_STANDARD)
24
+ list(APPEND build_options "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
25
+ endif()
26
+
27
+ if(NOT ARG_INSTALL)
28
+ list(APPEND build_options "-Dpybind11_SOURCE_DIR=${pybind11_SOURCE_DIR}")
29
+ else()
30
+ list(APPEND build_options "-DCMAKE_PREFIX_PATH=${pybind11_BINARY_DIR}/mock_install")
31
+ endif()
32
+
33
+ add_custom_target(
34
+ test_build_${name}
35
+ ${CMAKE_CTEST_COMMAND}
36
+ --build-and-test
37
+ "${CMAKE_CURRENT_SOURCE_DIR}/${name}"
38
+ "${CMAKE_CURRENT_BINARY_DIR}/${name}"
39
+ --build-config
40
+ Release
41
+ --build-noclean
42
+ --build-generator
43
+ ${CMAKE_GENERATOR}
44
+ $<$<BOOL:${CMAKE_GENERATOR_PLATFORM}>:--build-generator-platform>
45
+ ${CMAKE_GENERATOR_PLATFORM}
46
+ --build-makeprogram
47
+ ${CMAKE_MAKE_PROGRAM}
48
+ --build-target
49
+ check_${name}
50
+ --build-options
51
+ ${build_options})
52
+ if(ARG_INSTALL)
53
+ add_dependencies(test_build_${name} mock_install)
54
+ endif()
55
+ add_dependencies(test_cmake_build test_build_${name})
56
+ endfunction()
57
+
58
+ possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)
59
+
60
+ pybind11_add_build_test(subdirectory_function)
61
+ pybind11_add_build_test(subdirectory_target)
62
+ if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy")
63
+ message(STATUS "Skipping embed test on PyPy")
64
+ else()
65
+ pybind11_add_build_test(subdirectory_embed)
66
+ endif()
67
+
68
+ if(PYBIND11_INSTALL)
69
+ add_custom_target(
70
+ mock_install ${CMAKE_COMMAND} "-DCMAKE_INSTALL_PREFIX=${pybind11_BINARY_DIR}/mock_install" -P
71
+ "${pybind11_BINARY_DIR}/cmake_install.cmake")
72
+
73
+ pybind11_add_build_test(installed_function INSTALL)
74
+ pybind11_add_build_test(installed_target INSTALL)
75
+ if(NOT ("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy"
76
+ ))
77
+ pybind11_add_build_test(installed_embed INSTALL)
78
+ endif()
79
+ endif()
80
+
81
+ add_dependencies(check test_cmake_build)
82
+
83
+ add_subdirectory(subdirectory_target EXCLUDE_FROM_ALL)
84
+ add_subdirectory(subdirectory_embed EXCLUDE_FROM_ALL)
@@ -0,0 +1,21 @@
1
+ #include <pybind11/embed.h>
2
+ namespace py = pybind11;
3
+
4
+ PYBIND11_EMBEDDED_MODULE(test_cmake_build, m) {
5
+ m.def("add", [](int i, int j) { return i + j; });
6
+ }
7
+
8
+ int main(int argc, char *argv[]) {
9
+ if (argc != 2)
10
+ throw std::runtime_error("Expected test.py file as the first argument");
11
+ auto test_py_file = argv[1];
12
+
13
+ py::scoped_interpreter guard{};
14
+
15
+ auto m = py::module_::import("test_cmake_build");
16
+ if (m.attr("add")(1, 2).cast<int>() != 3)
17
+ throw std::runtime_error("embed.cpp failed");
18
+
19
+ py::module_::import("sys").attr("argv") = py::make_tuple("test.py", "embed.cpp");
20
+ py::eval_file(test_py_file, py::globals());
21
+ }
@@ -0,0 +1,28 @@
1
+ cmake_minimum_required(VERSION 3.4)
2
+
3
+ # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with
4
+ # some versions of VS that have a patched CMake 3.11. This forces us to emulate
5
+ # the behavior using the following workaround:
6
+ if(${CMAKE_VERSION} VERSION_LESS 3.18)
7
+ cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
8
+ else()
9
+ cmake_policy(VERSION 3.18)
10
+ endif()
11
+
12
+ project(test_installed_embed CXX)
13
+
14
+ find_package(pybind11 CONFIG REQUIRED)
15
+ message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
16
+
17
+ add_executable(test_installed_embed ../embed.cpp)
18
+ target_link_libraries(test_installed_embed PRIVATE pybind11::embed)
19
+ set_target_properties(test_installed_embed PROPERTIES OUTPUT_NAME test_cmake_build)
20
+
21
+ # Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::embed).
22
+ # This may be needed to resolve header conflicts, e.g. between Python release and debug headers.
23
+ set_target_properties(test_installed_embed PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
24
+
25
+ add_custom_target(
26
+ check_installed_embed
27
+ $<TARGET_FILE:test_installed_embed> ${PROJECT_SOURCE_DIR}/../test.py
28
+ DEPENDS test_installed_embed)
@@ -0,0 +1,39 @@
1
+ cmake_minimum_required(VERSION 3.4)
2
+ project(test_installed_module CXX)
3
+
4
+ # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with
5
+ # some versions of VS that have a patched CMake 3.11. This forces us to emulate
6
+ # the behavior using the following workaround:
7
+ if(${CMAKE_VERSION} VERSION_LESS 3.18)
8
+ cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
9
+ else()
10
+ cmake_policy(VERSION 3.18)
11
+ endif()
12
+
13
+ project(test_installed_function CXX)
14
+
15
+ find_package(pybind11 CONFIG REQUIRED)
16
+ message(
17
+ STATUS "Found pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}: ${pybind11_INCLUDE_DIRS}")
18
+
19
+ pybind11_add_module(test_installed_function SHARED NO_EXTRAS ../main.cpp)
20
+ set_target_properties(test_installed_function PROPERTIES OUTPUT_NAME test_cmake_build)
21
+
22
+ if(DEFINED Python_EXECUTABLE)
23
+ set(_Python_EXECUTABLE "${Python_EXECUTABLE}")
24
+ elseif(DEFINED PYTHON_EXECUTABLE)
25
+ set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
26
+ else()
27
+ message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)")
28
+ endif()
29
+
30
+ add_custom_target(
31
+ check_installed_function
32
+ ${CMAKE_COMMAND}
33
+ -E
34
+ env
35
+ PYTHONPATH=$<TARGET_FILE_DIR:test_installed_function>
36
+ ${_Python_EXECUTABLE}
37
+ ${PROJECT_SOURCE_DIR}/../test.py
38
+ ${PROJECT_NAME}
39
+ DEPENDS test_installed_function)
@@ -0,0 +1,46 @@
1
+ cmake_minimum_required(VERSION 3.4)
2
+
3
+ # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with
4
+ # some versions of VS that have a patched CMake 3.11. This forces us to emulate
5
+ # the behavior using the following workaround:
6
+ if(${CMAKE_VERSION} VERSION_LESS 3.18)
7
+ cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
8
+ else()
9
+ cmake_policy(VERSION 3.18)
10
+ endif()
11
+
12
+ project(test_installed_target CXX)
13
+
14
+ find_package(pybind11 CONFIG REQUIRED)
15
+ message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
16
+
17
+ add_library(test_installed_target MODULE ../main.cpp)
18
+
19
+ target_link_libraries(test_installed_target PRIVATE pybind11::module)
20
+ set_target_properties(test_installed_target PROPERTIES OUTPUT_NAME test_cmake_build)
21
+
22
+ # Make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib
23
+ pybind11_extension(test_installed_target)
24
+
25
+ # Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::module).
26
+ # This may be needed to resolve header conflicts, e.g. between Python release and debug headers.
27
+ set_target_properties(test_installed_target PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
28
+
29
+ if(DEFINED Python_EXECUTABLE)
30
+ set(_Python_EXECUTABLE "${Python_EXECUTABLE}")
31
+ elseif(DEFINED PYTHON_EXECUTABLE)
32
+ set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
33
+ else()
34
+ message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)")
35
+ endif()
36
+
37
+ add_custom_target(
38
+ check_installed_target
39
+ ${CMAKE_COMMAND}
40
+ -E
41
+ env
42
+ PYTHONPATH=$<TARGET_FILE_DIR:test_installed_target>
43
+ ${_Python_EXECUTABLE}
44
+ ${PROJECT_SOURCE_DIR}/../test.py
45
+ ${PROJECT_NAME}
46
+ DEPENDS test_installed_target)
@@ -0,0 +1,6 @@
1
+ #include <pybind11/pybind11.h>
2
+ namespace py = pybind11;
3
+
4
+ PYBIND11_MODULE(test_cmake_build, m) {
5
+ m.def("add", [](int i, int j) { return i + j; });
6
+ }