dev-python/flatbuffers: test support for Numpy 2.0

Signed-off-by: Petr Vaněk <arkamar@gentoo.org>
This commit is contained in:
Petr Vaněk
2024-07-01 14:21:07 +02:00
parent 06f66d41e4
commit 228e91ddbb
2 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
From d053fbd391610e72fff1f8ee02c1222305f15de9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Van=C4=9Bk?= <arkamar@gentoo.org>
Date: Mon, 1 Jul 2024 10:29:39 +0000
Subject: [PATCH] Support for Numpy 2.0 in tests
The newbyteorder has been removed in Numpy 2.0 [1]. Its usages are
replaced with respect to migration guide.
[1] https://numpy.org/devdocs/numpy_2_0_migration_guide.html#ndarray-and-scalar-methods
Fixes: #8332
Upstream-PR: https://github.com/google/flatbuffers/pull/8346
diff --git a/tests/py_test.py b/tests/py_test.py
index 7d6c0a37966..fc13a490f71 100644
--- a/tests/py_test.py
+++ b/tests/py_test.py
@@ -1095,7 +1095,7 @@ def test_create_numpy_vector_int8(self):
# Reverse endian:
b = flatbuffers.Builder(0)
- x_other_endian = x.byteswap().newbyteorder()
+ x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
b.CreateNumpyVector(x_other_endian)
self.assertBuilderEquals(
b,
@@ -1144,7 +1144,7 @@ def test_create_numpy_vector_uint16(self):
# Reverse endian:
b = flatbuffers.Builder(0)
- x_other_endian = x.byteswap().newbyteorder()
+ x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
b.CreateNumpyVector(x_other_endian)
self.assertBuilderEquals(
b,
@@ -1213,7 +1213,7 @@ def test_create_numpy_vector_int64(self):
# Reverse endian:
b = flatbuffers.Builder(0)
- x_other_endian = x.byteswap().newbyteorder()
+ x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
b.CreateNumpyVector(x_other_endian)
self.assertBuilderEquals(
b,
@@ -1287,7 +1287,7 @@ def test_create_numpy_vector_float32(self):
# Reverse endian:
b = flatbuffers.Builder(0)
- x_other_endian = x.byteswap().newbyteorder()
+ x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
b.CreateNumpyVector(x_other_endian)
self.assertBuilderEquals(
b,
@@ -1361,7 +1361,7 @@ def test_create_numpy_vector_float64(self):
# Reverse endian:
b = flatbuffers.Builder(0)
- x_other_endian = x.byteswap().newbyteorder()
+ x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
b.CreateNumpyVector(x_other_endian)
self.assertBuilderEquals(
b,
@@ -1427,7 +1427,7 @@ def test_create_numpy_vector_bool(self):
# Reverse endian:
b = flatbuffers.Builder(0)
- x_other_endian = x.byteswap().newbyteorder()
+ x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
b.CreateNumpyVector(x_other_endian)
self.assertBuilderEquals(
b,

View File

@@ -0,0 +1,46 @@
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{10..12} )
inherit distutils-r1
DESCRIPTION="RFC 7049 - Concise Binary Object Representation"
HOMEPAGE="
https://github.com/google/flatbuffers/
https://pypi.org/project/flatbuffers/
"
SRC_URI="
https://github.com/google/${PN}/archive/v${PV}.tar.gz
-> ${P}.gh.tar.gz
"
S=${WORKDIR}/${P}/python
LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="~amd64 ~arm ~arm64 ~riscv ~sparc ~x86"
IUSE="test"
RESTRICT="!test? ( test )"
BDEPEND="
test? (
dev-python/numpy[${PYTHON_USEDEP}]
)
"
src_prepare() {
cd "${WORKDIR}/${P}" || die
eapply "${FILESDIR}/${PN}-24.3.25-numpy-2.patch"
cd "${S}" || die
distutils-r1_src_prepare
}
python_test() {
cd "${WORKDIR}/${P}/tests" || die
# zeroes means without benchmarks
"${EPYTHON}" py_test.py 0 0 0 0 false || die
"${EPYTHON}" py_flexbuffers_test.py -v || die
}