<s> from __future__ import with_statement <EOL> import os <EOL> import unittest <EOL> from test import test_support <EOL> from array import array <EOL> class ArrayJyTestCase ( unittest . TestCase ) : <EOL> def test_jarray ( self ) : <EOL> import jarray <EOL> from java . lang import String <EOL> jarray . array ( range ( <NUM_LIT:5> ) , '<STR_LIT:i>' ) <EOL> jarray . array ( [ String ( "<STR_LIT:a>" ) , String ( "<STR_LIT:b>" ) , String ( "<STR_LIT:c>" ) ] , String ) <EOL> jarray . zeros ( <NUM_LIT:5> , '<STR_LIT:i>' ) <EOL> jarray . zeros ( <NUM_LIT:5> , String ) <EOL> def test_java_object_arrays ( self ) : <EOL> from array import zeros <EOL> from java . lang import String <EOL> from java . lang . reflect import Array <EOL> from java . util import Arrays <EOL> jStringArr = array ( String , [ String ( "<STR_LIT:a>" ) , String ( "<STR_LIT:b>" ) , String ( "<STR_LIT:c>" ) ] ) <EOL> self . assert_ ( <EOL> Arrays . equals ( jStringArr . typecode , '<STR_LIT>' ) , <EOL> "<STR_LIT>" % <EOL> ( jStringArr . typecode , str ( String ) ) ) <EOL> self . assertEqual ( zeros ( String , <NUM_LIT:5> ) , Array . newInstance ( String , <NUM_LIT:5> ) ) <EOL> import java . lang . String <EOL> self . assertEqual ( jStringArr , eval ( str ( jStringArr ) ) ) <EOL> def test_java_compat ( self ) : <EOL> from array import zeros <EOL> from java . awt import Color <EOL> hsb = Color . RGBtoHSB ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:255> , None ) <EOL> self . assertEqual ( hsb , array ( '<STR_LIT:f>' , [ <NUM_LIT:0.5> , <NUM_LIT:1> , <NUM_LIT:1> ] ) , <EOL> "<STR_LIT>" ) <EOL> rgb = apply ( Color . HSBtoRGB , tuple ( hsb ) ) <EOL> self . assertEqual ( rgb , - <NUM_LIT> , <EOL> "<STR_LIT>" ) <EOL> hsb1 = zeros ( '<STR_LIT:f>' , <NUM_LIT:3> ) <EOL> Color . RGBtoHSB ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:255> , hsb1 ) <EOL> self . assertEqual ( hsb , hsb1 , "<STR_LIT>" ) <EOL> def test_java_roundtrip ( self ) : <EOL> from java . lang import Object <EOL> x = array ( Object , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> x . append ( <NUM_LIT:3> ) <EOL> y = array ( Object , [ x ] ) <EOL> self . assertEqual ( x , y [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> class ToFromfileTestCase ( unittest . TestCase ) : <EOL> def tearDown ( self ) : <EOL> if os . path . exists ( test_support . TESTFN ) : <EOL> os . remove ( test_support . TESTFN ) <EOL> def test_tofromfile ( self ) : <EOL> x = array ( '<STR_LIT:i>' , range ( <NUM_LIT:5> ) ) <EOL> with open ( test_support . TESTFN , '<STR_LIT:wb>' ) as f : <EOL> x . tofile ( f ) <EOL> x = array ( '<STR_LIT:i>' , [ ] ) <EOL> with open ( test_support . TESTFN , '<STR_LIT>' ) as f : <EOL> x . fromfile ( f , <NUM_LIT:5> ) <EOL> x *= <NUM_LIT:2> <EOL> x . tofile ( f ) <EOL> with open ( test_support . TESTFN , '<STR_LIT:rb>' ) as f : <EOL> x . fromfile ( f , <NUM_LIT:10> ) <EOL> self . assertEqual ( x , array ( '<STR_LIT:i>' , range ( <NUM_LIT:5> ) * <NUM_LIT:4> ) ) <EOL> class ArrayOpsTestCase ( unittest . TestCase ) : <EOL> def test_ops ( self ) : <EOL> class Foo ( object ) : <EOL> def __radd__ ( self , that ) : <EOL> return '<STR_LIT>' <EOL> ar = array ( '<STR_LIT:i>' , range ( <NUM_LIT:5> ) ) <EOL> self . assertEqual ( '<STR_LIT>' , ar + Foo ( ) ) <EOL> ar += Foo ( ) <EOL> self . assertEqual ( '<STR_LIT>' , ar ) <EOL> def test_main ( ) : <EOL> tests = [ ToFromfileTestCase , ArrayOpsTestCase ] <EOL> if test_support . is_jython : <EOL> tests . extend ( [ ArrayJyTestCase ] ) <EOL> test_support . run_unittest ( * tests ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
