Debian Codegraph @

test/jpypetest/test_properties.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 subrun
19 import unittest
20 import jpype
21
22
23 @subrun.TestCase
24 class PropertiesTestCase(unittest.TestCase):
25
26 @classmethod
27 def setUpClass(cls):
28 import jpype.beans
29 jpype.startJVM(classpath="test/classes", convertStrings=False)
30
31 def setUp(self):
32 self._bean = jpype.JClass('jpype.properties.TestBean')()
33
34 def testPropertyPublicMethodOverlap(self):
35 self._bean.setProperty1("val")
36 self.assertEqual("getsetval", self._bean.getProperty1())
37
38 def testPublicMethodPropertyOverlap(self):
39 self.assertEqual("method", self._bean.property1())
40
41 def testPropertyProtectedMethodOverlapInvisibleAttribute(self):
42 self._bean.property2 = "val"
43 self.assertEqual("getsetval", self._bean.property2)
44
45 def testProtectedMethodPropertyOverlapInvisibleAttribute(self):
46 self.assertFalse(hasattr(self._bean.property2, '__call__'))
47
48 def testPropertyProtectedMethodOverlapAttribute(self):
49 self._bean.property3 = "val"
50 self.assertEqual("getsetval", self._bean.property3)
51
52 def testProtectedMethodPropertyOverlapAttribute(self):
53 self.assertFalse(hasattr(self._bean.property3, '__call__'))
54
55 def testPropertyProtectedMethodOverlapAttributeSet(self):
56 self._bean.setProperty3("val")
57 self.assertEqual("getsetval", self._bean.property3)
58
59 def testPropertyProtectedMethodOverlapAttributeGet(self):
60 self._bean.property3 = "val"
61 self.assertEqual("getsetval", self._bean.getProperty3())
62
63 def testPrivateAttributeNoThreeCharacterMethodMatchCollision(self):
64 self._bean.property4 = "val"
65 self.assertEqual("abcval", self._bean.abcProperty4())
66
67 def testPropertyOnlySetter(self):
68 self._bean.property5 = "val"
69 self.assertEqual("returnsetval", self._bean.returnProperty5())
70
71 def testPropertyOnlySetterSet(self):
72 self._bean.setProperty5("val")
73 with self.assertRaises(AttributeError):
74 self.assertEqual("setval", self._bean.property5)
75
76 def testPropertyDifferentAttribute(self):
77 self._bean.property6 = "val"
78 self.assertEqual("getsetval", self._bean.property6)
79 self.assertEqual("setval", self._bean.property7)
80
81 def testProertyDifferentAttributeSet(self):
82 self._bean.setProperty6("val")
83 self.assertEqual("getsetval", self._bean.property6)
84 self.assertEqual("setval", self._bean.property7)
85
86 def testHasProperties(self):
87 cls = jpype.JClass("jpype.properties.TestBean")
88 obj = cls()
89 self.assertTrue(isinstance(cls.__dict__['propertyMember'], property))
90 self.assertTrue(isinstance(cls.__dict__['readOnly'], property))
91 self.assertTrue(isinstance(cls.__dict__['writeOnly'], property))
92 self.assertTrue(isinstance(cls.__dict__['with_'], property))
93
94 def testPropertyMember(self):
95 obj = jpype.JClass("jpype.properties.TestBean")()
96 obj.propertyMember = "q"
97 self.assertEqual(obj.propertyMember, "q")
98
99 def testPropertyKeyword(self):
100 obj = jpype.JClass("jpype.properties.TestBean")()
101 obj.with_ = "a"
102 self.assertEqual(obj.with_, "a")
103 self.assertEqual(obj.m5, "a")
104
105 def testPropertyReadOnly(self):
106 # Test readonly
107 obj = jpype.JClass("jpype.properties.TestBean")()
108 obj.m3 = "b"
109 self.assertEqual(obj.readOnly, "b")
110 with self.assertRaises(AttributeError):
111 obj.readOnly = "c"
112
113 def testPropertyWriteOnly(self):
114 # Test writeonly
115 obj = jpype.JClass("jpype.properties.TestBean")()
116 obj.writeOnly = "c"
117 self.assertEqual(obj.m4, "c")
118 with self.assertRaises(AttributeError):
119 x = obj.writeOnly
120
121 def testNoProperties(self):
122 cls = jpype.JClass("jpype.properties.TestBean")
123 with self.assertRaises(KeyError):
124 cls.__dict__['failure1']
125 with self.assertRaises(KeyError):
126 cls.__dict__['failure2']