Debian Codegraph @

test/jpypetest/test_jpackage.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 jpype
20 from jpype.types import *
21 from jpype import JPackage
22 import common
23
24
25 class JPackageTestCase(common.JPypeTestCase):
26
27 def setUp(self):
28 common.JPypeTestCase.setUp(self)
29 self.jl = JPackage('java.lang')
30
31 def testCreate(self):
32 self.assertEqual(self.jl.String, JClass('java.lang.String'))
33
34 def testFail0(self):
35 with self.assertRaises(TypeError):
36 JPackage(1)
37
38 # def testFail1(self):
39 # #with self.assertRaises(RuntimeError):
40 # jl = JPackage('java.nosuch')
41
42 def testFail2(self):
43 with self.assertRaises(AttributeError):
44 self.jl.NoSuch
45
46 def testFail3(self):
47 with self.assertRaises(AttributeError):
48 self.jl.bar
49
50 def testStr(self):
51 self.assertIsInstance(str(self.jl), str)
52 self.assertEqual(str(self.jl), "java.lang")
53
54 def testRepr(self):
55 self.assertIsInstance(repr(self.jl), str)
56 self.assertEqual(repr(self.jl), "<java package 'java.lang'>")
57
58 def testCall(self):
59 with self.assertRaises(TypeError):
60 self.jl()
61
62 def testDir(self):
63 self.assertIsInstance(dir(self.jl), list)
64
65 def testGetAttr(self):
66 with self.assertRaises(TypeError):
67 self.jl.__getattribute__(object())
68
69 def testSetAttr(self):
70 with self.assertRaises(TypeError):
71 self.jl.__setattr__(object(), 1)
72
73 def testInvalid(self):
74 JL = JPackage("java.lng")
75 with self.assertRaisesRegex(AttributeError, "Java package 'java.lng' is not valid"):
76 getattr(JL, "foo")