<s> """<STR_LIT>""" <EOL> from random import randint <EOL> from os import path <EOL> import bot . lib . lib as lib <EOL> import bot . hardware . servo as s_mod <EOL> import tests . test_bot as test_bot <EOL> class TestPosition ( test_bot . TestBot ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestPosition , self ) . setUp ( ) <EOL> config = path . dirname ( path . realpath ( __file__ ) ) + "<STR_LIT>" <EOL> self . config = lib . get_config ( config ) <EOL> self . pwm_num = self . config [ '<STR_LIT>' ] <EOL> self . setup_pwm ( self . pwm_num , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . servo = s_mod . Servo ( self . pwm_num ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( TestPosition , self ) . tearDown ( ) <EOL> def test_0 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . servo . position = <NUM_LIT:0> <EOL> assert self . servo . position == <NUM_LIT:0> , self . servo . position <EOL> def test_180 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . servo . position = <NUM_LIT> <EOL> assert self . servo . position == <NUM_LIT> , self . servo . position <EOL> def test_middle ( self ) : <EOL> """<STR_LIT>""" <EOL> self . servo . position = <NUM_LIT> <EOL> assert self . servo . position == <NUM_LIT> , self . servo . position <EOL> def test_series ( self ) : <EOL> """<STR_LIT>""" <EOL> for position in range ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) : <EOL> self . servo . position = position <EOL> assert self . servo . position == position , self . servo . position <EOL> def test_manually_confirm ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> test_pos = randint ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> self . servo . position = test_pos <EOL> cur_pwm = self . get_pwm ( self . pwm_num ) <EOL> duty = int ( cur_pwm [ "<STR_LIT>" ] ) <EOL> read_pos = int ( round ( ( ( duty - <NUM_LIT> ) / <NUM_LIT> ) * <NUM_LIT> ) ) <EOL> assert read_pos == test_pos , "<STR_LIT>" . format ( read_pos , test_pos ) <EOL> def test_over_max ( self ) : <EOL> """<STR_LIT>""" <EOL> self . servo . position = <NUM_LIT> <EOL> assert self . servo . position == <NUM_LIT> , "<STR_LIT>" . format ( self . servo . position ) <EOL> def test_under_min ( self ) : <EOL> """<STR_LIT>""" <EOL> self . servo . position = - <NUM_LIT:1> <EOL> assert self . servo . position == <NUM_LIT:0> , "<STR_LIT>" . format ( self . servo . position ) </s>
