1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
import unittest
import jpype
import _jpype
class TestJpypeModule(unittest.TestCase):
def setUp(self):
self.methods={
'attach': [tuple(["none"]),RuntimeError],
'attachThreadAsDaemon': [tuple(),RuntimeError],
'attachThreadToJVM': [tuple(), RuntimeError],
'convertToDirectBuffer': [tuple(), RuntimeError],
'convertToJValue': [tuple(["a",1]), RuntimeError],
'createProxy': [tuple(['a',(1,2)]), AttributeError],
'detachThreadFromJVM': [tuple(), RuntimeError],
'dumpJVMStats': [tuple(), None],
'findArrayClass': [tuple('double[]'), RuntimeError],
'findClass': [tuple('java.lang.String'), RuntimeError],
'getArrayItem': [tuple([None,1]), TypeError],
'getArrayLength': [tuple([None]), TypeError],
'getArraySlice': [tuple([None,1,2]), TypeError],
'isStarted': [tuple(), None],
'isThreadAttachedToJVM': [tuple(), RuntimeError],
'newArray': [tuple([None,1]), TypeError],
'setArrayItem': [tuple([None,1,2]), TypeError],
'setArraySlice': [tuple([None,1,2,3]), TypeError],
'setConvertStringObjects': [tuple(), RuntimeError],
'setGetClassMethod': [tuple([None]), None],
'setGetJavaArrayClassMethod': [tuple([None]), None],
'setJavaArrayClass': [tuple([None]), None],
'setJavaExceptionClass': [tuple([None]), None],
'setJavaLangObjectClass': [tuple([None]), None],
'setProxyClass': [tuple([None]), None],
'setSpecialConstructorKey': [tuple([None]), None],
'setStringWrapperClass': [tuple([None]), None],
'setWrapperClass': [tuple([None]), None],
'shutdown': [tuple(), RuntimeError],
'startReferenceQueue': [tuple([1]), RuntimeError],
'startup': [tuple([None,tuple([None]),None]), TypeError],
'stopReferenceQueue': [tuple(), RuntimeError],
'synchronized': [tuple(), None],
}
def testEntryPoints(self):
for n,c in self.methods.items():
print('====',n)
method=getattr(_jpype, n)
args=c[0]
expect=c[1]
if expect==None:
method(*args)
else:
self.assertRaises(expect, method, *args)
# This is a special test suite that checks to see that every entry point to the private
# module will safely fail rather than segfaulting. It can't be run with other tests
# as the jvm must not be loaded.
#
# To test use
# nosetests test.bulletproof
|