| 1 |
|
| 2 |
import unittest |
| 3 |
|
| 4 |
import jpyutil |
| 5 |
|
| 6 |
jpyutil.init_jvm(jvm_maxmem='512M', jvm_classpath=['target/test-classes']) |
| 7 |
import jpy |
| 8 |
|
| 9 |
|
| 10 |
class DummyWrapper: |
| 11 |
def __init__(self, theThing): |
| 12 |
self.theThing = theThing |
| 13 |
|
| 14 |
def getValue(self): |
| 15 |
return 2 * self.theThing.getValue() |
| 16 |
|
| 17 |
|
| 18 |
def make_wrapper(type, thing): |
| 19 |
return DummyWrapper(thing) |
| 20 |
|
| 21 |
|
| 22 |
class TestTypeTranslation(unittest.TestCase): |
| 23 |
def setUp(self): |
| 24 |
self.Fixture = jpy.get_type('org.jpy.fixtures.TypeTranslationTestFixture') |
| 25 |
self.assertIsNotNone(self.Fixture) |
| 26 |
|
| 27 |
def test_Translation(self): |
| 28 |
fixture = self.Fixture() |
| 29 |
thing = fixture.makeThing(7) |
| 30 |
self.assertEqual(thing.getValue(), 7) |
| 31 |
self.assertEqual(repr(type(thing)), "<class 'org.jpy.fixtures.Thing'>") |
| 32 |
|
| 33 |
jpy.type_translations['org.jpy.fixtures.Thing'] = make_wrapper |
| 34 |
thing = fixture.makeThing(8) |
| 35 |
self.assertEqual(thing.getValue(), 16) |
| 36 |
self.assertEqual(type(thing), type(DummyWrapper(None))) |
| 37 |
|
| 38 |
jpy.type_translations['org.jpy.fixtures.Thing'] = None |
| 39 |
self.assertEqual(fixture.makeThing(9).getValue(), 9) |
| 40 |
|
| 41 |
|
| 42 |
if __name__ == '__main__': |
| 43 |
print('\nRunning ' + __file__) |
| 44 |
unittest.main() |