Debian Codegraph @

src/test/python/jpy_typeres_test.py

raw symbols SCIP
1 import unittest
2
3 import jpyutil
4
5
6 jpyutil.init_jvm(jvm_maxmem='512M', jvm_classpath=['target/test-classes'])
7 import jpy
8
9
10 class TestTypeResolution(unittest.TestCase):
11 def setUp(self):
12 self.Fixture = jpy.get_type('org.jpy.fixtures.TypeResolutionTestFixture')
13 self.assertIsNotNone(self.Fixture)
14
15
16 def test_ThatTypeIsResolvedLate(self):
17 self.assertTrue('org.jpy.fixtures.TypeResolutionTestFixture' in jpy.types)
18 self.assertTrue('org.jpy.fixtures.TypeResolutionTestFixture$SuperThing' in jpy.types)
19 self.assertTrue('org.jpy.fixtures.Thing' in jpy.types)
20
21 fixture = self.Fixture()
22
23 # Create a thing instance, the type 'org.jpy.fixtures.Thing' is not resolved yet
24 thing = fixture.createSuperThing(2001)
25
26 # Assert that 'org.jpy.fixtures.Thing' is not resolved yet
27 SuperThing = jpy.types['org.jpy.fixtures.TypeResolutionTestFixture$SuperThing']
28 self.assertFalse('add' in SuperThing.__dict__)
29
30 # Assert that 'org.jpy.fixtures.Thing' is not resolved yet
31 Thing = jpy.types['org.jpy.fixtures.Thing']
32 self.assertFalse('getValue' in Thing.__dict__)
33
34 # Calling 'add()' on SuperThing will resolve 'org.jpy.fixtures.Thing'
35 thing.add(10)
36 self.assertTrue('add' in SuperThing.__dict__)
37 self.assertTrue('getValue' in Thing.__dict__)
38
39 value = thing.getValue()
40 self.assertEqual(value, 2011)
41
42 # see https://github.com/bcdev/jpy/issues/63
43 def test_ThatJavaTypesHaveAValidClassAttribute(self):
44 Long = jpy.get_type('java.lang.Long')
45 self.assertIsNotNone(Long.jclass)
46 Class = jpy.get_type('java.lang.Class')
47 self.assertIsNotNone(Class.jclass)
48 Object = jpy.get_type('java.lang.Object')
49 self.assertIsNotNone(Object.jclass)
50
51 # see https://github.com/bcdev/jpy/issues/64
52 def test_ThatInterfaceTypesIncludeMethodsOfExtendedTypes(self):
53 ObjectInput = jpy.get_type('java.io.ObjectInput', resolve=True)
54 # assert that a method declared of java.io.ObjectInput is in __dict__
55 self.assertTrue('readObject' in ObjectInput.__dict__)
56 # assert that a method declared of java.io.DataInput is in __dict__
57 self.assertTrue('readLine' in ObjectInput.__dict__)
58
59
60
61 if __name__ == '__main__':
62 print('\nRunning ' + __file__)
63 unittest.main()