Skip to content

Commit

Permalink
Merge pull request jpype-project#1239 from marscher/test_cleanups
Browse files Browse the repository at this point in the history
Test cleanups
  • Loading branch information
marscher authored Nov 19, 2024
2 parents dfdeb76 + 338c94b commit 29cce31
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
6 changes: 4 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ coverage:
python:
target: 85%
threshold: 1%
paths: "jpype/"
paths:
- "jpype/"
cpp:
target: 80%
threshold: 1%
Expand All @@ -21,7 +22,8 @@ coverage:
java:
target: 75%
threshold: 2%
paths: "native/java/"
paths:
- "native/java/"

parsers:
gcov:
Expand Down
6 changes: 4 additions & 2 deletions test/jpypetest/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(".")))
8 changes: 4 additions & 4 deletions test/jpypetest/test_jdouble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions test/jpypetest/test_jfloat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions test/jpypetest/test_jobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# *****************************************************************************
import _jpype
import jpype
import _jpype
from jpype.types import *
from jpype import java
import common
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 29cce31

Please sign in to comment.