2016-08-29 01:41:05 +00:00
|
|
|
import pytest
|
|
|
|
|
2020-08-16 20:02:12 +00:00
|
|
|
import env # noqa: F401
|
|
|
|
from pybind11_tests import numpy_array as m
|
2017-01-24 16:26:51 +00:00
|
|
|
|
2020-08-16 20:02:12 +00:00
|
|
|
np = pytest.importorskip("numpy")
|
2016-08-29 01:41:05 +00:00
|
|
|
|
|
|
|
|
2018-03-20 20:55:29 +00:00
|
|
|
def test_dtypes():
|
|
|
|
# See issue #1328.
|
|
|
|
# - Platform-dependent sizes.
|
|
|
|
for size_check in m.get_platform_dtype_size_checks():
|
|
|
|
print(size_check)
|
|
|
|
assert size_check.size_cpp == size_check.size_numpy, size_check
|
|
|
|
# - Concrete sizes.
|
|
|
|
for check in m.get_concrete_dtype_checks():
|
|
|
|
print(check)
|
|
|
|
assert check.numpy == check.pybind11, check
|
|
|
|
if check.numpy.num != check.pybind11.num:
|
2020-10-16 20:38:13 +00:00
|
|
|
print(
|
2022-02-12 00:06:16 +00:00
|
|
|
f"NOTE: typenum mismatch for {check}: {check.numpy.num} != {check.pybind11.num}"
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2018-03-20 20:55:29 +00:00
|
|
|
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
@pytest.fixture(scope="function")
|
2016-09-08 22:03:35 +00:00
|
|
|
def arr():
|
2020-10-16 20:38:13 +00:00
|
|
|
return np.array([[1, 2, 3], [4, 5, 6]], "=u2")
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
2016-08-29 01:41:05 +00:00
|
|
|
def test_array_attributes():
|
2020-10-16 20:38:13 +00:00
|
|
|
a = np.array(0, "f8")
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.ndim(a) == 0
|
|
|
|
assert all(m.shape(a) == [])
|
|
|
|
assert all(m.strides(a) == [])
|
2016-09-08 22:03:35 +00:00
|
|
|
with pytest.raises(IndexError) as excinfo:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.shape(a, 0)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "invalid axis: 0 (ndim = 0)"
|
2016-09-08 22:03:35 +00:00
|
|
|
with pytest.raises(IndexError) as excinfo:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.strides(a, 0)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "invalid axis: 0 (ndim = 0)"
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.writeable(a)
|
|
|
|
assert m.size(a) == 1
|
|
|
|
assert m.itemsize(a) == 8
|
|
|
|
assert m.nbytes(a) == 8
|
|
|
|
assert m.owndata(a)
|
2016-08-29 01:41:05 +00:00
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
a = np.array([[1, 2, 3], [4, 5, 6]], "u2").view()
|
2016-08-29 01:41:05 +00:00
|
|
|
a.flags.writeable = False
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.ndim(a) == 2
|
|
|
|
assert all(m.shape(a) == [2, 3])
|
|
|
|
assert m.shape(a, 0) == 2
|
|
|
|
assert m.shape(a, 1) == 3
|
|
|
|
assert all(m.strides(a) == [6, 2])
|
|
|
|
assert m.strides(a, 0) == 6
|
|
|
|
assert m.strides(a, 1) == 2
|
2016-09-08 22:03:35 +00:00
|
|
|
with pytest.raises(IndexError) as excinfo:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.shape(a, 2)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "invalid axis: 2 (ndim = 2)"
|
2016-09-08 22:03:35 +00:00
|
|
|
with pytest.raises(IndexError) as excinfo:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.strides(a, 2)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "invalid axis: 2 (ndim = 2)"
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert not m.writeable(a)
|
|
|
|
assert m.size(a) == 6
|
|
|
|
assert m.itemsize(a) == 2
|
|
|
|
assert m.nbytes(a) == 12
|
|
|
|
assert not m.owndata(a)
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"args, ret", [([], 0), ([0], 0), ([1], 3), ([0, 1], 1), ([1, 2], 5)]
|
|
|
|
)
|
2016-09-08 22:03:35 +00:00
|
|
|
def test_index_offset(arr, args, ret):
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.index_at(arr, *args) == ret
|
|
|
|
assert m.index_at_t(arr, *args) == ret
|
|
|
|
assert m.offset_at(arr, *args) == ret * arr.dtype.itemsize
|
|
|
|
assert m.offset_at_t(arr, *args) == ret * arr.dtype.itemsize
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_dim_check_fail(arr):
|
2020-10-16 20:38:13 +00:00
|
|
|
for func in (
|
|
|
|
m.index_at,
|
|
|
|
m.index_at_t,
|
|
|
|
m.offset_at,
|
|
|
|
m.offset_at_t,
|
|
|
|
m.data,
|
|
|
|
m.data_t,
|
|
|
|
m.mutate_data,
|
|
|
|
m.mutate_data_t,
|
|
|
|
):
|
2016-09-08 22:03:35 +00:00
|
|
|
with pytest.raises(IndexError) as excinfo:
|
|
|
|
func(arr, 1, 2, 3)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "too many indices for an array: 3 (ndim = 2)"
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"args, ret",
|
|
|
|
[
|
|
|
|
([], [1, 2, 3, 4, 5, 6]),
|
|
|
|
([1], [4, 5, 6]),
|
|
|
|
([0, 1], [2, 3, 4, 5, 6]),
|
|
|
|
([1, 2], [6]),
|
|
|
|
],
|
|
|
|
)
|
2016-09-08 22:03:35 +00:00
|
|
|
def test_data(arr, args, ret):
|
2017-02-25 21:43:01 +00:00
|
|
|
from sys import byteorder
|
2020-10-16 20:38:13 +00:00
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert all(m.data_t(arr, *args) == ret)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert all(m.data(arr, *args)[(0 if byteorder == "little" else 1) :: 2] == ret)
|
|
|
|
assert all(m.data(arr, *args)[(1 if byteorder == "little" else 0) :: 2] == 0)
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
@pytest.mark.parametrize("dim", [0, 1, 3])
|
2016-09-08 22:03:35 +00:00
|
|
|
def test_at_fail(arr, dim):
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
for func in m.at_t, m.mutate_at_t:
|
2016-09-08 22:03:35 +00:00
|
|
|
with pytest.raises(IndexError) as excinfo:
|
|
|
|
func(arr, *([0] * dim))
|
2022-02-12 00:06:16 +00:00
|
|
|
assert str(excinfo.value) == f"index dimension mismatch: {dim} (ndim = 2)"
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_at(arr):
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.at_t(arr, 0, 2) == 3
|
|
|
|
assert m.at_t(arr, 1, 0) == 4
|
|
|
|
|
|
|
|
assert all(m.mutate_at_t(arr, 0, 2).ravel() == [1, 2, 4, 4, 5, 6])
|
|
|
|
assert all(m.mutate_at_t(arr, 1, 0).ravel() == [1, 2, 4, 5, 5, 6])
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
def test_mutate_readonly(arr):
|
|
|
|
arr.flags.writeable = False
|
2020-10-16 20:38:13 +00:00
|
|
|
for func, args in (
|
|
|
|
(m.mutate_data, ()),
|
|
|
|
(m.mutate_data_t, ()),
|
|
|
|
(m.mutate_at_t, (0, 0)),
|
|
|
|
):
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
with pytest.raises(ValueError) as excinfo:
|
|
|
|
func(arr, *args)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "array is not writeable"
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_mutate_data(arr):
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert all(m.mutate_data(arr).ravel() == [2, 4, 6, 8, 10, 12])
|
|
|
|
assert all(m.mutate_data(arr).ravel() == [4, 8, 12, 16, 20, 24])
|
|
|
|
assert all(m.mutate_data(arr, 1).ravel() == [4, 8, 12, 32, 40, 48])
|
|
|
|
assert all(m.mutate_data(arr, 0, 1).ravel() == [4, 16, 24, 64, 80, 96])
|
|
|
|
assert all(m.mutate_data(arr, 1, 2).ravel() == [4, 16, 24, 64, 80, 192])
|
2016-09-08 22:03:35 +00:00
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert all(m.mutate_data_t(arr).ravel() == [5, 17, 25, 65, 81, 193])
|
|
|
|
assert all(m.mutate_data_t(arr).ravel() == [6, 18, 26, 66, 82, 194])
|
|
|
|
assert all(m.mutate_data_t(arr, 1).ravel() == [6, 18, 26, 67, 83, 195])
|
|
|
|
assert all(m.mutate_data_t(arr, 0, 1).ravel() == [6, 19, 27, 68, 84, 196])
|
|
|
|
assert all(m.mutate_data_t(arr, 1, 2).ravel() == [6, 19, 27, 68, 84, 197])
|
2016-09-08 22:03:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_bounds_check(arr):
|
2020-10-16 20:38:13 +00:00
|
|
|
for func in (
|
|
|
|
m.index_at,
|
|
|
|
m.index_at_t,
|
|
|
|
m.data,
|
|
|
|
m.data_t,
|
|
|
|
m.mutate_data,
|
|
|
|
m.mutate_data_t,
|
|
|
|
m.at_t,
|
|
|
|
m.mutate_at_t,
|
|
|
|
):
|
2016-09-08 22:03:35 +00:00
|
|
|
with pytest.raises(IndexError) as excinfo:
|
2016-11-20 20:21:54 +00:00
|
|
|
func(arr, 2, 0)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "index 2 is out of bounds for axis 0 with size 2"
|
2016-09-08 22:03:35 +00:00
|
|
|
with pytest.raises(IndexError) as excinfo:
|
2016-11-20 20:21:54 +00:00
|
|
|
func(arr, 0, 4)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "index 4 is out of bounds for axis 1 with size 3"
|
2016-10-12 21:34:06 +00:00
|
|
|
|
2016-10-12 22:57:42 +00:00
|
|
|
|
2016-10-12 21:34:06 +00:00
|
|
|
def test_make_c_f_array():
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.make_c_array().flags.c_contiguous
|
|
|
|
assert not m.make_c_array().flags.f_contiguous
|
|
|
|
assert m.make_f_array().flags.f_contiguous
|
|
|
|
assert not m.make_f_array().flags.c_contiguous
|
2016-10-12 22:57:42 +00:00
|
|
|
|
|
|
|
|
2018-05-06 13:59:25 +00:00
|
|
|
def test_make_empty_shaped_array():
|
|
|
|
m.make_empty_shaped_array()
|
|
|
|
|
2019-06-11 12:00:05 +00:00
|
|
|
# empty shape means numpy scalar, PEP 3118
|
|
|
|
assert m.scalar_int().ndim == 0
|
|
|
|
assert m.scalar_int().shape == ()
|
|
|
|
assert m.scalar_int() == 42
|
|
|
|
|
2018-05-06 13:59:25 +00:00
|
|
|
|
2016-10-12 22:57:42 +00:00
|
|
|
def test_wrap():
|
2017-01-17 01:22:00 +00:00
|
|
|
def assert_references(a, b, base=None):
|
|
|
|
if base is None:
|
|
|
|
base = a
|
2016-11-20 20:21:54 +00:00
|
|
|
assert a is not b
|
2020-10-16 20:38:13 +00:00
|
|
|
assert a.__array_interface__["data"][0] == b.__array_interface__["data"][0]
|
2016-11-20 20:21:54 +00:00
|
|
|
assert a.shape == b.shape
|
|
|
|
assert a.strides == b.strides
|
|
|
|
assert a.flags.c_contiguous == b.flags.c_contiguous
|
|
|
|
assert a.flags.f_contiguous == b.flags.f_contiguous
|
|
|
|
assert a.flags.writeable == b.flags.writeable
|
|
|
|
assert a.flags.aligned == b.flags.aligned
|
2022-02-12 00:06:16 +00:00
|
|
|
# 1.13 supported Python 3.6
|
|
|
|
if tuple(int(x) for x in np.__version__.split(".")[:2]) >= (1, 14):
|
2018-01-11 14:37:52 +00:00
|
|
|
assert a.flags.writebackifcopy == b.flags.writebackifcopy
|
|
|
|
else:
|
|
|
|
assert a.flags.updateifcopy == b.flags.updateifcopy
|
2016-11-20 20:21:54 +00:00
|
|
|
assert np.all(a == b)
|
|
|
|
assert not b.flags.owndata
|
2017-01-17 01:22:00 +00:00
|
|
|
assert b.base is base
|
2016-11-20 20:21:54 +00:00
|
|
|
if a.flags.writeable and a.ndim == 2:
|
|
|
|
a[0, 0] = 1234
|
|
|
|
assert b[0, 0] == 1234
|
|
|
|
|
|
|
|
a1 = np.array([1, 2], dtype=np.int16)
|
|
|
|
assert a1.flags.owndata and a1.base is None
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
a2 = m.wrap(a1)
|
2016-11-20 20:21:54 +00:00
|
|
|
assert_references(a1, a2)
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order="F")
|
2016-11-20 20:21:54 +00:00
|
|
|
assert a1.flags.owndata and a1.base is None
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
a2 = m.wrap(a1)
|
2016-11-20 20:21:54 +00:00
|
|
|
assert_references(a1, a2)
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
a1 = np.array([[1, 2], [3, 4]], dtype=np.float32, order="C")
|
2016-11-20 20:21:54 +00:00
|
|
|
a1.flags.writeable = False
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
a2 = m.wrap(a1)
|
2016-11-20 20:21:54 +00:00
|
|
|
assert_references(a1, a2)
|
|
|
|
|
|
|
|
a1 = np.random.random((4, 4, 4))
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
a2 = m.wrap(a1)
|
2016-11-20 20:21:54 +00:00
|
|
|
assert_references(a1, a2)
|
|
|
|
|
2017-01-17 01:22:00 +00:00
|
|
|
a1t = a1.transpose()
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
a2 = m.wrap(a1t)
|
2017-01-17 01:22:00 +00:00
|
|
|
assert_references(a1t, a2, a1)
|
2016-11-20 20:21:54 +00:00
|
|
|
|
2017-01-17 01:22:00 +00:00
|
|
|
a1d = a1.diagonal()
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
a2 = m.wrap(a1d)
|
2017-01-17 01:22:00 +00:00
|
|
|
assert_references(a1d, a2, a1)
|
2016-10-13 08:37:52 +00:00
|
|
|
|
2017-04-05 22:13:04 +00:00
|
|
|
a1m = a1[::-1, ::-1, ::-1]
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
a2 = m.wrap(a1m)
|
2017-04-05 22:13:04 +00:00
|
|
|
assert_references(a1m, a2, a1)
|
|
|
|
|
2016-10-13 08:37:52 +00:00
|
|
|
|
|
|
|
def test_numpy_view(capture):
|
|
|
|
with capture:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
ac = m.ArrayClass()
|
2016-10-13 08:37:52 +00:00
|
|
|
ac_view_1 = ac.numpy_view()
|
|
|
|
ac_view_2 = ac.numpy_view()
|
|
|
|
assert np.all(ac_view_1 == np.array([1, 2], dtype=np.int32))
|
|
|
|
del ac
|
2016-12-16 14:00:46 +00:00
|
|
|
pytest.gc_collect()
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2016-10-13 08:37:52 +00:00
|
|
|
ArrayClass()
|
|
|
|
ArrayClass::numpy_view()
|
|
|
|
ArrayClass::numpy_view()
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2016-10-13 08:37:52 +00:00
|
|
|
ac_view_1[0] = 4
|
|
|
|
ac_view_1[1] = 3
|
|
|
|
assert ac_view_2[0] == 4
|
|
|
|
assert ac_view_2[1] == 3
|
|
|
|
with capture:
|
|
|
|
del ac_view_1
|
|
|
|
del ac_view_2
|
2016-12-16 14:00:46 +00:00
|
|
|
pytest.gc_collect()
|
|
|
|
pytest.gc_collect()
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
capture
|
|
|
|
== """
|
2016-10-13 08:37:52 +00:00
|
|
|
~ArrayClass()
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2016-10-27 22:37:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_cast_numpy_int64_to_uint64():
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.function_taking_uint64(123)
|
|
|
|
m.function_taking_uint64(np.uint64(123))
|
2016-11-16 00:35:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_isinstance():
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.isinstance_untyped(np.array([1, 2, 3]), "not an array")
|
|
|
|
assert m.isinstance_typed(np.array([1.0, 2.0, 3.0]))
|
2016-11-16 00:35:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_constructors():
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
defaults = m.default_constructors()
|
2016-11-16 00:35:22 +00:00
|
|
|
for a in defaults.values():
|
|
|
|
assert a.size == 0
|
|
|
|
assert defaults["array"].dtype == np.array([]).dtype
|
|
|
|
assert defaults["array_t<int32>"].dtype == np.int32
|
|
|
|
assert defaults["array_t<double>"].dtype == np.float64
|
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
results = m.converting_constructors([1, 2, 3])
|
2016-11-16 00:35:22 +00:00
|
|
|
for a in results.values():
|
|
|
|
np.testing.assert_array_equal(a, [1, 2, 3])
|
|
|
|
assert results["array"].dtype == np.int_
|
|
|
|
assert results["array_t<int32>"].dtype == np.int32
|
|
|
|
assert results["array_t<double>"].dtype == np.float64
|
2017-02-24 10:33:31 +00:00
|
|
|
|
|
|
|
|
2017-02-26 23:03:00 +00:00
|
|
|
def test_overload_resolution(msg):
|
|
|
|
# Exact overload matches:
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.overloaded(np.array([1], dtype="float64")) == "double"
|
|
|
|
assert m.overloaded(np.array([1], dtype="float32")) == "float"
|
|
|
|
assert m.overloaded(np.array([1], dtype="ushort")) == "unsigned short"
|
|
|
|
assert m.overloaded(np.array([1], dtype="intc")) == "int"
|
|
|
|
assert m.overloaded(np.array([1], dtype="longlong")) == "long long"
|
|
|
|
assert m.overloaded(np.array([1], dtype="complex")) == "double complex"
|
|
|
|
assert m.overloaded(np.array([1], dtype="csingle")) == "float complex"
|
2017-02-26 23:03:00 +00:00
|
|
|
|
|
|
|
# No exact match, should call first convertible version:
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.overloaded(np.array([1], dtype="uint8")) == "double"
|
2017-02-26 23:03:00 +00:00
|
|
|
|
2017-03-13 18:17:18 +00:00
|
|
|
with pytest.raises(TypeError) as excinfo:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.overloaded("not an array")
|
2020-10-16 20:38:13 +00:00
|
|
|
assert (
|
|
|
|
msg(excinfo.value)
|
|
|
|
== """
|
2017-03-13 18:17:18 +00:00
|
|
|
overloaded(): incompatible function arguments. The following argument types are supported:
|
2020-05-14 12:34:48 +00:00
|
|
|
1. (arg0: numpy.ndarray[numpy.float64]) -> str
|
|
|
|
2. (arg0: numpy.ndarray[numpy.float32]) -> str
|
|
|
|
3. (arg0: numpy.ndarray[numpy.int32]) -> str
|
|
|
|
4. (arg0: numpy.ndarray[numpy.uint16]) -> str
|
|
|
|
5. (arg0: numpy.ndarray[numpy.int64]) -> str
|
|
|
|
6. (arg0: numpy.ndarray[numpy.complex128]) -> str
|
|
|
|
7. (arg0: numpy.ndarray[numpy.complex64]) -> str
|
2017-03-13 18:17:18 +00:00
|
|
|
|
|
|
|
Invoked with: 'not an array'
|
|
|
|
"""
|
2020-10-16 20:38:13 +00:00
|
|
|
)
|
2017-03-13 18:17:18 +00:00
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.overloaded2(np.array([1], dtype="float64")) == "double"
|
|
|
|
assert m.overloaded2(np.array([1], dtype="float32")) == "float"
|
|
|
|
assert m.overloaded2(np.array([1], dtype="complex64")) == "float complex"
|
|
|
|
assert m.overloaded2(np.array([1], dtype="complex128")) == "double complex"
|
|
|
|
assert m.overloaded2(np.array([1], dtype="float32")) == "float"
|
2017-02-26 23:03:00 +00:00
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.overloaded3(np.array([1], dtype="float64")) == "double"
|
|
|
|
assert m.overloaded3(np.array([1], dtype="intc")) == "int"
|
2017-02-26 23:03:00 +00:00
|
|
|
expected_exc = """
|
|
|
|
overloaded3(): incompatible function arguments. The following argument types are supported:
|
2020-05-14 12:34:48 +00:00
|
|
|
1. (arg0: numpy.ndarray[numpy.int32]) -> str
|
|
|
|
2. (arg0: numpy.ndarray[numpy.float64]) -> str
|
2017-02-26 23:03:00 +00:00
|
|
|
|
2018-01-11 14:37:52 +00:00
|
|
|
Invoked with: """
|
2017-02-26 23:03:00 +00:00
|
|
|
|
|
|
|
with pytest.raises(TypeError) as excinfo:
|
2020-10-16 20:38:13 +00:00
|
|
|
m.overloaded3(np.array([1], dtype="uintc"))
|
|
|
|
assert msg(excinfo.value) == expected_exc + repr(np.array([1], dtype="uint32"))
|
2017-02-26 23:03:00 +00:00
|
|
|
with pytest.raises(TypeError) as excinfo:
|
2020-10-16 20:38:13 +00:00
|
|
|
m.overloaded3(np.array([1], dtype="float32"))
|
|
|
|
assert msg(excinfo.value) == expected_exc + repr(np.array([1.0], dtype="float32"))
|
2017-02-26 23:03:00 +00:00
|
|
|
with pytest.raises(TypeError) as excinfo:
|
2020-10-16 20:38:13 +00:00
|
|
|
m.overloaded3(np.array([1], dtype="complex"))
|
|
|
|
assert msg(excinfo.value) == expected_exc + repr(np.array([1.0 + 0.0j]))
|
2017-02-26 23:03:00 +00:00
|
|
|
|
|
|
|
# Exact matches:
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.overloaded4(np.array([1], dtype="double")) == "double"
|
|
|
|
assert m.overloaded4(np.array([1], dtype="longlong")) == "long long"
|
2017-02-26 23:03:00 +00:00
|
|
|
# Non-exact matches requiring conversion. Since float to integer isn't a
|
|
|
|
# save conversion, it should go to the double overload, but short can go to
|
|
|
|
# either (and so should end up on the first-registered, the long long).
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.overloaded4(np.array([1], dtype="float32")) == "double"
|
|
|
|
assert m.overloaded4(np.array([1], dtype="short")) == "long long"
|
2017-02-26 23:03:00 +00:00
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.overloaded5(np.array([1], dtype="double")) == "double"
|
|
|
|
assert m.overloaded5(np.array([1], dtype="uintc")) == "unsigned int"
|
|
|
|
assert m.overloaded5(np.array([1], dtype="float32")) == "unsigned int"
|
2017-02-26 23:03:00 +00:00
|
|
|
|
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
def test_greedy_string_overload():
|
|
|
|
"""Tests fix for #685 - ndarray shouldn't go to std::string overload"""
|
2017-02-24 10:33:31 +00:00
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.issue685("abc") == "string"
|
2020-10-16 20:38:13 +00:00
|
|
|
assert m.issue685(np.array([97, 98, 99], dtype="b")) == "array"
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.issue685(123) == "other"
|
2017-03-19 04:14:23 +00:00
|
|
|
|
|
|
|
|
2017-03-20 20:48:38 +00:00
|
|
|
def test_array_unchecked_fixed_dims(msg):
|
2020-10-16 20:38:13 +00:00
|
|
|
z1 = np.array([[1, 2], [3, 4]], dtype="float64")
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.proxy_add2(z1, 10)
|
2017-03-19 04:14:23 +00:00
|
|
|
assert np.all(z1 == [[11, 12], [13, 14]])
|
|
|
|
|
|
|
|
with pytest.raises(ValueError) as excinfo:
|
2020-10-16 20:38:13 +00:00
|
|
|
m.proxy_add2(np.array([1.0, 2, 3]), 5.0)
|
|
|
|
assert (
|
|
|
|
msg(excinfo.value) == "array has incorrect number of dimensions: 1; expected 2"
|
|
|
|
)
|
2017-03-19 04:14:23 +00:00
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
expect_c = np.ndarray(shape=(3, 3, 3), buffer=np.array(range(3, 30)), dtype="int")
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert np.all(m.proxy_init3(3.0) == expect_c)
|
2017-03-19 04:14:23 +00:00
|
|
|
expect_f = np.transpose(expect_c)
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert np.all(m.proxy_init3F(3.0) == expect_f)
|
2017-03-19 04:14:23 +00:00
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.proxy_squared_L2_norm(np.array(range(6))) == 55
|
|
|
|
assert m.proxy_squared_L2_norm(np.array(range(6), dtype="float64")) == 55
|
2017-03-20 20:48:38 +00:00
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.proxy_auxiliaries2(z1) == [11, 11, True, 2, 8, 2, 2, 4, 32]
|
|
|
|
assert m.proxy_auxiliaries2(z1) == m.array_auxiliaries2(z1)
|
2017-03-20 20:48:38 +00:00
|
|
|
|
2020-10-02 17:07:04 +00:00
|
|
|
assert m.proxy_auxiliaries1_const_ref(z1[0, :])
|
|
|
|
assert m.proxy_auxiliaries2_const_ref(z1)
|
|
|
|
|
2017-03-20 20:48:38 +00:00
|
|
|
|
2021-08-26 15:12:35 +00:00
|
|
|
def test_array_unchecked_dyn_dims():
|
2020-10-16 20:38:13 +00:00
|
|
|
z1 = np.array([[1, 2], [3, 4]], dtype="float64")
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.proxy_add2_dyn(z1, 10)
|
2017-03-20 20:48:38 +00:00
|
|
|
assert np.all(z1 == [[11, 12], [13, 14]])
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
expect_c = np.ndarray(shape=(3, 3, 3), buffer=np.array(range(3, 30)), dtype="int")
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert np.all(m.proxy_init3_dyn(3.0) == expect_c)
|
2017-03-20 20:48:38 +00:00
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
assert m.proxy_auxiliaries2_dyn(z1) == [11, 11, True, 2, 8, 2, 2, 4, 32]
|
|
|
|
assert m.proxy_auxiliaries2_dyn(z1) == m.array_auxiliaries2(z1)
|
2017-04-10 15:05:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_array_failure():
|
|
|
|
with pytest.raises(ValueError) as excinfo:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.array_fail_test()
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "cannot create a pybind11::array from a nullptr"
|
2017-04-10 15:05:26 +00:00
|
|
|
|
|
|
|
with pytest.raises(ValueError) as excinfo:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.array_t_fail_test()
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "cannot create a pybind11::array_t from a nullptr"
|
2017-04-13 16:41:55 +00:00
|
|
|
|
2017-04-14 20:33:44 +00:00
|
|
|
with pytest.raises(ValueError) as excinfo:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.array_fail_test_negative_size()
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(excinfo.value) == "negative dimensions are not allowed"
|
2017-04-14 20:33:44 +00:00
|
|
|
|
2017-04-13 16:41:55 +00:00
|
|
|
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
def test_initializer_list():
|
|
|
|
assert m.array_initializer_list1().shape == (1,)
|
|
|
|
assert m.array_initializer_list2().shape == (1, 2)
|
|
|
|
assert m.array_initializer_list3().shape == (1, 2, 3)
|
|
|
|
assert m.array_initializer_list4().shape == (1, 2, 3, 4)
|
|
|
|
|
2017-04-13 16:41:55 +00:00
|
|
|
|
2021-08-26 15:12:35 +00:00
|
|
|
def test_array_resize():
|
2020-10-16 20:38:13 +00:00
|
|
|
a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype="float64")
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.array_reshape2(a)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert a.size == 9
|
|
|
|
assert np.all(a == [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
|
2017-04-13 16:41:55 +00:00
|
|
|
|
|
|
|
# total size change should succced with refcheck off
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.array_resize3(a, 4, False)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert a.size == 64
|
2017-04-13 16:41:55 +00:00
|
|
|
# ... and fail with refcheck on
|
|
|
|
try:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.array_resize3(a, 3, True)
|
2017-04-13 16:41:55 +00:00
|
|
|
except ValueError as e:
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(e).startswith("cannot resize an array")
|
2017-04-13 16:41:55 +00:00
|
|
|
# transposed array doesn't own data
|
|
|
|
b = a.transpose()
|
|
|
|
try:
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.array_resize3(b, 3, False)
|
2017-04-13 16:41:55 +00:00
|
|
|
except ValueError as e:
|
2020-10-16 20:38:13 +00:00
|
|
|
assert str(e).startswith("cannot resize this array: it does not own its data")
|
2017-04-13 16:41:55 +00:00
|
|
|
# ... but reshape should be fine
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
m.array_reshape2(b)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert b.shape == (8, 8)
|
2017-04-13 16:41:55 +00:00
|
|
|
|
|
|
|
|
2020-08-16 20:02:12 +00:00
|
|
|
@pytest.mark.xfail("env.PYPY")
|
2021-08-26 15:12:35 +00:00
|
|
|
def test_array_create_and_resize():
|
Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898. For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.
- test_constants_and_functions: this adds more overload tests with
overloads with different number of arguments for more comprehensive
overload_cast testing. The test style conversion broke the overload
tests under MSVC 2015, prompting the additional tests while looking
for a workaround.
- test_eigen: this dropped the unused functions `get_cm_corners` and
`get_cm_corners_const`--these same tests were duplicates of the same
things provided (and used) via ReturnTester methods.
- test_opaque_types: this test had a hidden dependence on ExampleMandA
which is now fixed by using the global UserType which suffices for the
relevant test.
- test_methods_and_attributes: this required some additions to UserType
to make it usable as a replacement for the test's previous SimpleType:
UserType gained a value mutator, and the `value` property is not
mutable (it was previously readonly). Some overload tests were also
added to better test overload_cast (as described above).
- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
the templated versions with an empty parameter pack expand to the same
thing.
- test_stl: this was already mostly in the new style; this just tweaks
things a bit, localizing a class, and adding some missing
`// test_whatever` comments.
- test_virtual_functions: like `test_stl`, this was mostly in the new
test style already, but needed some `// test_whatever` comments.
This commit also moves the inherited virtual example code to the end
of the file, after the main set of tests (since it is less important
than the other tests, and rather length); it also got renamed to
`test_inherited_virtuals` (from `test_inheriting_repeat`) because it
tests both inherited virtual approaches, not just the repeat approach.
2017-07-25 20:47:36 +00:00
|
|
|
a = m.create_and_resize(2)
|
2020-10-16 20:38:13 +00:00
|
|
|
assert a.size == 4
|
|
|
|
assert np.all(a == 42.0)
|
2018-08-27 22:23:59 +00:00
|
|
|
|
|
|
|
|
2021-08-26 21:11:01 +00:00
|
|
|
def test_array_view():
|
|
|
|
a = np.ones(100 * 4).astype("uint8")
|
|
|
|
a_float_view = m.array_view(a, "float32")
|
|
|
|
assert a_float_view.shape == (100 * 1,) # 1 / 4 bytes = 8 / 32
|
|
|
|
|
|
|
|
a_int16_view = m.array_view(a, "int16") # 1 / 2 bytes = 16 / 32
|
|
|
|
assert a_int16_view.shape == (100 * 2,)
|
|
|
|
|
|
|
|
|
|
|
|
def test_array_view_invalid():
|
|
|
|
a = np.ones(100 * 4).astype("uint8")
|
|
|
|
with pytest.raises(TypeError):
|
|
|
|
m.array_view(a, "deadly_dtype")
|
|
|
|
|
|
|
|
|
2021-08-26 15:12:35 +00:00
|
|
|
def test_reshape_initializer_list():
|
|
|
|
a = np.arange(2 * 7 * 3) + 1
|
|
|
|
x = m.reshape_initializer_list(a, 2, 7, 3)
|
|
|
|
assert x.shape == (2, 7, 3)
|
|
|
|
assert list(x[1][4]) == [34, 35, 36]
|
|
|
|
with pytest.raises(ValueError) as excinfo:
|
|
|
|
m.reshape_initializer_list(a, 1, 7, 3)
|
|
|
|
assert str(excinfo.value) == "cannot reshape array of size 42 into shape (1,7,3)"
|
|
|
|
|
|
|
|
|
|
|
|
def test_reshape_tuple():
|
|
|
|
a = np.arange(3 * 7 * 2) + 1
|
|
|
|
x = m.reshape_tuple(a, (3, 7, 2))
|
|
|
|
assert x.shape == (3, 7, 2)
|
|
|
|
assert list(x[1][4]) == [23, 24]
|
|
|
|
y = m.reshape_tuple(x, (x.size,))
|
|
|
|
assert y.shape == (42,)
|
|
|
|
with pytest.raises(ValueError) as excinfo:
|
|
|
|
m.reshape_tuple(a, (3, 7, 1))
|
|
|
|
assert str(excinfo.value) == "cannot reshape array of size 42 into shape (3,7,1)"
|
|
|
|
with pytest.raises(ValueError) as excinfo:
|
|
|
|
m.reshape_tuple(a, ())
|
|
|
|
assert str(excinfo.value) == "cannot reshape array of size 42 into shape ()"
|
|
|
|
|
|
|
|
|
2018-08-27 22:23:59 +00:00
|
|
|
def test_index_using_ellipsis():
|
|
|
|
a = m.index_using_ellipsis(np.zeros((5, 6, 7)))
|
|
|
|
assert a.shape == (6,)
|
2019-07-27 09:35:32 +00:00
|
|
|
|
|
|
|
|
2021-06-08 18:56:45 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"test_func",
|
|
|
|
[
|
|
|
|
m.test_fmt_desc_float,
|
|
|
|
m.test_fmt_desc_double,
|
|
|
|
m.test_fmt_desc_const_float,
|
|
|
|
m.test_fmt_desc_const_double,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_format_descriptors_for_floating_point_types(test_func):
|
|
|
|
assert "numpy.ndarray[numpy.float" in test_func.__doc__
|
|
|
|
|
|
|
|
|
2020-09-15 12:50:51 +00:00
|
|
|
@pytest.mark.parametrize("forcecast", [False, True])
|
2020-10-16 20:38:13 +00:00
|
|
|
@pytest.mark.parametrize("contiguity", [None, "C", "F"])
|
2020-09-15 12:50:51 +00:00
|
|
|
@pytest.mark.parametrize("noconvert", [False, True])
|
|
|
|
@pytest.mark.filterwarnings(
|
|
|
|
"ignore:Casting complex values to real discards the imaginary part:numpy.ComplexWarning"
|
|
|
|
)
|
|
|
|
def test_argument_conversions(forcecast, contiguity, noconvert):
|
|
|
|
function_name = "accept_double"
|
2020-10-16 20:38:13 +00:00
|
|
|
if contiguity == "C":
|
2020-09-15 12:50:51 +00:00
|
|
|
function_name += "_c_style"
|
2020-10-16 20:38:13 +00:00
|
|
|
elif contiguity == "F":
|
2020-09-15 12:50:51 +00:00
|
|
|
function_name += "_f_style"
|
|
|
|
if forcecast:
|
|
|
|
function_name += "_forcecast"
|
|
|
|
if noconvert:
|
|
|
|
function_name += "_noconvert"
|
|
|
|
function = getattr(m, function_name)
|
|
|
|
|
2020-10-16 20:38:13 +00:00
|
|
|
for dtype in [np.dtype("float32"), np.dtype("float64"), np.dtype("complex128")]:
|
|
|
|
for order in ["C", "F"]:
|
2020-09-15 12:50:51 +00:00
|
|
|
for shape in [(2, 2), (1, 3, 1, 1), (1, 1, 1), (0,)]:
|
|
|
|
if not noconvert:
|
|
|
|
# If noconvert is not passed, only complex128 needs to be truncated and
|
|
|
|
# "cannot be safely obtained". So without `forcecast`, the argument shouldn't
|
|
|
|
# be accepted.
|
2020-10-16 20:38:13 +00:00
|
|
|
should_raise = dtype.name == "complex128" and not forcecast
|
2020-09-15 12:50:51 +00:00
|
|
|
else:
|
|
|
|
# If noconvert is passed, only float64 and the matching order is accepted.
|
|
|
|
# If at most one dimension has a size greater than 1, the array is also
|
|
|
|
# trivially contiguous.
|
|
|
|
trivially_contiguous = sum(1 for d in shape if d > 1) <= 1
|
2020-10-16 20:38:13 +00:00
|
|
|
should_raise = dtype.name != "float64" or (
|
|
|
|
contiguity is not None
|
|
|
|
and contiguity != order
|
|
|
|
and not trivially_contiguous
|
2020-09-15 12:50:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
array = np.zeros(shape, dtype=dtype, order=order)
|
|
|
|
if not should_raise:
|
|
|
|
function(array)
|
|
|
|
else:
|
2020-10-16 20:38:13 +00:00
|
|
|
with pytest.raises(
|
|
|
|
TypeError, match="incompatible function arguments"
|
|
|
|
):
|
2020-09-15 12:50:51 +00:00
|
|
|
function(array)
|
|
|
|
|
|
|
|
|
2020-08-16 20:02:12 +00:00
|
|
|
@pytest.mark.xfail("env.PYPY")
|
2019-07-27 09:35:32 +00:00
|
|
|
def test_dtype_refcount_leak():
|
|
|
|
from sys import getrefcount
|
2020-10-16 20:38:13 +00:00
|
|
|
|
2019-07-27 09:35:32 +00:00
|
|
|
dtype = np.dtype(np.float_)
|
|
|
|
a = np.array([1], dtype=dtype)
|
|
|
|
before = getrefcount(dtype)
|
|
|
|
m.ndim(a)
|
|
|
|
after = getrefcount(dtype)
|
|
|
|
assert after == before
|