<s> from test import test_support <EOL> import unittest <EOL> from java . io import ByteArrayInputStream , ByteArrayOutputStream , ObjectInputStream , ObjectOutputStream <EOL> from org . python . util import PythonObjectInputStream <EOL> def serialize ( o , special = False ) : <EOL> b = ByteArrayOutputStream ( ) <EOL> objs = ObjectOutputStream ( b ) <EOL> objs . writeObject ( o ) <EOL> if not special : <EOL> OIS = ObjectInputStream <EOL> else : <EOL> OIS = PythonObjectInputStream <EOL> objs = OIS ( ByteArrayInputStream ( b . toByteArray ( ) ) ) <EOL> return objs . readObject ( ) <EOL> from jser2_classes import A , AJ , N , NL , NT <EOL> class TestJavaSerialisation ( unittest . TestCase ) : <EOL> def serialize_and_check ( self , obj , special = False ) : <EOL> obj1 = serialize ( obj , special ) <EOL> self . assertEqual ( obj , obj1 ) <EOL> def test_list ( self ) : <EOL> self . serialize_and_check ( [ <NUM_LIT:1> , "<STR_LIT:a>" , <NUM_LIT> ] ) <EOL> def test_dict ( self ) : <EOL> self . serialize_and_check ( { '<STR_LIT:a>' : <NUM_LIT> } ) <EOL> def test_tuple ( self ) : <EOL> self . serialize_and_check ( ( <NUM_LIT:1> , '<STR_LIT:a>' ) ) <EOL> def test_oldstyle ( self ) : <EOL> self . serialize_and_check ( A ( '<STR_LIT:x>' ) ) <EOL> def test_jsubcl ( self ) : <EOL> self . serialize_and_check ( AJ ( '<STR_LIT:x>' ) , special = True ) <EOL> def test_singletons ( self ) : <EOL> for v in ( None , Ellipsis ) : <EOL> v1 = serialize ( v ) <EOL> self . assert_ ( v is v1 ) <EOL> v1 = serialize ( ( v , ) ) [ <NUM_LIT:0> ] <EOL> self . assert_ ( v is v1 ) <EOL> def test_NotImplemented ( self ) : <EOL> v1 = serialize ( ( NotImplemented , ) ) [ <NUM_LIT:0> ] <EOL> self . assert_ ( v1 is NotImplemented ) <EOL> def test_type ( self ) : <EOL> list1 = serialize ( list ) <EOL> self . assert_ ( list1 is list ) <EOL> list1 = serialize ( ( list , ) ) [ <NUM_LIT:0> ] <EOL> self . assert_ ( list1 is list ) <EOL> def test_user_type ( self ) : <EOL> N1 = serialize ( N ) <EOL> self . assert_ ( N1 is N ) <EOL> N1 = serialize ( ( N , ) ) [ <NUM_LIT:0> ] <EOL> self . assert_ ( N1 is N ) <EOL> def test_newstyle ( self ) : <EOL> self . serialize_and_check ( N ( '<STR_LIT:x>' ) ) <EOL> def test_newstyle_list ( self ) : <EOL> self . serialize_and_check ( NL ( '<STR_LIT:x>' , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> def test_newstyle_tuple ( self ) : <EOL> self . serialize_and_check ( NT ( '<STR_LIT:x>' , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( TestJavaSerialisation ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
