Index: Lib/test/test_java_list_delegate.py =================================================================== --- Lib/test/test_java_list_delegate.py (revision 6252) +++ Lib/test/test_java_list_delegate.py (working copy) @@ -21,17 +21,17 @@ except Exception, e: return type(e) - def check_list(self, control, results, initial): - for result in results: + def check_list(self, control, results, list_type_names, initial, test_name): + for result, n in zip(results, list_type_names): try: len(result) except: print result - self.assertEquals(len(control), len(result), "%s is wrong for %s" % (type(result), initial)) + self.assertEquals(len(control), len(result), "%s: length for %s does not match that of list" % (test_name, n)) for pvalue, jvalue in zip(control, result): - self.assertEquals(pvalue, jvalue) + self.assertEquals(pvalue, jvalue, "%s: values from %s do not match those from list" % (test_name, n)) - def _list_op_test(self, initial_value, op_func, check_value): + def _list_op_test(self, initial_value, op_func, test_name): """ Tests a list operation @@ -39,24 +39,33 @@ - a python list - a java.util.List instance - givens the same result in both cases + gives the same result in both cases """ lists = [list(initial_value), ArrayList(initial_value), Vector(initial_value)] + list_type_names = ['list', 'ArrayList', 'Vector'] results = [self._perform_op(l, op_func) for l in lists] - self.check_list(lists[0], lists[1:], initial_value) - if check_value or not isinstance(results[0], list): - for r in results[1:]: - self.assertEquals(results[0], r) + self.check_list(lists[0], lists[1:], list_type_names[1:], initial_value, test_name) + if not isinstance(results[0], list): + for r,n in zip(results[1:], list_type_names[1:]): + self.assertEquals(results[0], r, '%s: result for list does not match result for java type %s' % (test_name,n) ) else: - self.check_list(results[0], results[1:], initial_value) + self.check_list(results[0], results[1:], list_type_names[1:], initial_value, test_name) def test_get_integer(self): initial_value = range(0, 5) for i in xrange(-7, 7): - self._list_op_test(initial_value, lambda xs: xs[i], True) + self._list_op_test(initial_value, lambda xs: xs[i], 'get_integer [%d]' % (i,)) + def test_get_slice(self): + initial_value = range(0, 10) + + for i in xrange(-12, 12): + for j in xrange(-12, 12): + for k in xrange(-12, 12): + self._list_op_test(initial_value, lambda xs: xs[i:j:k], 'get_slice [%d:%d:%d]' % (i,j,k)) + def test_set_integer(self): initial_value = range(0, 5) @@ -66,7 +75,7 @@ return _f for i in xrange(-7, 7): - self._list_op_test(initial_value, make_op_func(i), True) + self._list_op_test(initial_value, make_op_func(i), 'set_integer [%d]' % (i,)) def test_set_slice(self): initial_value = range(0, 10) @@ -79,10 +88,10 @@ for i in xrange(-12, 12): for j in xrange(-12, 12): for k in xrange(-12, 12): - self._list_op_test(initial_value, make_op_func(i, j, k, []), True) - self._list_op_test(initial_value, make_op_func(i, j, k, range(0,2)), True) - self._list_op_test(initial_value, make_op_func(i, j, k, range(0,4)), True) - self._list_op_test(initial_value, make_op_func(i, j, k, xrange(0,2)), True) + self._list_op_test(initial_value, make_op_func(i, j, k, []), 'set_slice [%d:%d:%d]=[]' % (i,j,k)) + self._list_op_test(initial_value, make_op_func(i, j, k, range(0,2)), 'set_slice [%d:%d:%d]=range(0,2)' % (i,j,k)) + self._list_op_test(initial_value, make_op_func(i, j, k, range(0,4)), 'set_slice [%d:%d:%d]=range(0,4)' % (i,j,k)) + self._list_op_test(initial_value, make_op_func(i, j, k, xrange(0,2)), 'set_slice [%d:%d:%d]=xrange(0,2)' % (i,j,k)) def test_del_integer(self): initial_value = range(0,5) @@ -93,7 +102,7 @@ return _f for i in xrange(-7, 7): - self._list_op_test(initial_value, make_op_func(i), True) + self._list_op_test(initial_value, make_op_func(i), 'del_integer [%d]' % (i,)) def test_del_slice(self): initial_value = range(0,10) @@ -106,7 +115,7 @@ for i in xrange(-12, 12): for j in xrange(-12, 12): for k in xrange(-12, 12): - self._list_op_test(initial_value, make_op_func(i, j, k), True) + self._list_op_test(initial_value, make_op_func(i, j, k), 'del_slice [%d:%d:%d]' % (i,j,k)) def test_len(self): jlist = ArrayList() Index: src/org/python/core/PyList.java =================================================================== --- src/org/python/core/PyList.java (revision 6252) +++ src/org/python/core/PyList.java (working copy) @@ -813,7 +813,22 @@ @Override public Iterator iterator() { - return list.iterator(); + return new Iterator() { + + private final Iterator iter = list.iterator(); + + public boolean hasNext() { + return iter.hasNext(); + } + + public Object next() { + return iter.next().__tojava__(Object.class); + } + + public void remove() { + iter.remove(); + } + }; } @Override