From 100065a3a048ced7b332ea7d7b6f5c2afda86447 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 19 Nov 2024 09:43:31 +0100 Subject: [PATCH 1/3] [tests] ensure DeprecationWarning is triggered --- test/jpypetest/test_jobject.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/jpypetest/test_jobject.py b/test/jpypetest/test_jobject.py index b6fcd87c2..bf5e78e37 100644 --- a/test/jpypetest/test_jobject.py +++ b/test/jpypetest/test_jobject.py @@ -17,7 +17,6 @@ # ***************************************************************************** import _jpype import jpype -import _jpype from jpype.types import * from jpype import java import common @@ -292,7 +291,8 @@ def testRepr(self): def testDeprecated(self): # this one should issue a warning jo = JClass("java.lang.Object") - self.assertIsInstance(JObject(None, object), jo) + with self.assertWarns(DeprecationWarning): + self.assertIsInstance(JObject(None, object), jo) def testGetSetBad(self): JS = JClass("java.lang.String") From f4d524fbf9e2bfe08000e5cc160fde423adc16e0 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 19 Nov 2024 09:45:52 +0100 Subject: [PATCH 2/3] [tests] floating point almost equal fix --- test/jpypetest/common.py | 6 ++++-- test/jpypetest/test_jdouble.py | 8 ++++---- test/jpypetest/test_jfloat.py | 13 +++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/jpypetest/common.py b/test/jpypetest/common.py index 8f7d45b2d..10e62e60c 100644 --- a/test/jpypetest/common.py +++ b/test/jpypetest/common.py @@ -136,10 +136,11 @@ def assertElementsEqual(self, a, b): for i in range(len(a)): self.assertEqual(a[i], b[i]) - def assertElementsAlmostEqual(self, a, b): + def assertElementsAlmostEqual(self, a, b, places=None, msg=None, + delta=None): self.assertEqual(len(a), len(b)) for i in range(len(a)): - self.assertAlmostEqual(a[i], b[i]) + self.assertAlmostEqual(a[i], b[i], places, msg, delta) def useEqualityFunc(self, func): return UseFunc(self, func, 'assertEqual') @@ -153,4 +154,5 @@ def java_version(): "import jpype; jpype.startJVM(); " "print(jpype.java.lang.System.getProperty('java.version'))"]), encoding='ascii') + # todo: make this robust for version "numbers" containing strings (e.g.) 22.1-internal return tuple(map(int, java_version.split("."))) diff --git a/test/jpypetest/test_jdouble.py b/test/jpypetest/test_jdouble.py index cf3b89799..bd7471e77 100644 --- a/test/jpypetest/test_jdouble.py +++ b/test/jpypetest/test_jdouble.py @@ -15,12 +15,12 @@ # See NOTICE file for details. # # ***************************************************************************** -import sys +from unittest.util import safe_repr + import jpype import common import random import _jpype -import jpype from jpype import java from jpype.types import * try: @@ -49,8 +49,8 @@ def compareDoubleEqual(self, x, y, msg=None): b = -b if b < a * 1e-14: return - msg = self._formatMessage(msg, '%s == %s' % (safe_repr(first), - safe_repr(second))) + msg = self._formatMessage(msg, '%s == %s' % (safe_repr(x), + safe_repr(y))) raise self.failureException(msg) @common.requireInstrumentation diff --git a/test/jpypetest/test_jfloat.py b/test/jpypetest/test_jfloat.py index eb63fe168..c92b1fe4a 100644 --- a/test/jpypetest/test_jfloat.py +++ b/test/jpypetest/test_jfloat.py @@ -15,11 +15,12 @@ # See NOTICE file for details. # # ***************************************************************************** -import sys -import jpype -import common import random +from unittest.util import safe_repr + import _jpype + +import common import jpype from jpype import java from jpype.types import * @@ -49,8 +50,8 @@ def compareFloatEqual(self, x, y, msg=None): b = -b if b < a * 1e-7: return - msg = self._formatMessage(msg, '%s == %s' % (safe_repr(first), - safe_repr(second))) + msg = self._formatMessage(msg, '%s == %s' % (safe_repr(x), + safe_repr(y))) raise self.failureException(msg) @common.requireInstrumentation @@ -385,7 +386,7 @@ def testArraySetFromNPDouble(self): def testArrayInitFromNPFloat16(self): a = np.random.random(100).astype(np.float16) jarr = JArray(JFloat)(a) - self.assertElementsAlmostEqual(a, jarr) + self.assertElementsAlmostEqual(a, jarr, places=5) @common.requireNumpy def testArrayInitFromNPFloat32(self): From 338c94b8fe8cd9b4e6ced923319e31b54ae593a6 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 19 Nov 2024 10:16:05 +0100 Subject: [PATCH 3/3] [ci/codecov] fix list elements super useful: curl -X POST --data-binary @codecov.yml https://codecov.io/validate --- codecov.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codecov.yml b/codecov.yml index 94500f038..8e6a34600 100644 --- a/codecov.yml +++ b/codecov.yml @@ -11,7 +11,8 @@ coverage: python: target: 85% threshold: 1% - paths: "jpype/" + paths: + - "jpype/" cpp: target: 80% threshold: 1% @@ -21,7 +22,8 @@ coverage: java: target: 75% threshold: 2% - paths: "native/java/" + paths: + - "native/java/" parsers: gcov: