def testSyncronizedFail(self): with self.assertRaisesRegex(TypeError, "Java object is required"): with jpype.synchronized(object()): pass with self.assertRaisesRegex(TypeError, "Java primitives cannot be used"): with jpype.synchronized(jpype.JInt(1)): pass
def run(self): global glob, success, obj with synchronized(obj): # Increment the global resource glob += 1 # Wait for a while time.sleep(0.1) # If anything else accessed then it was a fail if glob != 1: success = False # Decrement the global resoure glob -= 1
def testSynchronizeFail(self): with self.assertRaises(TypeError): jpype.synchronized("hello")
def testMonitor(self): JI = JClass("java.lang.Integer") with jpype.synchronized(JI) as monitor: self.assertIsInstance(str(monitor), str) self.assertIsInstance(repr(monitor), str)