Debian Codegraph @

test/jpypetest/test_map.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
21
22 class JMapTestCase(common.JPypeTestCase):
23 """ Test for methods of java.lang.Map
24 """
25
26 def setUp(self):
27 common.JPypeTestCase.setUp(self)
28
29 def testLen(self):
30 cls = jpype.JClass('java.util.HashMap')
31 obj = cls()
32 obj.put("a", 1)
33 obj.put("b", 2)
34 obj.put("c", 3)
35 self.assertEqual(len(obj), 3)
36
37 def testIter(self):
38 cls = jpype.JClass('java.util.TreeMap')
39 obj = cls()
40 obj.put("a", 1)
41 obj.put("b", 2)
42 obj.put("c", 3)
43 self.assertEqual(tuple(i for i in obj), ('a', 'b', 'c'))
44
45 def testGetItem(self):
46 cls = jpype.JClass('java.util.HashMap')
47 obj = cls()
48 obj.put("a", 1)
49 obj.put("b", 2)
50 obj.put("c", 3)
51 self.assertEqual(obj['b'], 2)
52
53 def testSetItem(self):
54 cls = jpype.JClass('java.util.HashMap')
55 obj = cls()
56 obj.put("a", 1)
57 obj.put("b", 2)
58 obj.put("c", 3)
59 obj['b'] = 5
60 self.assertEqual(obj['b'], 5)
61
62 def testSetItem_2(self):
63 cls = jpype.JClass('java.util.TreeMap')
64 obj = cls()
65 obj.put("a", 1)
66 obj.put("b", 2)
67 obj.put("c", 3)
68 del obj['b']
69 self.assertEqual(tuple(i for i in obj), ('a', 'c'))