Debian Codegraph @

test/jpypetest/test_core.py

raw symbols SCIP
1 # *****************************************************************************
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 # See NOTICE file for details.
16 #
17 # *****************************************************************************
18 from unittest import mock
19 import jpype
20 import common
21 from jpype.types import *
22
23
24 class JCharTestCase(common.JPypeTestCase):
25 def setUp(self):
26 common.JPypeTestCase.setUp(self)
27
28 def testShutdownHook(self):
29 Thread = JClass("java.lang.Thread")
30 Runnable = JClass("java.lang.Runnable")
31 Runtime = JClass("java.lang.Runtime")
32 @jpype.JImplements(Runnable)
33 class Run:
34 @jpype.JOverride
35 def run(self):
36 pass
37 th = Thread(Run())
38 Runtime.getRuntime().addShutdownHook(th)
39 self.assertTrue(Runtime.getRuntime().removeShutdownHook(th))
40
41 def testShutdownWrongThread(self):
42 Thread = JClass("java.lang.Thread")
43 Runnable = JClass("java.lang.Runnable")
44 @jpype.JImplements(Runnable)
45 class Run:
46 def __init__(self):
47 self.rc = False
48
49 @jpype.JOverride
50 def run(self):
51 try:
52 jpype.shutdownJVM()
53 except:
54 self.rc = True
55 run = Run()
56 th = Thread(run)
57 th.start()
58 th.join()
59 self.assertTrue(run.rc)