<s> """<STR_LIT>""" <EOL> import unittest <EOL> from openmdao . main . api import Component , Assembly <EOL> from openmdao . main . datatypes . api import Float , List , Array <EOL> from numpy import array , zeros <EOL> class MyDefComp ( Component ) : <EOL> f_in = Float ( <NUM_LIT> , iotype = '<STR_LIT>' ) <EOL> f_out = Float ( iotype = '<STR_LIT>' ) <EOL> arr_in = Array ( [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ] , iotype = '<STR_LIT>' ) <EOL> list_in = List ( value = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] , iotype = '<STR_LIT>' ) <EOL> def execute ( self ) : <EOL> self . f_out = self . f_in + <NUM_LIT:1.> <EOL> class MyNoDefComp ( Component ) : <EOL> f_in = Float ( iotype = '<STR_LIT>' ) <EOL> f_out = Float ( iotype = '<STR_LIT>' ) <EOL> arr_in = Array ( iotype = '<STR_LIT>' ) <EOL> list_in = List ( iotype = '<STR_LIT>' ) <EOL> def execute ( self ) : <EOL> self . f_out = self . f_in + <NUM_LIT:1.> <EOL> class SetDefaultsTestCase ( unittest . TestCase ) : <EOL> def test_set_to_unset_default ( self ) : <EOL> comp = MyNoDefComp ( ) <EOL> self . assertEqual ( <NUM_LIT:0.> , comp . f_in ) <EOL> comp . f_in = <NUM_LIT> <EOL> comp . arr_in = array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> comp . list_in = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> comp . run ( ) <EOL> comp . revert_to_defaults ( ) <EOL> self . assertEqual ( <NUM_LIT:0.> , comp . f_in ) <EOL> self . assertTrue ( all ( zeros ( <NUM_LIT:0> , '<STR_LIT:d>' ) == comp . arr_in ) ) <EOL> self . assertEqual ( [ ] , comp . list_in ) <EOL> def test_set_to_default ( self ) : <EOL> comp = MyDefComp ( ) <EOL> self . assertEqual ( <NUM_LIT> , comp . f_in ) <EOL> comp . f_in = <NUM_LIT> <EOL> comp . arr_in = array ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . assertFalse ( array ( [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ] ) == comp . arr_in ) <EOL> comp . run ( ) <EOL> comp . revert_to_defaults ( ) <EOL> self . assertEqual ( <NUM_LIT> , comp . f_in ) <EOL> self . assertTrue ( all ( array ( [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ] ) == comp . arr_in ) ) <EOL> def test_set_recursive ( self ) : <EOL> asm = Assembly ( ) <EOL> asm . add ( '<STR_LIT>' , MyDefComp ( ) ) <EOL> asm . add ( '<STR_LIT>' , MyNoDefComp ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0.> , asm . nodefcomp . f_in ) <EOL> self . assertEqual ( <NUM_LIT> , asm . defcomp . f_in ) <EOL> asm . nodefcomp . f_in = <NUM_LIT> <EOL> asm . defcomp . f_in = <NUM_LIT> <EOL> asm . revert_to_defaults ( ) <EOL> self . assertEqual ( <NUM_LIT:0.> , asm . nodefcomp . f_in ) <EOL> self . assertEqual ( <NUM_LIT> , asm . defcomp . f_in ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
