import unittest import sys from os import path # <AK> added from jt import jpyutil from . import test_dir # <AK> added jpyutil.init_jvm(jvm_maxmem='512M', jvm_classpath=[path.join(test_dir,"java","classes")]) import jpy class TestJavaArrays(unittest.TestCase): def do_test_basic_array_protocol_with_length(self, type, initial, expected): #*** jtypes extension ***# with self.assertRaises(ValueError, msg="ValueError expected") as e: jpy.array(type, -3) self.assertEqual(str(e.exception), "array: argument 2 (init) must be either an integer array length or any sequence") #*** jtypes extension ***# a = jpy.array(type, 3) self.assertEqual(len(a), 3) self.assertEqual(a[0], initial[0]) self.assertEqual(a[1], initial[1]) self.assertEqual(a[2], initial[2]) a[0] = expected[0] a[1] = expected[1] a[2] = expected[2] return a def do_test_array_with_initializer(self, type, expected):
import unittest import sys from jt import jpyutil jpyutil.init_jvm(jvm_maxmem='512M') import jpy class TestString(unittest.TestCase): """ Tests various Java SE classes from rt.jar """ def setUp(self): self.String = jpy.get_type('java.lang.String') self.assertIsNotNone(self.String) def test_constructor(self): s = self.String('Bibo') self.assertEqual(type(s), self.String) self.assertEqual(str(s), 'Bibo') def test_unicode_constructor_with_py27(self): # This test is actually the same as test_constructor(), but 'str' is not 'unicode' in Python 2.7 s = self.String(u'Bibo') self.assertEqual(type(s), self.String) self.assertEqual(str(s), 'Bibo') def test_toString(self): s = self.String('Bibo') self.assertTrue('toString' in self.String.__dict__)