<s> """<STR_LIT>""" <EOL> import unittest <EOL> import param <EOL> import numbergen <EOL> import random <EOL> from nose . tools import istest , nottest <EOL> from param . parameterized import ParamOverrides <EOL> @ nottest <EOL> class _SomeRandomNumbers ( object ) : <EOL> def __call__ ( self ) : <EOL> return random . random ( ) <EOL> @ nottest <EOL> class TestPO ( param . Parameterized ) : <EOL> inst = param . Parameter ( default = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , instantiate = True ) <EOL> notinst = param . Parameter ( default = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , instantiate = False ) <EOL> const = param . Parameter ( default = <NUM_LIT:1> , constant = True ) <EOL> ro = param . Parameter ( default = "<STR_LIT>" , readonly = True ) <EOL> ro2 = param . Parameter ( default = object ( ) , readonly = True , instantiate = True ) <EOL> dyn = param . Dynamic ( default = <NUM_LIT:1> ) <EOL> @ nottest <EOL> class AnotherTestPO ( param . Parameterized ) : <EOL> instPO = param . Parameter ( default = TestPO ( ) , instantiate = True ) <EOL> notinstPO = param . Parameter ( default = TestPO ( ) , instantiate = False ) <EOL> @ nottest <EOL> class TestAbstractPO ( param . Parameterized ) : <EOL> __abstract = True <EOL> @ nottest <EOL> class TestParamInstantiation ( AnotherTestPO ) : <EOL> instPO = param . Parameter ( default = AnotherTestPO ( ) , instantiate = False ) <EOL> @ istest <EOL> class TestParameterized ( unittest . TestCase ) : <EOL> def test_constant_parameter ( self ) : <EOL> """<STR_LIT>""" <EOL> testpo = TestPO ( const = <NUM_LIT> ) <EOL> self . assertEqual ( testpo . const , <NUM_LIT> ) <EOL> self . assertRaises ( TypeError , setattr , testpo , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> TestPO . const = <NUM_LIT:9> <EOL> testpo = TestPO ( ) <EOL> self . assertEqual ( testpo . const , <NUM_LIT:9> ) <EOL> def test_readonly_parameter ( self ) : <EOL> """<STR_LIT>""" <EOL> testpo = TestPO ( ) <EOL> self . assertEqual ( testpo . ro , "<STR_LIT>" ) <EOL> try : <EOL> t = TestPO ( ro = <NUM_LIT:20> ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> t = TestPO ( ) <EOL> self . assertRaises ( TypeError , setattr , t , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> self . assertRaises ( TypeError , setattr , TestPO , '<STR_LIT>' , <NUM_LIT:5> ) <EOL> self . assertEqual ( testpo . params ( ) [ '<STR_LIT>' ] . constant , True ) <EOL> self . assertEqual ( testpo . params ( ) [ '<STR_LIT>' ] . instantiate , False ) <EOL> def test_basic_instantiation ( self ) : <EOL> """<STR_LIT>""" <EOL> testpo = TestPO ( ) <EOL> self . assertEqual ( testpo . inst , TestPO . inst ) <EOL> self . assertEqual ( testpo . notinst , TestPO . notinst ) <EOL> TestPO . inst [ <NUM_LIT:1> ] = <NUM_LIT:7> <EOL> TestPO . notinst [ <NUM_LIT:1> ] = <NUM_LIT:7> <EOL> self . assertEqual ( testpo . notinst , [ <NUM_LIT:1> , <NUM_LIT:7> , <NUM_LIT:3> ] ) <EOL> self . assertEqual ( testpo . inst , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> def test_more_instantiation ( self ) : <EOL> """<STR_LIT>""" <EOL> anothertestpo = AnotherTestPO ( ) <EOL> TestPO . notinst [ <NUM_LIT:1> ] = <NUM_LIT:7> <EOL> self . assertEqual ( anothertestpo . instPO . notinst , [ <NUM_LIT:1> , <NUM_LIT:7> , <NUM_LIT:3> ] ) <EOL> def test_instantiation_inheritance ( self ) : <EOL> """<STR_LIT>""" <EOL> t = TestParamInstantiation ( ) <EOL> assert t . params ( '<STR_LIT>' ) . instantiate is True <EOL> assert isinstance ( t . instPO , AnotherTestPO ) <EOL> def test_abstract_class ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( TestAbstractPO . abstract , True ) <EOL> self . assertEqual ( TestPO . abstract , False ) <EOL> def test_params ( self ) : <EOL> """<STR_LIT>""" <EOL> assert '<STR_LIT:name>' in param . Parameterized . params ( ) <EOL> assert len ( param . Parameterized . params ( ) ) in [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert '<STR_LIT>' in TestPO . params ( ) <EOL> assert '<STR_LIT>' in TestPO . params ( ) <EOL> assert param . Parameterized . params ( ) is param . Parameterized ( ) . params ( ) , "<STR_LIT>" <EOL> def test_state_saving ( self ) : <EOL> t = TestPO ( dyn = _SomeRandomNumbers ( ) ) <EOL> g = t . get_value_generator ( '<STR_LIT>' ) <EOL> g . _Dynamic_time_fn = None <EOL> assert t . dyn != t . dyn <EOL> orig = t . dyn <EOL> t . state_push ( ) <EOL> t . dyn <EOL> assert t . inspect_value ( '<STR_LIT>' ) != orig <EOL> t . state_pop ( ) <EOL> assert t . inspect_value ( '<STR_LIT>' ) == orig <EOL> from param import parameterized <EOL> @ nottest <EOL> class some_fn ( param . ParameterizedFunction ) : <EOL> num_phase = param . Number ( <NUM_LIT> ) <EOL> frequencies = param . List ( [ <NUM_LIT> ] ) <EOL> scale = param . Number ( <NUM_LIT> ) <EOL> def __call__ ( self , ** params_to_override ) : <EOL> params = parameterized . ParamOverrides ( self , params_to_override ) <EOL> num_phase = params [ '<STR_LIT>' ] <EOL> frequencies = params [ '<STR_LIT>' ] <EOL> scale = params [ '<STR_LIT>' ] <EOL> return scale , num_phase , frequencies <EOL> instance = some_fn . instance ( ) <EOL> @ istest <EOL> class TestParameterizedFunction ( unittest . TestCase ) : <EOL> def _basic_tests ( self , fn ) : <EOL> self . assertEqual ( fn ( ) , ( <NUM_LIT> , <NUM_LIT> , [ <NUM_LIT> ] ) ) <EOL> self . assertEqual ( fn ( frequencies = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , ( <NUM_LIT> , <NUM_LIT> , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertEqual ( fn ( ) , ( <NUM_LIT> , <NUM_LIT> , [ <NUM_LIT> ] ) ) <EOL> fn . frequencies = [ <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:30> ] <EOL> self . assertEqual ( fn ( frequencies = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , ( <NUM_LIT> , <NUM_LIT> , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertEqual ( fn ( ) , ( <NUM_LIT> , <NUM_LIT> , [ <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:30> ] ) ) <EOL> def test_parameterized_function ( self ) : <EOL> self . _basic_tests ( some_fn ) <EOL> def test_parameterized_function_instance ( self ) : <EOL> self . _basic_tests ( instance ) <EOL> def test_pickle_instance ( self ) : <EOL> import pickle <EOL> s = pickle . dumps ( instance ) <EOL> instance . scale = <NUM_LIT> <EOL> i = pickle . loads ( s ) <EOL> self . assertEqual ( i ( ) , ( <NUM_LIT> , <NUM_LIT> , [ <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:30> ] ) ) <EOL> @ nottest <EOL> class TestPO1 ( param . Parameterized ) : <EOL> x = param . Number ( default = numbergen . UniformRandom ( lbound = - <NUM_LIT:1> , ubound = <NUM_LIT:1> , seed = <NUM_LIT:1> ) , bounds = ( - <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> y = param . Number ( default = <NUM_LIT:1> , bounds = ( - <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> @ istest <EOL> class TestNumberParameter ( unittest . TestCase ) : <EOL> def test_outside_bounds ( self ) : <EOL> t1 = TestPO1 ( ) <EOL> try : <EOL> t1 . y = <NUM_LIT:10> <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> assert False , "<STR_LIT>" <EOL> def test_outside_bounds_numbergen ( self ) : <EOL> t1 = TestPO1 ( ) <EOL> t1 . x = numbergen . UniformRandom ( lbound = <NUM_LIT:2> , ubound = <NUM_LIT:3> ) <EOL> try : <EOL> t1 . x <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> assert False , "<STR_LIT>" <EOL> @ istest <EOL> class TestStringParameter ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestStringParameter , self ) . setUp ( ) <EOL> class TestString ( param . Parameterized ) : <EOL> a = param . String ( ) <EOL> b = param . String ( default = '<STR_LIT>' , allow_None = True ) <EOL> c = param . String ( default = None ) <EOL> self . _TestString = TestString <EOL> def test_handling_of_None ( self ) : <EOL> t = self . _TestString ( ) <EOL> try : <EOL> t . a = None <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> raise AssertionError <EOL> t . b = None <EOL> assert t . c is None <EOL> @ istest <EOL> class TestParamOverrides ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestParamOverrides , self ) . setUp ( ) <EOL> self . po = param . Parameterized ( name = '<STR_LIT:A>' , print_level = <NUM_LIT:0> ) <EOL> def test_init_name ( self ) : <EOL> self . assertEqual ( self . po . name , '<STR_LIT:A>' ) <EOL> def test_simple_override ( self ) : <EOL> overrides = ParamOverrides ( self . po , { '<STR_LIT:name>' : '<STR_LIT:B>' } ) <EOL> self . assertEqual ( overrides [ '<STR_LIT:name>' ] , '<STR_LIT:B>' ) <EOL> self . assertEqual ( overrides [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> def test_missing_key ( self ) : <EOL> overrides = ParamOverrides ( self . po , { '<STR_LIT:name>' : '<STR_LIT:B>' } ) <EOL> try : <EOL> overrides [ '<STR_LIT>' ] <EOL> except AttributeError : <EOL> pass <EOL> except : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> else : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import nose <EOL> nose . runmodule ( ) </s>
