<s> import unittest <EOL> from troposphere import Parameter , Ref <EOL> from troposphere . validators import boolean , integer , integer_range <EOL> from troposphere . validators import positive_integer , network_port <EOL> from troposphere . validators import s3_bucket_name , encoding , status <EOL> from troposphere . validators import iam_path , iam_names , iam_role_name <EOL> from troposphere . validators import iam_group_name <EOL> class TestValidators ( unittest . TestCase ) : <EOL> def test_boolean ( self ) : <EOL> for x in [ True , "<STR_LIT:True>" , "<STR_LIT:true>" , <NUM_LIT:1> , "<STR_LIT:1>" ] : <EOL> self . assertEqual ( boolean ( x ) , "<STR_LIT:true>" , repr ( x ) ) <EOL> for x in [ False , "<STR_LIT:False>" , "<STR_LIT:false>" , <NUM_LIT:0> , "<STR_LIT:0>" ] : <EOL> self . assertEqual ( boolean ( x ) , "<STR_LIT:false>" , repr ( x ) ) <EOL> for x in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:abc>" ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> boolean ( x ) <EOL> def test_integer ( self ) : <EOL> self . assertEqual ( integer ( - <NUM_LIT:1> ) , - <NUM_LIT:1> ) <EOL> self . assertEqual ( integer ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> self . assertEqual ( integer ( <NUM_LIT:0> ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( integer ( "<STR_LIT:0>" ) , "<STR_LIT:0>" ) <EOL> self . assertEqual ( integer ( <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( integer ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> self . assertEqual ( integer ( <NUM_LIT:1.0> ) , <NUM_LIT:1.0> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> integer ( "<STR_LIT:string>" ) <EOL> with self . assertRaises ( ValueError ) : <EOL> integer ( object ) <EOL> with self . assertRaises ( ValueError ) : <EOL> integer ( None ) <EOL> def test_positive_integer ( self ) : <EOL> for x in [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ] : <EOL> positive_integer ( x ) <EOL> for x in [ - <NUM_LIT:1> , - <NUM_LIT:10> ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> positive_integer ( x ) <EOL> def test_integer_range ( self ) : <EOL> between_ten_and_twenty = integer_range ( <NUM_LIT:10> , <NUM_LIT:20> ) <EOL> self . assertEqual ( between_ten_and_twenty ( <NUM_LIT:10> ) , <NUM_LIT:10> ) <EOL> self . assertEqual ( between_ten_and_twenty ( <NUM_LIT:15> ) , <NUM_LIT:15> ) <EOL> self . assertEqual ( between_ten_and_twenty ( <NUM_LIT:20> ) , <NUM_LIT:20> ) <EOL> for i in ( - <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> between_ten_and_twenty ( i ) <EOL> def test_network_port ( self ) : <EOL> for x in [ - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ] : <EOL> network_port ( x ) <EOL> for x in [ - <NUM_LIT:2> , - <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> network_port ( x ) <EOL> def test_network_port_ref ( self ) : <EOL> p = Parameter ( '<STR_LIT>' ) <EOL> network_port ( Ref ( p ) ) <EOL> def test_s3_bucket_name ( self ) : <EOL> for b in [ '<STR_LIT:a>' * <NUM_LIT:3> , '<STR_LIT:a>' * <NUM_LIT> , '<STR_LIT>' ] : <EOL> s3_bucket_name ( b ) <EOL> for b in [ '<STR_LIT:a>' * <NUM_LIT:2> , '<STR_LIT:a>' * <NUM_LIT:64> , '<STR_LIT>' ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> s3_bucket_name ( b ) <EOL> def test_encoding ( self ) : <EOL> for e in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> encoding ( e ) <EOL> for e in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> encoding ( e ) <EOL> def test_status ( self ) : <EOL> for s in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> status ( s ) <EOL> for s in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> status ( s ) <EOL> def test_iam_names ( self ) : <EOL> for s in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> iam_names ( s ) <EOL> for s in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> iam_names ( s ) <EOL> def test_iam_path ( self ) : <EOL> for s in [ '<STR_LIT>' % ( '<STR_LIT:a>' * <NUM_LIT:30> ) , '<STR_LIT>' % ( '<STR_LIT:a>' * <NUM_LIT> ) ] : <EOL> iam_path ( s ) <EOL> for s in [ '<STR_LIT>' % ( '<STR_LIT:a>' * <NUM_LIT> ) , '<STR_LIT>' % ( '<STR_LIT:a>' * <NUM_LIT> ) ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> iam_path ( s ) <EOL> def test_iam_role_name ( self ) : <EOL> for s in [ '<STR_LIT:a>' * <NUM_LIT:30> , '<STR_LIT:a>' * <NUM_LIT:64> ] : <EOL> iam_role_name ( s ) <EOL> for s in [ '<STR_LIT:a>' * <NUM_LIT> , '<STR_LIT:a>' * <NUM_LIT> ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> iam_role_name ( s ) <EOL> def test_iam_group_name ( self ) : <EOL> for s in [ '<STR_LIT:a>' * <NUM_LIT:64> , '<STR_LIT:a>' * <NUM_LIT> ] : <EOL> iam_group_name ( s ) <EOL> for s in [ '<STR_LIT:a>' * <NUM_LIT> , '<STR_LIT:a>' * <NUM_LIT> ] : <EOL> with self . assertRaises ( ValueError ) : <EOL> iam_group_name ( s ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
