<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals , absolute_import <EOL> import unittest <EOL> from py4j . compat import unicode <EOL> from py4j . java_gateway import JavaGateway , GatewayParameters <EOL> from py4j . protocol import Py4JJavaError , Py4JError <EOL> from py4j . tests . java_gateway_test import ( <EOL> start_example_app_process , safe_shutdown , sleep ) <EOL> def get_list ( count ) : <EOL> return [ unicode ( i ) for i in range ( count ) ] <EOL> class AutoConvertTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . p = start_example_app_process ( ) <EOL> self . gateway = JavaGateway ( <EOL> gateway_parameters = GatewayParameters ( auto_convert = True ) ) <EOL> def tearDown ( self ) : <EOL> safe_shutdown ( self ) <EOL> self . p . join ( ) <EOL> sleep ( ) <EOL> def testAutoConvert ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> python_list = get_list ( <NUM_LIT:3> ) <EOL> java_list = ex . getList ( <NUM_LIT:3> ) <EOL> self . assertTrue ( java_list . equals ( python_list ) ) <EOL> def testAutoConvertConstructor ( self ) : <EOL> python_list = get_list ( <NUM_LIT:3> ) <EOL> java_list = self . gateway . jvm . java . util . ArrayList ( python_list ) <EOL> self . assertTrue ( java_list . equals ( python_list ) ) <EOL> def testAutoConvertNotByteArray ( self ) : <EOL> self . gateway . jvm . java . nio . ByteBuffer . wrap ( bytearray ( range ( <NUM_LIT:255> ) ) ) <EOL> class ListTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . p = start_example_app_process ( ) <EOL> self . gateway = JavaGateway ( ) <EOL> def tearDown ( self ) : <EOL> safe_shutdown ( self ) <EOL> self . p . join ( ) <EOL> sleep ( ) <EOL> def testJavaListProtocol ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> pList = get_list ( <NUM_LIT:3> ) <EOL> jList = ex . getList ( <NUM_LIT:3> ) <EOL> pList . append ( "<STR_LIT:1>" ) <EOL> jList . append ( "<STR_LIT:1>" ) <EOL> pList . sort ( ) <EOL> jList . sort ( ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList . reverse ( ) <EOL> jList . reverse ( ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> self . assertEqual ( pList . count ( "<STR_LIT:1>" ) , jList . count ( "<STR_LIT:1>" ) ) <EOL> self . assertEqual ( pList . count ( "<STR_LIT:2>" ) , jList . count ( "<STR_LIT:2>" ) ) <EOL> self . assertEqual ( pList . count ( "<STR_LIT>" ) , jList . count ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( max ( pList ) , max ( jList ) ) <EOL> self . assertEqual ( min ( pList ) , min ( jList ) ) <EOL> def testJavaListProtocol2 ( self ) : <EOL> ex = self . gateway . entry_point . getNewExample ( ) <EOL> pList = get_list ( <NUM_LIT:3> ) <EOL> pList2 = get_list ( <NUM_LIT:4> ) <EOL> jList = ex . getList ( <NUM_LIT:3> ) <EOL> jList2 = ex . getList ( <NUM_LIT:4> ) <EOL> pList3 = pList + pList2 <EOL> jList3 = jList + jList2 <EOL> self . assertEqual ( len ( pList3 ) , len ( jList3 ) ) <EOL> self . assertEqual ( str ( pList3 ) , str ( jList3 ) ) <EOL> pList3 = pList * <NUM_LIT:3> <EOL> jList3 = jList * <NUM_LIT:3> <EOL> self . assertEqual ( len ( pList3 ) , len ( jList3 ) ) <EOL> self . assertEqual ( str ( pList3 ) , str ( jList3 ) ) <EOL> pList3 = <NUM_LIT:3> * pList <EOL> jList3 = <NUM_LIT:3> * jList <EOL> self . assertEqual ( len ( pList3 ) , len ( jList3 ) ) <EOL> self . assertEqual ( str ( pList3 ) , str ( jList3 ) ) <EOL> pList3 = pList * <NUM_LIT:0> <EOL> jList3 = jList * <NUM_LIT:0> <EOL> self . assertEqual ( len ( pList3 ) , len ( jList3 ) ) <EOL> self . assertEqual ( str ( pList3 ) , str ( jList3 ) ) <EOL> pList += pList2 <EOL> jList += jList2 <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList2 *= <NUM_LIT:3> <EOL> jList2 *= <NUM_LIT:3> <EOL> self . assertEqual ( len ( pList2 ) , len ( jList2 ) ) <EOL> self . assertEqual ( str ( pList2 ) , str ( jList2 ) ) <EOL> pList2 *= - <NUM_LIT:1> <EOL> jList2 *= - <NUM_LIT:1> <EOL> self . assertEqual ( len ( pList2 ) , len ( jList2 ) ) <EOL> self . assertEqual ( str ( pList2 ) , str ( jList2 ) ) <EOL> def testJavaListGetSlice ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> pList = get_list ( <NUM_LIT:5> ) <EOL> jList = ex . getList ( <NUM_LIT:5> ) <EOL> pSlice = pList [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> jSlice = jList [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . assertEqual ( len ( pSlice ) , len ( jSlice ) ) <EOL> self . assertEqual ( str ( pSlice ) , str ( jSlice ) ) <EOL> pSlice = pList [ <NUM_LIT:0> : <NUM_LIT:0> ] <EOL> jSlice = jList [ <NUM_LIT:0> : <NUM_LIT:0> ] <EOL> self . assertEqual ( len ( pSlice ) , len ( jSlice ) ) <EOL> self . assertEqual ( str ( pSlice ) , str ( jSlice ) ) <EOL> pSlice = pList [ <NUM_LIT:0> : - <NUM_LIT:2> ] <EOL> jSlice = jList [ <NUM_LIT:0> : - <NUM_LIT:2> ] <EOL> self . assertEqual ( len ( pSlice ) , len ( jSlice ) ) <EOL> self . assertEqual ( str ( pSlice ) , str ( jSlice ) ) <EOL> def testJavaListDelSlice ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> pList = get_list ( <NUM_LIT:5> ) <EOL> jList = ex . getList ( <NUM_LIT:5> ) <EOL> del pList [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> del jList [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> def testJavaListSetSlice ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> pList = get_list ( <NUM_LIT:6> ) <EOL> jList = ex . getList ( <NUM_LIT:6> ) <EOL> tList = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> pList [ <NUM_LIT:0> : <NUM_LIT:0> ] = tList <EOL> jList [ <NUM_LIT:0> : <NUM_LIT:0> ] = tList <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList [ <NUM_LIT:1> : <NUM_LIT:2> ] = tList <EOL> jList [ <NUM_LIT:1> : <NUM_LIT:2> ] = tList <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList [ <NUM_LIT:3> : <NUM_LIT:5> ] = tList <EOL> jList [ <NUM_LIT:3> : <NUM_LIT:5> ] = tList <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList [ <NUM_LIT:1> : <NUM_LIT:5> : <NUM_LIT:2> ] = tList <EOL> jList [ <NUM_LIT:1> : <NUM_LIT:5> : <NUM_LIT:2> ] = tList <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList [ <NUM_LIT:0> : <NUM_LIT:4> ] = tList <EOL> jList [ <NUM_LIT:0> : <NUM_LIT:4> ] = tList <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList = get_list ( <NUM_LIT:6> ) <EOL> jList = ex . getList ( <NUM_LIT:6> ) <EOL> try : <EOL> pList [ <NUM_LIT:0> : <NUM_LIT:6> : <NUM_LIT:2> ] = tList <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> self . assertTrue ( True ) <EOL> try : <EOL> jList [ <NUM_LIT:0> : <NUM_LIT:6> : <NUM_LIT:2> ] = tList <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> self . assertTrue ( True ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList = get_list ( <NUM_LIT:6> ) <EOL> jList = ex . getList ( <NUM_LIT:6> ) <EOL> pList [ <NUM_LIT:100> : <NUM_LIT:100> ] = tList <EOL> jList [ <NUM_LIT:100> : <NUM_LIT:100> ] = tList <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList [ <NUM_LIT:1000> : <NUM_LIT> ] = tList <EOL> jList [ <NUM_LIT:1000> : <NUM_LIT> ] = tList <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> try : <EOL> self . assertTrue ( jList . equals ( pList ) ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except Exception : <EOL> self . assertTrue ( True ) <EOL> def testJavaList ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> pList = get_list ( <NUM_LIT:3> ) <EOL> jList = ex . getList ( <NUM_LIT:3> ) <EOL> pList2 = get_list ( <NUM_LIT:3> ) <EOL> jList2 = ex . getList ( <NUM_LIT:3> ) <EOL> self . assertEqual ( hash ( jList ) , hash ( jList2 ) ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> self . assertEqual ( pList , pList2 ) <EOL> self . assertEqual ( jList , jList2 ) <EOL> pList . append ( "<STR_LIT:4>" ) <EOL> jList . append ( "<STR_LIT:4>" ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> self . assertEqual ( pList [ <NUM_LIT:0> ] , jList [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( pList [ <NUM_LIT:3> ] , jList [ <NUM_LIT:3> ] ) <EOL> pList . extend ( pList2 ) <EOL> jList . extend ( jList2 ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> self . assertEqual ( "<STR_LIT:1>" in pList , "<STR_LIT:1>" in jList ) <EOL> self . assertEqual ( "<STR_LIT>" in pList , "<STR_LIT>" in jList ) <EOL> pList [ <NUM_LIT:0> ] = "<STR_LIT:100>" <EOL> jList [ <NUM_LIT:0> ] = "<STR_LIT:100>" <EOL> pList [ <NUM_LIT:3> ] = "<STR_LIT>" <EOL> jList [ <NUM_LIT:3> ] = "<STR_LIT>" <EOL> pList [ - <NUM_LIT:1> ] = "<STR_LIT>" <EOL> jList [ - <NUM_LIT:1> ] = "<STR_LIT>" <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList . insert ( <NUM_LIT:0> , "<STR_LIT:100>" ) <EOL> jList . insert ( <NUM_LIT:0> , "<STR_LIT:100>" ) <EOL> pList . insert ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> jList . insert ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> pList . insert ( - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> jList . insert ( - <NUM_LIT:1> , "<STR_LIT>" ) <EOL> pList . insert ( len ( pList ) , "<STR_LIT>" ) <EOL> jList . insert ( len ( pList ) , "<STR_LIT>" ) <EOL> pList . insert ( <NUM_LIT> , "<STR_LIT>" ) <EOL> jList . insert ( <NUM_LIT> , "<STR_LIT>" ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> self . assertEqual ( pList . pop ( ) , jList . pop ( ) ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> self . assertEqual ( pList . pop ( - <NUM_LIT:1> ) , jList . pop ( - <NUM_LIT:1> ) ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> self . assertEqual ( pList . pop ( <NUM_LIT:2> ) , jList . pop ( <NUM_LIT:2> ) ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> del pList [ <NUM_LIT:0> ] <EOL> del jList [ <NUM_LIT:0> ] <EOL> del pList [ - <NUM_LIT:1> ] <EOL> del jList [ - <NUM_LIT:1> ] <EOL> del pList [ <NUM_LIT:1> ] <EOL> del jList [ <NUM_LIT:1> ] <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> pList . append ( "<STR_LIT>" ) <EOL> jList . append ( "<STR_LIT>" ) <EOL> pList . insert ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> jList . insert ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> pList . remove ( "<STR_LIT>" ) <EOL> jList . remove ( "<STR_LIT>" ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> try : <EOL> jList [ <NUM_LIT:15> ] <EOL> self . fail ( "<STR_LIT>" ) <EOL> except IndexError : <EOL> self . assertTrue ( True ) <EOL> def testRemove ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> pList = get_list ( <NUM_LIT:3> ) <EOL> jList = ex . getList ( <NUM_LIT:3> ) <EOL> pList . append ( <NUM_LIT:10> ) <EOL> jList . append ( <NUM_LIT:10> ) <EOL> pList . remove ( <NUM_LIT:10> ) <EOL> jList . remove ( <NUM_LIT:10> ) <EOL> self . assertEqual ( len ( pList ) , len ( jList ) ) <EOL> self . assertEqual ( str ( pList ) , str ( jList ) ) <EOL> def testBinaryOp ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> pList = get_list ( <NUM_LIT:3> ) <EOL> jList = ex . getList ( <NUM_LIT:3> ) <EOL> jList2 = ex . getList ( <NUM_LIT:4> ) <EOL> self . assertTrue ( jList == jList ) <EOL> self . assertTrue ( jList != jList2 ) <EOL> self . assertTrue ( jList != pList ) <EOL> def testException ( self ) : <EOL> ex = self . gateway . getNewExample ( ) <EOL> jList = ex . getList ( <NUM_LIT:1> ) <EOL> try : <EOL> jList . get ( <NUM_LIT:5> ) <EOL> except Py4JJavaError : <EOL> self . assertTrue ( True ) <EOL> except Py4JError : <EOL> self . fail ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
