Debian Codegraph @

test/jpypetest/test_functional.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 def callFunctional(cls, i):
23 fun = cls @(lambda x: x)
24 return fun.call(i)
25
26
27 class FunctionalTestCase(common.JPypeTestCase):
28
29 def _checkValidFunctional(self, name, value):
30 cls = jpype.JClass("jpype.functional." + name)
31 self.assertEqual(callFunctional(cls, value), value)
32
33 def testAnnotated(self):
34 self._checkValidFunctional("Annotated", 0)
35
36 def testNonAnnotated(self):
37 self._checkValidFunctional("NonAnnotated", 1)
38
39 def testExtendsFunctional(self):
40 self._checkValidFunctional("ExtendsFunctional", 2)
41
42 def testExtendsNonFunctional(self):
43 with self.assertRaises(TypeError):
44 self._checkValidFunctional("ExtendsNonFunctional", 3)
45
46 def testAnnotatedWithObjectMethods(self):
47 self._checkValidFunctional("AnnotatedWithObjectMethods", 4)
48
49 def testNonAnnotatedWithObjectMethods(self):
50 self._checkValidFunctional("NonAnnotatedWithObjectMethods", 5)
51
52 def testRedeclaresAnnotated(self):
53 self._checkValidFunctional("RedeclaresAnnotated", 6)
54
55 def testRedeclaresNonAnnotated(self):
56 self._checkValidFunctional("RedeclaresNonAnnotated", 7)
57
58 def testStaticDefaultMethods(self):
59 # Predicate has both static and default methods
60 Predicate = jpype.JClass("java.util.function.Predicate")
61 fun = Predicate @ (lambda x: True)
62 self.assertTrue(fun.test(fun))