mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
chore: move to Ruff and add rules (#4483)
This commit is contained in:
@@ -263,79 +263,96 @@ def test_eigen_return_references():
|
||||
primary = np.ones((10, 10))
|
||||
a = m.ReturnTester()
|
||||
a_get1 = a.get()
|
||||
assert not a_get1.flags.owndata and a_get1.flags.writeable
|
||||
assert not a_get1.flags.owndata
|
||||
assert a_get1.flags.writeable
|
||||
assign_both(a_get1, primary, 3, 3, 5)
|
||||
a_get2 = a.get_ptr()
|
||||
assert not a_get2.flags.owndata and a_get2.flags.writeable
|
||||
assert not a_get2.flags.owndata
|
||||
assert a_get2.flags.writeable
|
||||
assign_both(a_get1, primary, 2, 3, 6)
|
||||
|
||||
a_view1 = a.view()
|
||||
assert not a_view1.flags.owndata and not a_view1.flags.writeable
|
||||
assert not a_view1.flags.owndata
|
||||
assert not a_view1.flags.writeable
|
||||
with pytest.raises(ValueError):
|
||||
a_view1[2, 3] = 4
|
||||
a_view2 = a.view_ptr()
|
||||
assert not a_view2.flags.owndata and not a_view2.flags.writeable
|
||||
assert not a_view2.flags.owndata
|
||||
assert not a_view2.flags.writeable
|
||||
with pytest.raises(ValueError):
|
||||
a_view2[2, 3] = 4
|
||||
|
||||
a_copy1 = a.copy_get()
|
||||
assert a_copy1.flags.owndata and a_copy1.flags.writeable
|
||||
assert a_copy1.flags.owndata
|
||||
assert a_copy1.flags.writeable
|
||||
np.testing.assert_array_equal(a_copy1, primary)
|
||||
a_copy1[7, 7] = -44 # Shouldn't affect anything else
|
||||
c1want = array_copy_but_one(primary, 7, 7, -44)
|
||||
a_copy2 = a.copy_view()
|
||||
assert a_copy2.flags.owndata and a_copy2.flags.writeable
|
||||
assert a_copy2.flags.owndata
|
||||
assert a_copy2.flags.writeable
|
||||
np.testing.assert_array_equal(a_copy2, primary)
|
||||
a_copy2[4, 4] = -22 # Shouldn't affect anything else
|
||||
c2want = array_copy_but_one(primary, 4, 4, -22)
|
||||
|
||||
a_ref1 = a.ref()
|
||||
assert not a_ref1.flags.owndata and a_ref1.flags.writeable
|
||||
assert not a_ref1.flags.owndata
|
||||
assert a_ref1.flags.writeable
|
||||
assign_both(a_ref1, primary, 1, 1, 15)
|
||||
a_ref2 = a.ref_const()
|
||||
assert not a_ref2.flags.owndata and not a_ref2.flags.writeable
|
||||
assert not a_ref2.flags.owndata
|
||||
assert not a_ref2.flags.writeable
|
||||
with pytest.raises(ValueError):
|
||||
a_ref2[5, 5] = 33
|
||||
a_ref3 = a.ref_safe()
|
||||
assert not a_ref3.flags.owndata and a_ref3.flags.writeable
|
||||
assert not a_ref3.flags.owndata
|
||||
assert a_ref3.flags.writeable
|
||||
assign_both(a_ref3, primary, 0, 7, 99)
|
||||
a_ref4 = a.ref_const_safe()
|
||||
assert not a_ref4.flags.owndata and not a_ref4.flags.writeable
|
||||
assert not a_ref4.flags.owndata
|
||||
assert not a_ref4.flags.writeable
|
||||
with pytest.raises(ValueError):
|
||||
a_ref4[7, 0] = 987654321
|
||||
|
||||
a_copy3 = a.copy_ref()
|
||||
assert a_copy3.flags.owndata and a_copy3.flags.writeable
|
||||
assert a_copy3.flags.owndata
|
||||
assert a_copy3.flags.writeable
|
||||
np.testing.assert_array_equal(a_copy3, primary)
|
||||
a_copy3[8, 1] = 11
|
||||
c3want = array_copy_but_one(primary, 8, 1, 11)
|
||||
a_copy4 = a.copy_ref_const()
|
||||
assert a_copy4.flags.owndata and a_copy4.flags.writeable
|
||||
assert a_copy4.flags.owndata
|
||||
assert a_copy4.flags.writeable
|
||||
np.testing.assert_array_equal(a_copy4, primary)
|
||||
a_copy4[8, 4] = 88
|
||||
c4want = array_copy_but_one(primary, 8, 4, 88)
|
||||
|
||||
a_block1 = a.block(3, 3, 2, 2)
|
||||
assert not a_block1.flags.owndata and a_block1.flags.writeable
|
||||
assert not a_block1.flags.owndata
|
||||
assert a_block1.flags.writeable
|
||||
a_block1[0, 0] = 55
|
||||
primary[3, 3] = 55
|
||||
a_block2 = a.block_safe(2, 2, 3, 2)
|
||||
assert not a_block2.flags.owndata and a_block2.flags.writeable
|
||||
assert not a_block2.flags.owndata
|
||||
assert a_block2.flags.writeable
|
||||
a_block2[2, 1] = -123
|
||||
primary[4, 3] = -123
|
||||
a_block3 = a.block_const(6, 7, 4, 3)
|
||||
assert not a_block3.flags.owndata and not a_block3.flags.writeable
|
||||
assert not a_block3.flags.owndata
|
||||
assert not a_block3.flags.writeable
|
||||
with pytest.raises(ValueError):
|
||||
a_block3[2, 2] = -44444
|
||||
|
||||
a_copy5 = a.copy_block(2, 2, 2, 3)
|
||||
assert a_copy5.flags.owndata and a_copy5.flags.writeable
|
||||
assert a_copy5.flags.owndata
|
||||
assert a_copy5.flags.writeable
|
||||
np.testing.assert_array_equal(a_copy5, primary[2:4, 2:5])
|
||||
a_copy5[1, 1] = 777
|
||||
c5want = array_copy_but_one(primary[2:4, 2:5], 1, 1, 777)
|
||||
|
||||
a_corn1 = a.corners()
|
||||
assert not a_corn1.flags.owndata and a_corn1.flags.writeable
|
||||
assert not a_corn1.flags.owndata
|
||||
assert a_corn1.flags.writeable
|
||||
a_corn1 *= 50
|
||||
a_corn1[1, 1] = 999
|
||||
primary[0, 0] = 50
|
||||
@@ -343,7 +360,8 @@ def test_eigen_return_references():
|
||||
primary[9, 0] = 50
|
||||
primary[9, 9] = 999
|
||||
a_corn2 = a.corners_const()
|
||||
assert not a_corn2.flags.owndata and not a_corn2.flags.writeable
|
||||
assert not a_corn2.flags.owndata
|
||||
assert not a_corn2.flags.writeable
|
||||
with pytest.raises(ValueError):
|
||||
a_corn2[1, 0] = 51
|
||||
|
||||
@@ -503,10 +521,14 @@ def test_numpy_ref_mutators():
|
||||
|
||||
assert [zc[1, 2], zcro[1, 2], zr[1, 2], zrro[1, 2]] == [23] * 4
|
||||
|
||||
assert not zc.flags.owndata and zc.flags.writeable
|
||||
assert not zr.flags.owndata and zr.flags.writeable
|
||||
assert not zcro.flags.owndata and not zcro.flags.writeable
|
||||
assert not zrro.flags.owndata and not zrro.flags.writeable
|
||||
assert not zc.flags.owndata
|
||||
assert zc.flags.writeable
|
||||
assert not zr.flags.owndata
|
||||
assert zr.flags.writeable
|
||||
assert not zcro.flags.owndata
|
||||
assert not zcro.flags.writeable
|
||||
assert not zrro.flags.owndata
|
||||
assert not zrro.flags.writeable
|
||||
|
||||
zc[1, 2] = 99
|
||||
expect = np.array([[11.0, 12, 13], [21, 22, 99], [31, 32, 33]])
|
||||
@@ -530,7 +552,8 @@ def test_numpy_ref_mutators():
|
||||
# the const should drop away)
|
||||
y1 = np.array(m.get_cm_const_ref())
|
||||
|
||||
assert y1.flags.owndata and y1.flags.writeable
|
||||
assert y1.flags.owndata
|
||||
assert y1.flags.writeable
|
||||
# We should get copies of the eigen data, which was modified above:
|
||||
assert y1[1, 2] == 99
|
||||
y1[1, 2] += 12
|
||||
@@ -603,38 +626,38 @@ def test_nocopy_wrapper():
|
||||
# All but the second should fail with m.get_elem_nocopy:
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.get_elem_nocopy(int_matrix_colmajor)
|
||||
assert "get_elem_nocopy(): incompatible function arguments." in str(
|
||||
excinfo.value
|
||||
) and ", flags.f_contiguous" in str(excinfo.value)
|
||||
assert "get_elem_nocopy(): incompatible function arguments." in str(excinfo.value)
|
||||
assert ", flags.f_contiguous" in str(excinfo.value)
|
||||
assert m.get_elem_nocopy(dbl_matrix_colmajor) == 8
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.get_elem_nocopy(int_matrix_rowmajor)
|
||||
assert "get_elem_nocopy(): incompatible function arguments." in str(
|
||||
excinfo.value
|
||||
) and ", flags.f_contiguous" in str(excinfo.value)
|
||||
assert "get_elem_nocopy(): incompatible function arguments." in str(excinfo.value)
|
||||
assert ", flags.f_contiguous" in str(excinfo.value)
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.get_elem_nocopy(dbl_matrix_rowmajor)
|
||||
assert "get_elem_nocopy(): incompatible function arguments." in str(
|
||||
excinfo.value
|
||||
) and ", flags.f_contiguous" in str(excinfo.value)
|
||||
assert "get_elem_nocopy(): incompatible function arguments." in str(excinfo.value)
|
||||
assert ", flags.f_contiguous" in str(excinfo.value)
|
||||
|
||||
# For the row-major test, we take a long matrix in row-major, so only the third is allowed:
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.get_elem_rm_nocopy(int_matrix_colmajor)
|
||||
assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
|
||||
excinfo.value
|
||||
) and ", flags.c_contiguous" in str(excinfo.value)
|
||||
)
|
||||
assert ", flags.c_contiguous" in str(excinfo.value)
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.get_elem_rm_nocopy(dbl_matrix_colmajor)
|
||||
assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
|
||||
excinfo.value
|
||||
) and ", flags.c_contiguous" in str(excinfo.value)
|
||||
)
|
||||
assert ", flags.c_contiguous" in str(excinfo.value)
|
||||
assert m.get_elem_rm_nocopy(int_matrix_rowmajor) == 8
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.get_elem_rm_nocopy(dbl_matrix_rowmajor)
|
||||
assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
|
||||
excinfo.value
|
||||
) and ", flags.c_contiguous" in str(excinfo.value)
|
||||
)
|
||||
assert ", flags.c_contiguous" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_eigen_ref_life_support():
|
||||
|
||||
Reference in New Issue
Block a user