| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import unittest |
| 19 |
|
| 20 |
import _jpype |
| 21 |
import jpype |
| 22 |
from jpype import * |
| 23 |
import common |
| 24 |
|
| 25 |
|
| 26 |
class FaultTestCase(common.JPypeTestCase): |
| 27 |
""" Test for fault paths in JPype |
| 28 |
|
| 29 |
This test is only executed if fault instrumentation is compiled in. |
| 30 |
Fault instrumentation is trigger as part of the coverage compilation. |
| 31 |
|
| 32 |
This test suite brutally tries to force an exception to be thrown |
| 33 |
at each entry point and function call. The exception is controlled |
| 34 |
based on the name of the function in the JP_TRACE_IN and JP_PY_TRY |
| 35 |
block. Specific fault points are also triggered to produce |
| 36 |
abnormal objects which can then be passed to trigger error handling |
| 37 |
behaviors for off normal conditions. |
| 38 |
|
| 39 |
Most of the time the correct response to a fault is to pass it back |
| 40 |
to the user. But there are two exception to this rule. Function |
| 41 |
in which a Java resource is released using a Release* method must not |
| 42 |
fault because these calls can occur during exception handling routines |
| 43 |
and throwing may trigger an abort. Second, Python calls to free, |
| 44 |
finalize, and dealloc are not allowed to propagate exceptions as |
| 45 |
this would potentially interrupt the GC or prevent a object from being |
| 46 |
freed. Exceptions during the destructor path should be eaten or |
| 47 |
they may trigger randomly in places the user can't control (assigning |
| 48 |
a variable, leaving a scope). |
| 49 |
|
| 50 |
Many of these tests will be moved to other test units so that they |
| 51 |
are located with rest of the tests for that unit. Tests that |
| 52 |
test for something other than SystemError should be separated from |
| 53 |
the rest of the fault test. |
| 54 |
|
| 55 |
This may be one of the most tedious files every written by human hands. |
| 56 |
Coffee is advised. |
| 57 |
|
| 58 |
""" |
| 59 |
|
| 60 |
def setUp(self): |
| 61 |
common.JPypeTestCase.setUp(self) |
| 62 |
|
| 63 |
@common.requireInstrumentation |
| 64 |
def testJPArray_new(self): |
| 65 |
_jpype.fault("PyJPArray_new") |
| 66 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 67 |
JArray(JInt)(5) |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
@common.unittest.SkipTest |
| 72 |
def testJPArray_releaseBuffer(self): |
| 73 |
_jpype.fault("PyJPArray_releaseBuffer") |
| 74 |
|
| 75 |
def f(): |
| 76 |
ja = JArray(JInt)(5) |
| 77 |
m = memoryview(ja) |
| 78 |
with self.assertRaises(SystemError): |
| 79 |
f() |
| 80 |
|
| 81 |
@common.requireInstrumentation |
| 82 |
def testJPObject_null(self): |
| 83 |
Fixture = JClass("jpype.common.Fixture") |
| 84 |
_jpype.fault("PyJPObject_init.null") |
| 85 |
null = Fixture() |
| 86 |
with self.assertRaisesRegex(TypeError, 'Not a Java value'): |
| 87 |
str(null) |
| 88 |
self.assertEqual(hash(null), hash(None)) |
| 89 |
with self.assertRaisesRegex(AttributeError, 'requires'): |
| 90 |
print(null.int_field) |
| 91 |
with self.assertRaisesRegex(AttributeError, 'requires'): |
| 92 |
null.int_field = 1 |
| 93 |
|
| 94 |
|
| 95 |
@common.requireInstrumentation |
| 96 |
def testJPClass_init(self): |
| 97 |
_jpype.fault("PyJPClass_init") |
| 98 |
with self.assertRaises(SystemError): |
| 99 |
_jpype._JClass("foo", (_jpype._JObject,), {}, internal=True) |
| 100 |
with self.assertRaises(TypeError): |
| 101 |
_jpype._JClass("foo", (object,), {}) |
| 102 |
_jpype._JClass("foo", (_jpype._JObject,), {}, internal=True) |
| 103 |
|
| 104 |
@common.requireInstrumentation |
| 105 |
def testJPClass_getattro(self): |
| 106 |
js = JClass("java.lang.String") |
| 107 |
_jpype.fault("PyJPClass_getattro") |
| 108 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 109 |
js.foo |
| 110 |
with self.assertRaises(TypeError): |
| 111 |
getattr(js, object()) |
| 112 |
_jpype.fault("PyJPModule_getContext") |
| 113 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 114 |
js.substring |
| 115 |
|
| 116 |
@common.requireInstrumentation |
| 117 |
def testJPClass_setattro(self): |
| 118 |
js = JClass("java.lang.String") |
| 119 |
_jpype.fault("PyJPClass_setattro") |
| 120 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 121 |
js.substring = 1 |
| 122 |
with self.assertRaises(TypeError): |
| 123 |
setattr(js, object(), 1) |
| 124 |
with self.assertRaises(AttributeError): |
| 125 |
js.substring = None |
| 126 |
_jpype.fault("PyJPModule_getContext") |
| 127 |
with self.assertRaises(SystemError): |
| 128 |
js.substring = 1 |
| 129 |
|
| 130 |
@common.requireInstrumentation |
| 131 |
def testJPClass_subclasscheck(self): |
| 132 |
js = JClass("java.lang.String") |
| 133 |
_jpype.fault("PyJPClass_subclasscheck") |
| 134 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 135 |
issubclass(js, JObject) |
| 136 |
_jpype.fault("PyJPModule_getContext") |
| 137 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 138 |
issubclass(js, JObject) |
| 139 |
|
| 140 |
@common.requireInstrumentation |
| 141 |
def testJPClass_class(self): |
| 142 |
js = JClass("java.lang.String") |
| 143 |
_jpype.fault("PyJPClass_class") |
| 144 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 145 |
js.class_ |
| 146 |
with self.assertRaises(AttributeError): |
| 147 |
_jpype._JClass("foo", (_jpype.JObject,), {}, internal=True).class_ |
| 148 |
_jpype.fault("PyJPModule_getContext") |
| 149 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 150 |
js.class_ |
| 151 |
|
| 152 |
@common.requireInstrumentation |
| 153 |
def testJPClass_setClass(self): |
| 154 |
js = JClass("java.lang.String") |
| 155 |
_jpype.fault("PyJPClass_setClass") |
| 156 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 157 |
js.class_ = None |
| 158 |
with self.assertRaises(TypeError): |
| 159 |
js.class_ = None |
| 160 |
with self.assertRaises(TypeError): |
| 161 |
js.class_ = JObject() |
| 162 |
_jpype.fault("PyJPModule_getContext") |
| 163 |
with self.assertRaises(SystemError): |
| 164 |
js.class_ = None |
| 165 |
|
| 166 |
@common.requireInstrumentation |
| 167 |
def testJPClass_hints(self): |
| 168 |
js = JClass("java.lang.String") |
| 169 |
_jpype.fault("PyJPClass_hints") |
| 170 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 171 |
js._hints |
| 172 |
_jpype.fault("PyJPModule_getContext") |
| 173 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 174 |
js._hints |
| 175 |
self.assertIsInstance(js._hints, _jpype._JClassHints) |
| 176 |
|
| 177 |
@common.requireInstrumentation |
| 178 |
def testJPClass_setHints(self): |
| 179 |
js = JClass("java.lang.String") |
| 180 |
_jpype.fault("PyJPClass_setHints") |
| 181 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 182 |
js._hints = None |
| 183 |
|
| 184 |
@common.requireInstrumentation |
| 185 |
def testJPClass_cnaConvertToJava(self): |
| 186 |
js = JClass("java.lang.String") |
| 187 |
_jpype.fault("PyJPClass_canConvertToJava") |
| 188 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 189 |
js._canConvertToJava("f") |
| 190 |
_jpype.fault("PyJPModule_getContext") |
| 191 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 192 |
js._canConvertToJava("f") |
| 193 |
js._canConvertToJava("f") |
| 194 |
|
| 195 |
@common.requireInstrumentation |
| 196 |
def testJPClass_cast(self): |
| 197 |
js = JClass("java.lang.String") |
| 198 |
_jpype.fault("PyJPClass_cast") |
| 199 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 200 |
js._cast("f") |
| 201 |
with self.assertRaises(TypeError): |
| 202 |
js._cast(object()) |
| 203 |
_jpype.fault("PyJPModule_getContext") |
| 204 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 205 |
js._cast(JObject(None)) |
| 206 |
js._cast(JObject(None)) |
| 207 |
|
| 208 |
@common.requireInstrumentation |
| 209 |
def testJPClass_convertToJava(self): |
| 210 |
js = JClass("java.lang.String") |
| 211 |
_jpype.fault("PyJPClass_convertToJava") |
| 212 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 213 |
js._convertToJava("f") |
| 214 |
with self.assertRaises(TypeError): |
| 215 |
js._convertToJava(object()) |
| 216 |
_jpype.fault("PyJPModule_getContext") |
| 217 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 218 |
js._convertToJava("f") |
| 219 |
js._convertToJava("f") |
| 220 |
|
| 221 |
@common.requireInstrumentation |
| 222 |
def testJPClassHints_new(self): |
| 223 |
_jpype.fault("PyJPClassHints_new") |
| 224 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 225 |
_jpype._JClassHints() |
| 226 |
_jpype._JClassHints() |
| 227 |
|
| 228 |
@common.requireInstrumentation |
| 229 |
def testJPClassHints_init(self): |
| 230 |
_jpype.fault("PyJPClassHints_init") |
| 231 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 232 |
_jpype._JClassHints() |
| 233 |
_jpype._JClassHints() |
| 234 |
|
| 235 |
@common.requireInstrumentation |
| 236 |
def testJPClassHints_str(self): |
| 237 |
_jpype.fault("PyJPClassHints_str") |
| 238 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 239 |
str(_jpype._JClassHints()) |
| 240 |
str(_jpype._JClassHints()) |
| 241 |
|
| 242 |
@common.requireInstrumentation |
| 243 |
def testJPClassHints_addAttributeConversion(self): |
| 244 |
_jpype.fault("PyJPClassHints_addAttributeConversion") |
| 245 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 246 |
_jpype._JClassHints()._addAttributeConversion("f", None) |
| 247 |
|
| 248 |
def f(): |
| 249 |
pass |
| 250 |
with self.assertRaises(TypeError): |
| 251 |
_jpype._JClassHints()._addAttributeConversion(None, f) |
| 252 |
with self.assertRaises(TypeError): |
| 253 |
_jpype._JClassHints()._addAttributeConversion("f", None) |
| 254 |
_jpype._JClassHints()._addAttributeConversion("f", f) |
| 255 |
|
| 256 |
@common.requireInstrumentation |
| 257 |
def testJPClassHints_addTypeConversion(self): |
| 258 |
_jpype.fault("PyJPClassHints_addTypeConversion") |
| 259 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 260 |
_jpype._JClassHints()._addTypeConversion("f", None) |
| 261 |
|
| 262 |
def f(): |
| 263 |
pass |
| 264 |
|
| 265 |
|
| 266 |
with self.assertRaises(TypeError): |
| 267 |
_jpype._JClassHints()._addTypeConversion(str, None, 1) |
| 268 |
_jpype._JClassHints()._addTypeConversion(str, f, 1) |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
@common.requireInstrumentation |
| 279 |
def testJPMonitor_init(self): |
| 280 |
jo = JClass("java.lang.Object")() |
| 281 |
_jpype.fault("PyJPMonitor_init") |
| 282 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 283 |
_jpype._JMonitor(jo) |
| 284 |
_jpype.fault("PyJPModule_getContext") |
| 285 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 286 |
_jpype._JMonitor(jo) |
| 287 |
_jpype._JMonitor(jo) |
| 288 |
|
| 289 |
@common.requireInstrumentation |
| 290 |
def testJPMonitor_str(self): |
| 291 |
jo = JClass("java.lang.Object")() |
| 292 |
jm = _jpype._JMonitor(jo) |
| 293 |
_jpype.fault("PyJPMonitor_str") |
| 294 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 295 |
str(jm) |
| 296 |
|
| 297 |
@common.requireInstrumentation |
| 298 |
def testJPMonitor_enter(self): |
| 299 |
jo = JClass("java.lang.Object")() |
| 300 |
_jpype.fault("PyJPMonitor_enter") |
| 301 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 302 |
with _jpype._JMonitor(jo): |
| 303 |
pass |
| 304 |
_jpype.fault("PyJPModule_getContext") |
| 305 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 306 |
with _jpype._JMonitor(jo): |
| 307 |
pass |
| 308 |
|
| 309 |
@common.requireInstrumentation |
| 310 |
def testJPMonitor_exit(self): |
| 311 |
jo = JClass("java.lang.Object")() |
| 312 |
_jpype.fault("PyJPMonitor_exit") |
| 313 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 314 |
with _jpype._JMonitor(jo): |
| 315 |
pass |
| 316 |
|
| 317 |
@common.requireInstrumentation |
| 318 |
def testJPObject_new(self): |
| 319 |
_jpype.fault("PyJPObject_new") |
| 320 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 321 |
JString("a") |
| 322 |
_jpype.fault("PyJPModule_getContext") |
| 323 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 324 |
JString("a") |
| 325 |
with self.assertRaises(TypeError): |
| 326 |
_jpype._JObject() |
| 327 |
JString("a") |
| 328 |
|
| 329 |
@common.requireInstrumentation |
| 330 |
def testJPObject_hash(self): |
| 331 |
jo = JClass("java.lang.Object")() |
| 332 |
_jpype.fault("PyJPObject_hash") |
| 333 |
with self.assertRaises(SystemError): |
| 334 |
hash(jo) |
| 335 |
_jpype.fault("PyJPModule_getContext") |
| 336 |
with self.assertRaises(SystemError): |
| 337 |
hash(jo) |
| 338 |
hash(jo) |
| 339 |
|
| 340 |
@common.requireInstrumentation |
| 341 |
def testJPProxy_new(self): |
| 342 |
_jpype.fault("PyJPProxy_new") |
| 343 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 344 |
JProxy("java.io.Serializable", dict={}) |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
@common.unittest.SkipTest |
| 360 |
def testJPProxy_str(self): |
| 361 |
|
| 362 |
@JImplements("java.util.function.DoubleUnaryOperator") |
| 363 |
class f(object): |
| 364 |
@JOverride |
| 365 |
def applyAsDouble(self, d): |
| 366 |
return d |
| 367 |
jo = JObject(f(), "java.util.function.DoubleUnaryOperator") |
| 368 |
raise RuntimeError(jo.toString()) |
| 369 |
|
| 370 |
@common.requireInstrumentation |
| 371 |
def testJPProxy_dealloc(self): |
| 372 |
_jpype.fault("PyJPProxy_dealloc") |
| 373 |
|
| 374 |
def f(): |
| 375 |
_jpype._JProxy(None, None, [JClass("java.io.Serializable")]) |
| 376 |
f() |
| 377 |
|
| 378 |
@common.requireInstrumentation |
| 379 |
def testJPProxy_call(self): |
| 380 |
@JImplements("java.util.function.DoubleUnaryOperator") |
| 381 |
class f(object): |
| 382 |
@JOverride |
| 383 |
def applyAsDouble(self, d): |
| 384 |
if d == 2: |
| 385 |
return None |
| 386 |
return d |
| 387 |
_jpype.fault("JPProxy::getProxy") |
| 388 |
with self.assertRaises(SystemError): |
| 389 |
JObject(f(), "java.util.function.DoubleUnaryOperator") |
| 390 |
jo = JObject(f(), "java.util.function.DoubleUnaryOperator") |
| 391 |
with self.assertRaises(TypeError): |
| 392 |
jo.applyAsDouble(2) |
| 393 |
|
| 394 |
def testJPProxy_void(self): |
| 395 |
@JImplements("java.util.function.Consumer") |
| 396 |
class f(object): |
| 397 |
@JOverride |
| 398 |
def accept(self, d): |
| 399 |
return None |
| 400 |
jo = JObject(f(), "java.util.function.Consumer") |
| 401 |
jo.accept(None) |
| 402 |
|
| 403 |
@common.requireInstrumentation |
| 404 |
def testJPProxy_void_2(self): |
| 405 |
@JImplements("java.util.function.Consumer") |
| 406 |
class f(object): |
| 407 |
@JOverride |
| 408 |
def accept(self, d): |
| 409 |
return None |
| 410 |
jo = JObject(f(), "java.util.function.Consumer") |
| 411 |
_jpype.fault("JPProxy::getArgs") |
| 412 |
jo.accept(None) |
| 413 |
|
| 414 |
@common.requireInstrumentation |
| 415 |
def testJPProxy_box_return(self): |
| 416 |
q = None |
| 417 |
@JImplements("java.util.function.Supplier") |
| 418 |
class f(object): |
| 419 |
@JOverride |
| 420 |
def get(self): |
| 421 |
return q |
| 422 |
jo = JObject(f(), "java.util.function.Supplier") |
| 423 |
self.assertEqual(jo.get(), None) |
| 424 |
q = 1.0 |
| 425 |
self.assertIsInstance(jo.get(), java.lang.Double) |
| 426 |
q = 1 |
| 427 |
self.assertIsInstance(jo.get(), java.lang.Long) |
| 428 |
q = "ABC" |
| 429 |
self.assertIsInstance(jo.get(), java.lang.String) |
| 430 |
q = object() |
| 431 |
with self.assertRaises(TypeError): |
| 432 |
jo.get() |
| 433 |
|
| 434 |
@common.requireInstrumentation |
| 435 |
def testJPValue_alloc(self): |
| 436 |
_jpype.fault("PyJPValue_alloc") |
| 437 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 438 |
JInt(1) |
| 439 |
_jpype.fault("PyJPModule_getContext") |
| 440 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 441 |
JInt(1) |
| 442 |
JInt(1) |
| 443 |
|
| 444 |
@common.requireInstrumentation |
| 445 |
def testJPValue_finalize(self): |
| 446 |
_jpype.fault("PyJPValue_finalize") |
| 447 |
a = JInt(1) |
| 448 |
del a |
| 449 |
|
| 450 |
@common.requireInstrumentation |
| 451 |
def testJPValue_str(self): |
| 452 |
js = JString("f") |
| 453 |
_jpype.fault("PyJPValue_str") |
| 454 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 455 |
str(js) |
| 456 |
_jpype.fault("PyJPModule_getContext") |
| 457 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 458 |
str(js) |
| 459 |
str(js) |
| 460 |
|
| 461 |
@common.requireInstrumentation |
| 462 |
def testJPObject_getattro(self): |
| 463 |
jo = JString("f") |
| 464 |
_jpype.fault("PyJPObject_getattro") |
| 465 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 466 |
jo.substring |
| 467 |
_jpype.fault("PyJPModule_getContext") |
| 468 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 469 |
jo.substring |
| 470 |
jo.substring |
| 471 |
|
| 472 |
@common.requireInstrumentation |
| 473 |
def testJPObject_setattro(self): |
| 474 |
jo = JString("f") |
| 475 |
_jpype.fault("PyJPObject_setattro") |
| 476 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 477 |
jo.substring = None |
| 478 |
|
| 479 |
@common.requireInstrumentation |
| 480 |
def testJPField(self): |
| 481 |
jf = JClass("jpype.common.Fixture") |
| 482 |
jfi = jf() |
| 483 |
with self.assertRaises(AttributeError): |
| 484 |
jf.final_static_int_field = 2 |
| 485 |
with self.assertRaises(AttributeError): |
| 486 |
jfi.final_int_field = 2 |
| 487 |
_jpype.fault("JPField::setStaticAttribute") |
| 488 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 489 |
jf.static_int_field = 2 |
| 490 |
_jpype.fault("JPField::setAttribute") |
| 491 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 492 |
jfi.int_field = 2 |
| 493 |
_jpype.fault("JPField::getStaticAttribute") |
| 494 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 495 |
i = jf.static_int_field |
| 496 |
_jpype.fault("JPField::getAttribute") |
| 497 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 498 |
i = jfi.int_field |
| 499 |
si = jf.__dict__['static_int_field'] |
| 500 |
str(si) |
| 501 |
repr(si) |
| 502 |
i = None |
| 503 |
_jpype.fault("PyJPField_get") |
| 504 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 505 |
i = jfi.int_field |
| 506 |
self.assertEqual(i, None) |
| 507 |
_jpype.fault("PyJPField_set") |
| 508 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 509 |
jfi.int_field = 2 |
| 510 |
_jpype.fault("PyJPField_repr") |
| 511 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 512 |
repr(si) |
| 513 |
|
| 514 |
@common.requireInstrumentation |
| 515 |
def testConvertString(self): |
| 516 |
_jpype.fault("JPObjectType::canConvertToJava") |
| 517 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 518 |
JObject._convertToJava("foo") |
| 519 |
_jpype.fault("JPConversionString::matches") |
| 520 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 521 |
JString._convertToJava("foo") |
| 522 |
|
| 523 |
@common.requireInstrumentation |
| 524 |
def testJPObject(self): |
| 525 |
jf = JClass("jpype.common.Fixture") |
| 526 |
jfi = JClass("jpype.common.Fixture")() |
| 527 |
_jpype.fault("JPClass::setStaticField") |
| 528 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 529 |
jf.static_object_field = None |
| 530 |
_jpype.fault("JPClass::setField") |
| 531 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 532 |
jfi.object_field = None |
| 533 |
i = None |
| 534 |
_jpype.fault("JPClass::getStaticField") |
| 535 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 536 |
i = jf.static_object_field |
| 537 |
_jpype.fault("JPClass::getField") |
| 538 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 539 |
i = jfi.object_field |
| 540 |
self.assertEqual(i, None) |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
@common.unittest.SkipTest |
| 547 |
@common.requireInstrumentation |
| 548 |
def testJPTypeManagerFindClass(self): |
| 549 |
ja = JArray(JInt, 2)([[1, 1], [1, 1]]) |
| 550 |
_jpype.fault("JPTypeManager::findClass") |
| 551 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 552 |
memoryview(ja) |
| 553 |
_jpype.fault("JPTypeManager::findClassByName") |
| 554 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 555 |
JClass("foo.bar") |
| 556 |
jo = JString('a') |
| 557 |
_jpype.fault("JPTypeManager::findClassForObject") |
| 558 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 559 |
jo.substring(0, 1) |
| 560 |
|
| 561 |
@common.requireInstrumentation |
| 562 |
def testJPTypeManagerPopulate(self): |
| 563 |
_jpype.fault("JPTypeManager::populateMembers") |
| 564 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 565 |
JClass("java.math.MathContext") |
| 566 |
_jpype.fault("JPTypeManager::populateMethod") |
| 567 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 568 |
JClass("java.math.MathContext")().getPrecision() |
| 569 |
JClass("java.math.MathContext") |
| 570 |
|
| 571 |
@common.requireInstrumentation |
| 572 |
def testMethodPack(self): |
| 573 |
js = JString("a") |
| 574 |
_jpype.fault("JPMethod::packArgs") |
| 575 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 576 |
js.substring(1) |
| 577 |
|
| 578 |
@common.requireInstrumentation |
| 579 |
def testJBoxedGetJavaConversion(self): |
| 580 |
_jpype.fault("JPBoxedType::findJavaConversion") |
| 581 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 582 |
java.lang.Boolean._canConvertToJava(object()) |
| 583 |
_jpype.fault("JPBoxedType::findJavaConversion") |
| 584 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 585 |
java.lang.Character._canConvertToJava(object()) |
| 586 |
_jpype.fault("JPBoxedType::findJavaConversion") |
| 587 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 588 |
java.lang.Byte._canConvertToJava(object()) |
| 589 |
_jpype.fault("JPBoxedType::findJavaConversion") |
| 590 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 591 |
java.lang.Short._canConvertToJava(object()) |
| 592 |
_jpype.fault("JPBoxedType::findJavaConversion") |
| 593 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 594 |
java.lang.Integer._canConvertToJava(object()) |
| 595 |
_jpype.fault("JPBoxedType::findJavaConversion") |
| 596 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 597 |
java.lang.Long._canConvertToJava(object()) |
| 598 |
_jpype.fault("JPBoxedType::findJavaConversion") |
| 599 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 600 |
java.lang.Float._canConvertToJava(object()) |
| 601 |
_jpype.fault("JPBoxedType::findJavaConversion") |
| 602 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 603 |
java.lang.Double._canConvertToJava(object()) |
| 604 |
|
| 605 |
@common.requireInstrumentation |
| 606 |
def testJPJavaFrame(self): |
| 607 |
_jpype.fault("JPJavaFrame::JPJavaFrame::NewObjectA") |
| 608 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 609 |
raise SystemError("fault") |
| 610 |
_jpype.fault("JPJavaFrame::JPJavaFrame::NewObject") |
| 611 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 612 |
raise SystemError("fault") |
| 613 |
_jpype.fault("JPJavaFrame::NewDirectByteBuffer") |
| 614 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 615 |
raise SystemError("fault") |
| 616 |
_jpype.fault("JPJavaFrame::GetPrimitiveArrayCritical") |
| 617 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 618 |
raise SystemError("fault") |
| 619 |
_jpype.fault("JPJavaFrame::ReleasePrimitiveArrayCritical") |
| 620 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 621 |
raise SystemError("fault") |
| 622 |
|
| 623 |
@common.requireInstrumentation |
| 624 |
def testJPJavaFrameByteField(self): |
| 625 |
fields = JClass("jpype.common.Fixture")() |
| 626 |
_jpype.fault("JPJavaFrame::GetStaticByteField") |
| 627 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 628 |
print(fields.static_byte_field) |
| 629 |
_jpype.fault("JPJavaFrame::GetByteField") |
| 630 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 631 |
print(fields.byte_field) |
| 632 |
_jpype.fault("JPJavaFrame::SetStaticByteField") |
| 633 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 634 |
fields.static_byte_field = 1 |
| 635 |
_jpype.fault("JPJavaFrame::SetByteField") |
| 636 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 637 |
fields.byte_field = 0 |
| 638 |
|
| 639 |
@common.requireInstrumentation |
| 640 |
def testJPJavaFrameByteMethods(self): |
| 641 |
cls = JClass("jpype.common.Fixture") |
| 642 |
obj = cls() |
| 643 |
_jpype.fault("JPJavaFrame::CallStaticByteMethodA") |
| 644 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 645 |
cls.getStaticByte() |
| 646 |
_jpype.fault("JPJavaFrame::CallByteMethodA") |
| 647 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 648 |
obj.getByte() |
| 649 |
_jpype.fault("JPJavaFrame::CallNonvirtualByteMethodA") |
| 650 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 651 |
cls.getByte(obj) |
| 652 |
|
| 653 |
@common.requireInstrumentation |
| 654 |
def testJPJavaFrameShortField(self): |
| 655 |
fields = JClass("jpype.common.Fixture")() |
| 656 |
_jpype.fault("JPJavaFrame::GetStaticShortField") |
| 657 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 658 |
print(fields.static_short_field) |
| 659 |
_jpype.fault("JPJavaFrame::GetShortField") |
| 660 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 661 |
print(fields.short_field) |
| 662 |
_jpype.fault("JPJavaFrame::SetStaticShortField") |
| 663 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 664 |
fields.static_short_field = 1 |
| 665 |
_jpype.fault("JPJavaFrame::SetShortField") |
| 666 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 667 |
fields.short_field = 1 |
| 668 |
|
| 669 |
@common.requireInstrumentation |
| 670 |
def testJPJavaFrameShortMethod(self): |
| 671 |
cls = JClass("jpype.common.Fixture") |
| 672 |
obj = cls() |
| 673 |
_jpype.fault("JPJavaFrame::CallStaticShortMethodA") |
| 674 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 675 |
cls.getStaticShort() |
| 676 |
_jpype.fault("JPJavaFrame::CallShortMethodA") |
| 677 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 678 |
obj.getShort() |
| 679 |
_jpype.fault("JPJavaFrame::CallNonvirtualShortMethodA") |
| 680 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 681 |
cls.getShort(obj) |
| 682 |
|
| 683 |
@common.requireInstrumentation |
| 684 |
def testJPJavaFrameIntField(self): |
| 685 |
fields = JClass("jpype.common.Fixture")() |
| 686 |
_jpype.fault("JPJavaFrame::GetStaticIntField") |
| 687 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 688 |
print(fields.static_int_field) |
| 689 |
_jpype.fault("JPJavaFrame::GetIntField") |
| 690 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 691 |
print(fields.int_field) |
| 692 |
_jpype.fault("JPJavaFrame::SetStaticIntField") |
| 693 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 694 |
fields.static_int_field = 1 |
| 695 |
_jpype.fault("JPJavaFrame::SetIntField") |
| 696 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 697 |
fields.int_field = 1 |
| 698 |
|
| 699 |
@common.requireInstrumentation |
| 700 |
def testJPJavaFrameIntMethod(self): |
| 701 |
cls = JClass("jpype.common.Fixture") |
| 702 |
obj = cls() |
| 703 |
_jpype.fault("JPJavaFrame::CallStaticIntMethodA") |
| 704 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 705 |
cls.getStaticInt() |
| 706 |
_jpype.fault("JPJavaFrame::CallIntMethodA") |
| 707 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 708 |
obj.getInt() |
| 709 |
_jpype.fault("JPJavaFrame::CallNonvirtualIntMethodA") |
| 710 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 711 |
cls.getInt(obj) |
| 712 |
|
| 713 |
@common.requireInstrumentation |
| 714 |
def testJPJavaFrameLongField(self): |
| 715 |
fields = JClass("jpype.common.Fixture")() |
| 716 |
_jpype.fault("JPJavaFrame::GetStaticLongField") |
| 717 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 718 |
print(fields.static_long_field) |
| 719 |
_jpype.fault("JPJavaFrame::GetLongField") |
| 720 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 721 |
print(fields.long_field) |
| 722 |
_jpype.fault("JPJavaFrame::SetStaticLongField") |
| 723 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 724 |
fields.static_long_field = 1 |
| 725 |
_jpype.fault("JPJavaFrame::SetLongField") |
| 726 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 727 |
fields.long_field = 1 |
| 728 |
|
| 729 |
@common.requireInstrumentation |
| 730 |
def testJPJavaFrameLongMethod(self): |
| 731 |
cls = JClass("jpype.common.Fixture") |
| 732 |
obj = cls() |
| 733 |
_jpype.fault("JPJavaFrame::CallStaticLongMethodA") |
| 734 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 735 |
cls.getStaticLong() |
| 736 |
_jpype.fault("JPJavaFrame::CallLongMethodA") |
| 737 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 738 |
obj.getLong() |
| 739 |
_jpype.fault("JPJavaFrame::CallNonvirtualLongMethodA") |
| 740 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 741 |
cls.getLong(obj) |
| 742 |
|
| 743 |
@common.requireInstrumentation |
| 744 |
def testJPJavaFrameFloatField(self): |
| 745 |
fields = JClass("jpype.common.Fixture")() |
| 746 |
_jpype.fault("JPJavaFrame::GetStaticFloatField") |
| 747 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 748 |
print(fields.static_float_field) |
| 749 |
_jpype.fault("JPJavaFrame::GetFloatField") |
| 750 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 751 |
print(fields.float_field) |
| 752 |
_jpype.fault("JPJavaFrame::SetStaticFloatField") |
| 753 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 754 |
fields.static_float_field = 1 |
| 755 |
_jpype.fault("JPJavaFrame::SetFloatField") |
| 756 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 757 |
fields.float_field = 1 |
| 758 |
|
| 759 |
@common.requireInstrumentation |
| 760 |
def testJPJavaFrameFloatMethod(self): |
| 761 |
cls = JClass("jpype.common.Fixture") |
| 762 |
obj = cls() |
| 763 |
_jpype.fault("JPJavaFrame::CallStaticFloatMethodA") |
| 764 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 765 |
cls.getStaticFloat() |
| 766 |
_jpype.fault("JPJavaFrame::CallFloatMethodA") |
| 767 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 768 |
obj.getFloat() |
| 769 |
_jpype.fault("JPJavaFrame::CallNonvirtualFloatMethodA") |
| 770 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 771 |
cls.getFloat(obj) |
| 772 |
|
| 773 |
@common.requireInstrumentation |
| 774 |
def testJPJavaFrameDoubleField(self): |
| 775 |
fields = JClass("jpype.common.Fixture")() |
| 776 |
_jpype.fault("JPJavaFrame::GetStaticDoubleField") |
| 777 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 778 |
print(fields.static_double_field) |
| 779 |
_jpype.fault("JPJavaFrame::GetDoubleField") |
| 780 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 781 |
print(fields.double_field) |
| 782 |
_jpype.fault("JPJavaFrame::SetStaticDoubleField") |
| 783 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 784 |
fields.static_double_field = 1 |
| 785 |
_jpype.fault("JPJavaFrame::SetDoubleField") |
| 786 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 787 |
fields.double_field = 1 |
| 788 |
|
| 789 |
@common.requireInstrumentation |
| 790 |
def testJPJavaFrameDoubleMethod(self): |
| 791 |
cls = JClass("jpype.common.Fixture") |
| 792 |
obj = cls() |
| 793 |
_jpype.fault("JPJavaFrame::CallStaticDoubleMethodA") |
| 794 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 795 |
cls.getStaticDouble() |
| 796 |
_jpype.fault("JPJavaFrame::CallDoubleMethodA") |
| 797 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 798 |
obj.getDouble() |
| 799 |
_jpype.fault("JPJavaFrame::CallNonvirtualDoubleMethodA") |
| 800 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 801 |
cls.getDouble(obj) |
| 802 |
|
| 803 |
@common.requireInstrumentation |
| 804 |
def testJPJavaFrameCharField(self): |
| 805 |
fields = JClass("jpype.common.Fixture")() |
| 806 |
_jpype.fault("JPJavaFrame::GetStaticCharField") |
| 807 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 808 |
print(fields.static_char_field) |
| 809 |
_jpype.fault("JPJavaFrame::GetCharField") |
| 810 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 811 |
print(fields.char_field) |
| 812 |
_jpype.fault("JPJavaFrame::SetStaticCharField") |
| 813 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 814 |
fields.static_char_field = 1 |
| 815 |
_jpype.fault("JPJavaFrame::SetCharField") |
| 816 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 817 |
fields.char_field = 1 |
| 818 |
|
| 819 |
@common.requireInstrumentation |
| 820 |
def testJPJavaFrameCharMethod(self): |
| 821 |
cls = JClass("jpype.common.Fixture") |
| 822 |
obj = cls() |
| 823 |
_jpype.fault("JPJavaFrame::CallStaticCharMethodA") |
| 824 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 825 |
cls.getStaticChar() |
| 826 |
_jpype.fault("JPJavaFrame::CallCharMethodA") |
| 827 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 828 |
obj.getChar() |
| 829 |
_jpype.fault("JPJavaFrame::CallNonvirtualCharMethodA") |
| 830 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 831 |
cls.getChar(obj) |
| 832 |
|
| 833 |
@common.requireInstrumentation |
| 834 |
def testJPJavaFrameBooleanField(self): |
| 835 |
fields = JClass("jpype.common.Fixture")() |
| 836 |
_jpype.fault("JPJavaFrame::GetStaticBooleanField") |
| 837 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 838 |
print(fields.static_bool_field) |
| 839 |
_jpype.fault("JPJavaFrame::GetBooleanField") |
| 840 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 841 |
print(fields.bool_field) |
| 842 |
_jpype.fault("JPJavaFrame::SetStaticBooleanField") |
| 843 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 844 |
fields.static_bool_field = 1 |
| 845 |
_jpype.fault("JPJavaFrame::SetBooleanField") |
| 846 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 847 |
fields.bool_field = 1 |
| 848 |
|
| 849 |
@common.requireInstrumentation |
| 850 |
def testJPJavaFrameBooleanMethod(self): |
| 851 |
cls = JClass("jpype.common.Fixture") |
| 852 |
obj = cls() |
| 853 |
_jpype.fault("JPJavaFrame::CallStaticBooleanMethodA") |
| 854 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 855 |
cls.getStaticBool() |
| 856 |
_jpype.fault("JPJavaFrame::CallBooleanMethodA") |
| 857 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 858 |
obj.getBool() |
| 859 |
_jpype.fault("JPJavaFrame::CallNonvirtualBooleanMethodA") |
| 860 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 861 |
cls.getBool(obj) |
| 862 |
|
| 863 |
@common.requireInstrumentation |
| 864 |
def testJPJavaFrameObjectField(self): |
| 865 |
fields = JClass("jpype.common.Fixture")() |
| 866 |
_jpype.fault("JPJavaFrame::GetStaticObjectField") |
| 867 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 868 |
print(fields.static_object_field) |
| 869 |
_jpype.fault("JPJavaFrame::GetObjectField") |
| 870 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 871 |
print(fields.object_field) |
| 872 |
_jpype.fault("JPJavaFrame::SetStaticObjectField") |
| 873 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 874 |
fields.static_object_field = None |
| 875 |
_jpype.fault("JPJavaFrame::SetObjectField") |
| 876 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 877 |
fields.object_field = None |
| 878 |
|
| 879 |
@common.requireInstrumentation |
| 880 |
def testJPJavaFrameObjectMethod(self): |
| 881 |
cls = JClass("jpype.common.Fixture") |
| 882 |
obj = cls() |
| 883 |
_jpype.fault("JPJavaFrame::CallStaticObjectMethodA") |
| 884 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 885 |
cls.getStaticObject() |
| 886 |
_jpype.fault("JPJavaFrame::CallObjectMethodA") |
| 887 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 888 |
obj.getObject() |
| 889 |
_jpype.fault("JPJavaFrame::CallNonvirtualObjectMethodA") |
| 890 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 891 |
cls.getObject(obj) |
| 892 |
|
| 893 |
@common.requireInstrumentation |
| 894 |
def testJPJavaFrameBooleanArray(self): |
| 895 |
_jpype.fault("JPJavaFrame::NewBooleanArray") |
| 896 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 897 |
JArray(JBoolean)(1) |
| 898 |
ja = JArray(JBoolean)(5) |
| 899 |
_jpype.fault("JPJavaFrame::SetBooleanArrayRegion") |
| 900 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 901 |
ja[0] = 0 |
| 902 |
_jpype.fault("JPJavaFrame::GetBooleanArrayRegion") |
| 903 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 904 |
print(ja[0]) |
| 905 |
_jpype.fault("JPJavaFrame::GetBooleanArrayElements") |
| 906 |
with self.assertRaises(BufferError): |
| 907 |
memoryview(ja[0:3]) |
| 908 |
_jpype.fault("JPJavaFrame::ReleaseBooleanArrayElements") |
| 909 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 910 |
ja[0:3] = bytes([1, 2, 3]) |
| 911 |
_jpype.fault("JPJavaFrame::ReleaseBooleanArrayElements") |
| 912 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 913 |
jpype.JObject(ja[::2], jpype.JObject) |
| 914 |
_jpype.fault("JPJavaFrame::ReleaseBooleanArrayElements") |
| 915 |
|
| 916 |
def f(): |
| 917 |
|
| 918 |
memoryview(ja[0:3]) |
| 919 |
f() |
| 920 |
|
| 921 |
@common.requireInstrumentation |
| 922 |
def testJPJavaFrameMonitor(self): |
| 923 |
jo = JClass("java.lang.Object")() |
| 924 |
_jpype.fault("JPJavaFrame::MonitorEnter") |
| 925 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 926 |
with jpype.synchronized(jo): |
| 927 |
pass |
| 928 |
_jpype.fault("JPJavaFrame::MonitorExit") |
| 929 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 930 |
with jpype.synchronized(jo): |
| 931 |
pass |
| 932 |
|
| 933 |
@common.requireInstrumentation |
| 934 |
def testJPJavaFrameMonitor_2(self): |
| 935 |
_jpype.fault("JPJavaFrame::FromReflectedMethod") |
| 936 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 937 |
raise SystemError("fault") |
| 938 |
_jpype.fault("JPJavaFrame::FromReflectedField") |
| 939 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 940 |
raise SystemError("fault") |
| 941 |
_jpype.fault("JPJavaFrame::FindClass") |
| 942 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 943 |
raise SystemError("fault") |
| 944 |
|
| 945 |
@common.requireInstrumentation |
| 946 |
def testJPJavaFrameObjectArray(self): |
| 947 |
_jpype.fault("JPJavaFrame::NewObjectArray") |
| 948 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 949 |
JArray(JObject)(1) |
| 950 |
ja = JArray(JObject)(1) |
| 951 |
_jpype.fault("JPJavaFrame::SetObjectArrayElement") |
| 952 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 953 |
ja[0] = None |
| 954 |
_jpype.fault("JPJavaFrame::GetObjectArrayElement") |
| 955 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 956 |
print(ja[0]) |
| 957 |
|
| 958 |
@common.requireInstrumentation |
| 959 |
def testJPJavaFrameVoidMethod(self): |
| 960 |
_jpype.fault("JPJavaFrame::CallStaticVoidMethodA") |
| 961 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 962 |
raise SystemError("fault") |
| 963 |
_jpype.fault("JPJavaFrame::CallVoidMethodA") |
| 964 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 965 |
raise SystemError("fault") |
| 966 |
_jpype.fault("JPJavaFrame::CallVoidMethodA") |
| 967 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 968 |
raise SystemError("fault") |
| 969 |
_jpype.fault("None") |
| 970 |
|
| 971 |
@common.requireInstrumentation |
| 972 |
def testJPJavaFrameAssignable(self): |
| 973 |
_jpype.fault("JPJavaFrame::IsAssignableFrom") |
| 974 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 975 |
issubclass(JString, JObject) |
| 976 |
|
| 977 |
@common.requireInstrumentation |
| 978 |
def testJPJavaFrameString(self): |
| 979 |
_jpype.fault("JPJavaFrame::NewString") |
| 980 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 981 |
JString("aa") |
| 982 |
_jpype.fault("JPJavaFrame::GetStringUTFChars") |
| 983 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 984 |
str(JString("a")) |
| 985 |
_jpype.fault("JPJavaFrame::ReleaseStringUTFChars") |
| 986 |
|
| 987 |
|
| 988 |
str(JString("a")) |
| 989 |
_jpype.fault("JPJavaFrame::GetStringUTFLength") |
| 990 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 991 |
str(JString("a")) |
| 992 |
|
| 993 |
@common.requireInstrumentation |
| 994 |
def testJPJavaFrameArrayLength(self): |
| 995 |
_jpype.fault("JPJavaFrame::GetArrayLength") |
| 996 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 997 |
JArray(JInt)(5) |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
@common.requireInstrumentation |
| 1017 |
def testJPClassTypeGetJavaConversion(self): |
| 1018 |
jc = JClass("java.lang.StringBuilder") |
| 1019 |
_jpype.fault("JPClass::findJavaConversion") |
| 1020 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1021 |
jc._canConvertToJava(object()) |
| 1022 |
|
| 1023 |
@jpype.JConversion("java.lang.StringBuilder", exact=object) |
| 1024 |
def f(self, obj): |
| 1025 |
raise SystemError("fail") |
| 1026 |
with self.assertRaisesRegex(SystemError, "fail"): |
| 1027 |
jc._convertToJava(object()) |
| 1028 |
|
| 1029 |
@common.requireInstrumentation |
| 1030 |
def testStartup(self): |
| 1031 |
_jpype.fault("PyJPModule_startup") |
| 1032 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1033 |
_jpype.startup() |
| 1034 |
|
| 1035 |
@common.requireInstrumentation |
| 1036 |
def testShutdown(self): |
| 1037 |
_jpype.fault("PyJPModule_shutdown") |
| 1038 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1039 |
_jpype.shutdown() |
| 1040 |
|
| 1041 |
@common.requireInstrumentation |
| 1042 |
def testAttachThread(self): |
| 1043 |
_jpype.fault("PyJPModule_attachThread") |
| 1044 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1045 |
_jpype.attachThreadToJVM() |
| 1046 |
|
| 1047 |
@common.requireInstrumentation |
| 1048 |
def testAttachThreadAsDaemon(self): |
| 1049 |
_jpype.fault("PyJPModule_attachThreadAsDaemon") |
| 1050 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1051 |
_jpype.attachThreadAsDaemon() |
| 1052 |
|
| 1053 |
@common.requireInstrumentation |
| 1054 |
def testDetachThreadFault(self): |
| 1055 |
_jpype.fault("PyJPModule_detachThread") |
| 1056 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1057 |
_jpype.detachThreadFromJVM() |
| 1058 |
|
| 1059 |
def testDetachThread(self): |
| 1060 |
self.assertTrue(_jpype.isThreadAttachedToJVM()) |
| 1061 |
_jpype.detachThreadFromJVM() |
| 1062 |
self.assertFalse(_jpype.isThreadAttachedToJVM()) |
| 1063 |
_jpype.attachThreadToJVM() |
| 1064 |
|
| 1065 |
@common.requireInstrumentation |
| 1066 |
def testIsThreadAttached(self): |
| 1067 |
_jpype.fault("PyJPModule_isThreadAttached") |
| 1068 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1069 |
_jpype.isThreadAttachedToJVM() |
| 1070 |
|
| 1071 |
@common.requireInstrumentation |
| 1072 |
def testConvertToDirectBufferFault(self): |
| 1073 |
_jpype.fault("PyJPModule_convertToDirectByteBuffer") |
| 1074 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1075 |
_jpype.convertToDirectBuffer(1, False) |
| 1076 |
|
| 1077 |
def testConvertToDirectBufferExc(self): |
| 1078 |
with self.assertRaisesRegex(TypeError, "buffer support"): |
| 1079 |
_jpype.convertToDirectBuffer(1, False) |
| 1080 |
with self.assertRaisesRegex(BufferError, "not writable"): |
| 1081 |
_jpype.convertToDirectBuffer(bytes([1, 2, 3]), False) |
| 1082 |
with self.assertRaisesRegex(TypeError, "function takes exactly 2 arguments"): |
| 1083 |
_jpype.convertToDirectBuffer(bytes([1, 2, 3])) |
| 1084 |
|
| 1085 |
def testStartupBadArg(self): |
| 1086 |
with self.assertRaisesRegex(TypeError, "takes exactly"): |
| 1087 |
_jpype.startup() |
| 1088 |
with self.assertRaisesRegex(TypeError, "must be tuple"): |
| 1089 |
_jpype.startup(object(), object(), True, True, True, None) |
| 1090 |
with self.assertRaisesRegex(TypeError, "must be strings"): |
| 1091 |
_jpype.startup("", (object(),), True, True, True, None) |
| 1092 |
with self.assertRaisesRegex(TypeError, "must be a string"): |
| 1093 |
_jpype.startup(object(), tuple(), True, True, True, None) |
| 1094 |
with self.assertRaisesRegex(TypeError, "must be a string"): |
| 1095 |
_jpype.startup("", tuple(), True, True, True, object()) |
| 1096 |
with self.assertRaisesRegex(OSError, "started"): |
| 1097 |
_jpype.startup("", tuple(), True, True, True, None) |
| 1098 |
|
| 1099 |
def testGetClass(self): |
| 1100 |
with self.assertRaisesRegex(TypeError, "not found"): |
| 1101 |
_jpype._getClass("not.a.class") |
| 1102 |
|
| 1103 |
def testHasClass(self): |
| 1104 |
with self.assertRaisesRegex(TypeError, "not found"): |
| 1105 |
_jpype._hasClass("not.a.class") |
| 1106 |
with self.assertRaisesRegex(TypeError, "str is required"): |
| 1107 |
_jpype._hasClass(object()) |
| 1108 |
|
| 1109 |
def testArrayFromBuffer(self): |
| 1110 |
with self.assertRaisesRegex(TypeError, "2 arguments"): |
| 1111 |
_jpype.arrayFromBuffer() |
| 1112 |
with self.assertRaisesRegex(TypeError, "does not support buffers"): |
| 1113 |
_jpype.arrayFromBuffer(object(), object()) |
| 1114 |
|
| 1115 |
def testArrayNewType(self): |
| 1116 |
with self.assertRaisesRegex(TypeError, "2 arguments"): |
| 1117 |
_jpype._newArrayType() |
| 1118 |
with self.assertRaisesRegex(TypeError, "must be an integer"): |
| 1119 |
_jpype._newArrayType(object(), object()) |
| 1120 |
with self.assertRaisesRegex(TypeError, "class required"): |
| 1121 |
_jpype._newArrayType(object(), 1) |
| 1122 |
|
| 1123 |
@common.requireInstrumentation |
| 1124 |
def testClassHintsFaults(self): |
| 1125 |
class CTest(object): |
| 1126 |
pass |
| 1127 |
|
| 1128 |
@JConversion("java.lang.Number", exact=CTest) |
| 1129 |
def _CTestConversion(jcls, obj): |
| 1130 |
return java.lang.Integer(123) |
| 1131 |
|
| 1132 |
class ATest(object): |
| 1133 |
def __foo__(self): |
| 1134 |
pass |
| 1135 |
|
| 1136 |
@JConversion("java.lang.Number", attribute="__foo__") |
| 1137 |
def _ATestConversion(jcls, obj): |
| 1138 |
return java.lang.Integer(123) |
| 1139 |
|
| 1140 |
fixture = JClass("jpype.common.Fixture")() |
| 1141 |
_jpype.fault("JPPythonConversion::convert") |
| 1142 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1143 |
fixture.callNumber(CTest()) |
| 1144 |
_jpype.fault("JPAttributeConversion::matches") |
| 1145 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1146 |
fixture.callNumber(ATest()) |
| 1147 |
_jpype.fault("JPClassHints::addAttributeConversion") |
| 1148 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1149 |
@JConversion("java.lang.Number", attribute="__woo__") |
| 1150 |
def f(jcls, obj): |
| 1151 |
pass |
| 1152 |
_jpype.fault("JPTypeConversion::matches") |
| 1153 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1154 |
fixture.callNumber(CTest()) |
| 1155 |
_jpype.fault("JPClassHints::addTypeConversion") |
| 1156 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1157 |
@JConversion("java.lang.Number", exact=CTest) |
| 1158 |
def f(jcls, obj): |
| 1159 |
pass |
| 1160 |
|
| 1161 |
@common.requireInstrumentation |
| 1162 |
def testConversionFaults(self): |
| 1163 |
fixture = JClass("jpype.common.Fixture")() |
| 1164 |
_jpype.fault("JPConversionCharArray::matches") |
| 1165 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1166 |
fixture.callCharArray(object()) |
| 1167 |
_jpype.fault("JPConversionByteArray::matches") |
| 1168 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1169 |
fixture.callByteArray(object()) |
| 1170 |
_jpype.fault("JPConversionNull::matches") |
| 1171 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1172 |
fixture.callObject(None) |
| 1173 |
_jpype.fault("JPConversionClass::matches") |
| 1174 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1175 |
fixture.callClass(object()) |
| 1176 |
_jpype.fault("JPConversionObject::matches") |
| 1177 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1178 |
fixture.callObject(object()) |
| 1179 |
_jpype.fault("JPConversionJavaObjectAny::matches") |
| 1180 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1181 |
fixture.callObject(object()) |
| 1182 |
_jpype.fault("JPConversionJavaNumberAny::matches") |
| 1183 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1184 |
fixture.callNumber(object()) |
| 1185 |
_jpype.fault("JPConversionString::matches") |
| 1186 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1187 |
fixture.callString(object()) |
| 1188 |
_jpype.fault("JPConversionBoxBoolean::matches") |
| 1189 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1190 |
fixture.callObject(object()) |
| 1191 |
_jpype.fault("JPConversionBoxLong::matches") |
| 1192 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1193 |
fixture.callObject(object()) |
| 1194 |
_jpype.fault("JPConversionBoxDouble::matches") |
| 1195 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1196 |
fixture.callObject(object()) |
| 1197 |
_jpype.fault("JPConversionProxy::matches") |
| 1198 |
with self.assertRaisesRegex(SystemError, "fault"): |
| 1199 |
fixture.callObject(object()) |