You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. import pytest
  2. def test_keep_alive_argument(capture):
  3. from pybind11_tests import Parent, Child
  4. with capture:
  5. p = Parent()
  6. assert capture == "Allocating parent."
  7. with capture:
  8. p.addChild(Child())
  9. pytest.gc_collect()
  10. assert capture == """
  11. Allocating child.
  12. Releasing child.
  13. """
  14. with capture:
  15. del p
  16. pytest.gc_collect()
  17. assert capture == "Releasing parent."
  18. with capture:
  19. p = Parent()
  20. assert capture == "Allocating parent."
  21. with capture:
  22. p.addChildKeepAlive(Child())
  23. pytest.gc_collect()
  24. assert capture == "Allocating child."
  25. with capture:
  26. del p
  27. pytest.gc_collect()
  28. assert capture == """
  29. Releasing parent.
  30. Releasing child.
  31. """
  32. def test_keep_alive_return_value(capture):
  33. from pybind11_tests import Parent
  34. with capture:
  35. p = Parent()
  36. assert capture == "Allocating parent."
  37. with capture:
  38. p.returnChild()
  39. pytest.gc_collect()
  40. assert capture == """
  41. Allocating child.
  42. Releasing child.
  43. """
  44. with capture:
  45. del p
  46. pytest.gc_collect()
  47. assert capture == "Releasing parent."
  48. with capture:
  49. p = Parent()
  50. assert capture == "Allocating parent."
  51. with capture:
  52. p.returnChildKeepAlive()
  53. pytest.gc_collect()
  54. assert capture == "Allocating child."
  55. with capture:
  56. del p
  57. pytest.gc_collect()
  58. assert capture == """
  59. Releasing parent.
  60. Releasing child.
  61. """
  62. def test_return_none(capture):
  63. from pybind11_tests import Parent
  64. with capture:
  65. p = Parent()
  66. assert capture == "Allocating parent."
  67. with capture:
  68. p.returnNullChildKeepAliveChild()
  69. pytest.gc_collect()
  70. assert capture == ""
  71. with capture:
  72. del p
  73. pytest.gc_collect()
  74. assert capture == "Releasing parent."
  75. with capture:
  76. p = Parent()
  77. assert capture == "Allocating parent."
  78. with capture:
  79. p.returnNullChildKeepAliveParent()
  80. pytest.gc_collect()
  81. assert capture == ""
  82. with capture:
  83. del p
  84. pytest.gc_collect()
  85. assert capture == "Releasing parent."