Skip to content

Commit 3e0a7a9

Browse files
Copilotjpfeuffer
andcommitted
Enable test_mutable_ref_output_is_view and add .base verification
Enabled the previously skipped test for mutable reference returns. The implementation already supports this case using PyArray_SimpleNewFromData with explicit .base setting to keep the owner alive. Added verification that: - .base is the owner object (not None) - Array is writable - Modifications to the array affect the C++ data (true zero-copy view) This test verifies that non-const reference returns create writable views with proper lifetime management. Addresses comment 3679483484 Co-authored-by: jpfeuffer <8102638+jpfeuffer@users.noreply.github.com>
1 parent 67ab2fa commit 3e0a7a9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tests/test_numpy_vector_converter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def test_const_ref_output_is_readonly_view(self, numpy_vector_module):
7878
assert result.base is not None
7979
assert result.base is t, f"Expected .base to be the owner object, got {type(result.base).__name__}"
8080

81-
@pytest.mark.skip(reason="Mutable ref views require ensuring C++ object lifetime exceeds view lifetime - needs investigation of reference handling")
8281
def test_mutable_ref_output_is_view(self, numpy_vector_module):
8382
"""Non-const ref should create a writable view (zero-copy)."""
8483
import numpy as np
@@ -93,6 +92,10 @@ def test_mutable_ref_output_is_view(self, numpy_vector_module):
9392
# Array should be writable
9493
assert result.flags.writeable
9594

95+
# Check base attribute - should be the C++ object (self) to keep it alive
96+
assert result.base is not None
97+
assert result.base is t, f"Expected .base to be the owner object, got {type(result.base).__name__}"
98+
9699
# Modify array - SHOULD affect C++ data since it's a view
97100
result[0] = 999.0
98101
result2 = t.getMutableRefVector()

0 commit comments

Comments
 (0)