<s> import unittest <EOL> import java <EOL> import org . python . core <EOL> class PyReflFuncEnvl : <EOL> def __init__ ( self , name , meths ) : <EOL> self . reflfunc = org . python . core . PyReflectedFunction ( name ) <EOL> for meth in meths : <EOL> self . reflfunc . addMethod ( meth ) <EOL> def __call__ ( self , inst , args ) : <EOL> return self . reflfunc ( inst , * args ) <EOL> def extract_ov_meths ( jcl , envl_class ) : <EOL> meths = java . lang . Class . getDeclaredMethods ( jcl ) <EOL> names = [ m . name for m in meths ] <EOL> meth_dict = { } <EOL> for name in names : <EOL> if name . startswith ( '<STR_LIT>' ) and not meth_dict . has_key ( name ) : <EOL> meth_dict [ name ] = envl_class ( name , [ m for m in meths if m . name == name ] ) <EOL> return meth_dict <EOL> from javatests import JOverload <EOL> jo = JOverload ( ) <EOL> to_test = [ extract_ov_meths ( JOverload , PyReflFuncEnvl ) ] <EOL> class OverloadedDispatchTests ( unittest . TestCase ) : <EOL> def check ( self , lbl , rng , args , expected ) : <EOL> expected = expected . split ( ) <EOL> for meth_dict in to_test : <EOL> for i , expect in zip ( rng , expected ) : <EOL> self . assertEqual ( meth_dict [ '<STR_LIT>' % ( lbl , i ) ] ( jo , args ) , expect ) <EOL> def test_posprec ( self ) : <EOL> self . check ( '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> "<STR_LIT>" ) <EOL> def test_scal_int_zero ( self ) : <EOL> self . check ( '<STR_LIT>' , xrange ( <NUM_LIT:1> , <NUM_LIT:15> ) , [ <NUM_LIT:0> ] , <EOL> """<STR_LIT>""" ) <EOL> def test_scal_string ( self ) : <EOL> self . check ( '<STR_LIT>' , xrange ( <NUM_LIT:1> , <NUM_LIT:15> ) , [ '<STR_LIT:str>' ] , <EOL> """<STR_LIT>""" ) <EOL> def test_scal_char ( self ) : <EOL> self . check ( '<STR_LIT>' , xrange ( <NUM_LIT:1> , <NUM_LIT:15> ) , [ '<STR_LIT:c>' ] , <EOL> """<STR_LIT>""" ) <EOL> def test_scal_float_one ( self ) : <EOL> self . check ( '<STR_LIT>' , xrange ( <NUM_LIT:1> , <NUM_LIT:15> ) , [ <NUM_LIT:1.0> ] , <EOL> """<STR_LIT>""" ) <EOL> def printout ( meth_dict , lbl , rng , args ) : <EOL> for i in rng : <EOL> print meth_dict [ '<STR_LIT>' % ( lbl , i ) ] ( jo , args ) <EOL> import sys <EOL> if __name__ == '<STR_LIT:__main__>' and not sys . argv [ <NUM_LIT:1> : ] == [ '<STR_LIT>' ] : <EOL> try : <EOL> import test_support <EOL> except ImportError : <EOL> unittest . main ( ) <EOL> else : <EOL> test_support . run_unittest ( OverloadedDispatchTests ) </s>
