Skip to content

Commit 507ede7

Browse files
committedMay 3, 2023·
Systematically check that jpype.startJVM is tested and correctly typed
1 parent d847350 commit 507ede7

File tree

3 files changed

+46
-33
lines changed

3 files changed

+46
-33
lines changed
 

‎jpype/_core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def interactive():
160160
def startJVM(
161161
*jvmargs: str,
162162
jvmpath: typing.Optional[_PathOrStr] = None,
163-
classpath: typing.Optional[_PathOrStr] = None,
163+
classpath: typing.Optional[typing.Sequence[_PathOrStr], _PathOrStr] = None,
164164
ignoreUnrecognized: bool = False,
165165
convertStrings: bool = False,
166166
interrupt: bool = not interactive(),
@@ -223,7 +223,7 @@ def startJVM(
223223
# Allow the path to be a PathLike.
224224
jvmpath = os.fspath(jvmpath)
225225

226-
extra_jvm_args = tuple()
226+
extra_jvm_args: typing.Tuple[str, ...] = tuple()
227227

228228
# Classpath handling
229229
if _hasClassPath(jvmargs):

‎jpype/_core.pyi

-2
This file was deleted.

‎test/jpypetest/test_startup.py

+44-29
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222
from pathlib import Path
2323
import unittest
2424

25-
26-
@functools.wraps(jpype.startJVM)
27-
def runStartJVMTest(*args, **kwargs):
28-
jpype.startJVM(*args, **kwargs)
29-
try:
30-
assert jpype.JClass('jpype.array.TestArray') is not None
31-
except Exception as err:
32-
raise RuntimeError("Test class not found") from err
33-
34-
3525
root = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
3626
cp = os.path.join(root, 'classes').replace('\\', '/')
3727

@@ -62,72 +52,97 @@ def testInvalidArgsFalse(self):
6252
def testInvalidArgsTrue(self):
6353
jpype.startJVM(
6454
"-for_sure_InVaLiD",
65-
ignoreUnrecognized=True, convertStrings=False,
55+
ignoreUnrecognized=True,
56+
convertStrings=False,
6657
)
6758

6859
def testClasspathArgKeyword(self):
69-
runStartJVMTest(classpath=cp, convertStrings=False)
60+
jpype.startJVM(classpath=cp, convertStrings=False)
61+
assert jpype.JClass('jpype.array.TestArray') is not None
7062

7163
def testClasspathArgList(self):
72-
runStartJVMTest(classpath=[cp], convertStrings=False)
64+
jpype.startJVM(
65+
classpath=[cp],
66+
convertStrings=False,
67+
)
68+
assert jpype.JClass('jpype.array.TestArray') is not None
7369

7470
def testClasspathArgListEmpty(self):
75-
runStartJVMTest(classpath=[cp, ''], convertStrings=False)
71+
jpype.startJVM(
72+
classpath=[cp, ''],
73+
convertStrings=False,
74+
)
75+
assert jpype.JClass('jpype.array.TestArray') is not None
7676

7777
def testClasspathArgDef(self):
78-
runStartJVMTest('-Djava.class.path=%s' % cp, convertStrings=False)
78+
jpype.startJVM('-Djava.class.path=%s' % cp, convertStrings=False)
79+
assert jpype.JClass('jpype.array.TestArray') is not None
7980

8081
def testClasspathArgPath(self):
81-
runStartJVMTest(classpath=Path(cp), convertStrings=False)
82+
jpype.startJVM(classpath=Path(cp), convertStrings=False)
83+
assert jpype.JClass('jpype.array.TestArray') is not None
8284

8385
def testClasspathArgPathList(self):
84-
runStartJVMTest(classpath=[Path(cp)], convertStrings=False)
86+
jpype.startJVM(classpath=[Path(cp)], convertStrings=False)
87+
assert jpype.JClass('jpype.array.TestArray') is not None
8588

8689
def testClasspathArgGlob(self):
8790
jpype.startJVM(classpath=os.path.join(cp, '..', 'jar', 'mrjar*'))
8891
assert jpype.JClass('org.jpype.mrjar.A') is not None
8992

9093
def testClasspathTwice(self):
9194
with self.assertRaises(TypeError):
92-
runStartJVMTest('-Djava.class.path=%s' %
95+
jpype.startJVM('-Djava.class.path=%s' %
9396
cp, classpath=cp, convertStrings=False)
9497

9598
def testClasspathBadType(self):
9699
with self.assertRaises(TypeError):
97-
runStartJVMTest(classpath=1, convertStrings=False)
100+
jpype.startJVM(classpath=1, convertStrings=False)
98101

99102
def testJVMPathArg_Str(self):
100-
runStartJVMTest(self.jvmpath, classpath=cp, convertStrings=False)
103+
jpype.startJVM(self.jvmpath, classpath=cp, convertStrings=False)
104+
assert jpype.JClass('jpype.array.TestArray') is not None
101105

102106
def testJVMPathArg_None(self):
103107
# It is allowed to pass None as a JVM path
104-
runStartJVMTest(None, classpath=cp, )
108+
jpype.startJVM(
109+
None, # type: ignore
110+
classpath=cp,
111+
)
112+
assert jpype.JClass('jpype.array.TestArray') is not None
105113

106114
def testJVMPathArg_NoArgs(self):
107-
runStartJVMTest(classpath=cp)
115+
jpype.startJVM(
116+
classpath=cp,
117+
)
118+
assert jpype.JClass('jpype.array.TestArray') is not None
108119

109120
def testJVMPathArg_Path(self):
110121
with self.assertRaises(TypeError):
111-
runStartJVMTest(
122+
jpype.startJVM(
112123
# Pass a path as the first argument. This isn't supported (this is
113124
# reflected in the type definition), but the fact that it "works"
114125
# gives rise to this test.
115-
Path(self.jvmpath), # type: ignore
116-
classpath=cp,
126+
Path(self.jvmpath), # type: ignore
117127
convertStrings=False,
118128
)
119129

120130
def testJVMPathKeyword_str(self):
121-
runStartJVMTest(classpath=cp, jvmpath=self.jvmpath,
122-
convertStrings=False)
131+
jpype.startJVM(
132+
classpath=cp,
133+
jvmpath=self.jvmpath,
134+
convertStrings=False,
135+
)
136+
assert jpype.JClass('jpype.array.TestArray') is not None
123137

124138
def testJVMPathKeyword_Path(self):
125-
runStartJVMTest(jvmpath=Path(self.jvmpath), classpath=cp, convertStrings=False)
139+
jpype.startJVM(jvmpath=Path(self.jvmpath), classpath=cp, convertStrings=False)
140+
assert jpype.JClass('jpype.array.TestArray') is not None
126141

127142
def testPathTwice(self):
128143
with self.assertRaises(TypeError):
129144
jpype.startJVM(self.jvmpath, jvmpath=self.jvmpath)
130145

131146
def testBadKeyword(self):
132147
with self.assertRaises(TypeError):
133-
jpype.startJVM(invalid=True)
148+
jpype.startJVM(invalid=True) # type: ignore

0 commit comments

Comments
 (0)
Please sign in to comment.