Debian Codegraph @

test/jpypetest/test_thread.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 import jpype
19 import common
20 import pytest
21
22 from jpype.imports import *
23
24
25 class ThreadTestCase(common.JPypeTestCase):
26 def setUp(self):
27 common.JPypeTestCase.setUp(self)
28
29 @pytest.mark.filterwarnings("ignore::DeprecationWarning")
30 def testAttach(self):
31 # Make sure we are attached to start the test
32 jpype.attachThreadToJVM()
33 self.assertTrue(jpype.isThreadAttachedToJVM())
34
35 # Detach from the thread
36 jpype.detachThreadFromJVM()
37 self.assertFalse(jpype.isThreadAttachedToJVM())
38
39 # Reattach to the thread
40 jpype.attachThreadToJVM()
41 self.assertTrue(jpype.isThreadAttachedToJVM())
42
43 # Detach again
44 jpype.detachThreadFromJVM()
45 self.assertFalse(jpype.isThreadAttachedToJVM())
46
47 # Call a Java method which will cause it to attach automatically
48 s = jpype.JString("foo")
49 self.assertTrue(jpype.isThreadAttachedToJVM())
50
51 def testAttachNew(self):
52 import java
53 # Detach the thread
54 java.lang.Thread.detach()
55 self.assertFalse(java.lang.Thread.isAttached())
56
57 # Attach as a main thread
58 java.lang.Thread.attach()
59 self.assertTrue(java.lang.Thread.isAttached())
60 self.assertFalse(java.lang.Thread.currentThread().isDaemon())
61
62 # Detach the thread
63 java.lang.Thread.detach()
64 self.assertFalse(java.lang.Thread.isAttached())
65
66 # Attach as a daemon thread
67 java.lang.Thread.attachAsDaemon()
68 self.assertTrue(java.lang.Thread.isAttached())
69 self.assertTrue(java.lang.Thread.currentThread().isDaemon())