<s> import ddt <EOL> import jsonschema <EOL> from rally . plugins . common . sla import failure_rate <EOL> from tests . unit import test <EOL> class SLAPluginTestCase ( test . TestCase ) : <EOL> def test_validate ( self ) : <EOL> cnf = { "<STR_LIT>" : <NUM_LIT> } <EOL> failure_rate . sla . SLA . validate ( cnf ) <EOL> def test_validate_invalid_name ( self ) : <EOL> self . assertRaises ( jsonschema . ValidationError , <EOL> failure_rate . FailureRate . validate , <EOL> { "<STR_LIT>" : <NUM_LIT> } ) <EOL> def test_validate_invalid_type ( self ) : <EOL> self . assertRaises ( jsonschema . ValidationError , <EOL> failure_rate . FailureRate . validate , <EOL> { "<STR_LIT>" : <NUM_LIT> } ) <EOL> @ ddt . ddt <EOL> class FailureRateTestCase ( test . TestCase ) : <EOL> def test_config_schema ( self ) : <EOL> self . assertRaises ( jsonschema . ValidationError , <EOL> failure_rate . FailureRate . validate , <EOL> { "<STR_LIT>" : { "<STR_LIT>" : - <NUM_LIT:1> } } ) <EOL> self . assertRaises ( jsonschema . ValidationError , <EOL> failure_rate . FailureRate . validate , <EOL> { "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT> } } ) <EOL> self . assertRaises ( jsonschema . ValidationError , <EOL> failure_rate . FailureRate . validate , <EOL> { "<STR_LIT>" : { "<STR_LIT>" : - <NUM_LIT:0.1> } } ) <EOL> self . assertRaises ( jsonschema . ValidationError , <EOL> failure_rate . FailureRate . validate , <EOL> { "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT> } } ) <EOL> def test_result_min ( self ) : <EOL> sla1 = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> } ) <EOL> sla2 = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> } ) <EOL> for sla in [ sla1 , sla2 ] : <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] } ) <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ ] } ) <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] } ) <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] } ) <EOL> self . assertFalse ( sla1 . result ( ) [ "<STR_LIT:success>" ] ) <EOL> self . assertTrue ( sla2 . result ( ) [ "<STR_LIT:success>" ] ) <EOL> self . assertEqual ( "<STR_LIT>" , sla1 . status ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" , sla2 . status ( ) ) <EOL> def test_result_max ( self ) : <EOL> sla1 = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> } ) <EOL> sla2 = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> } ) <EOL> for sla in [ sla1 , sla2 ] : <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] } ) <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ ] } ) <EOL> self . assertFalse ( sla1 . result ( ) [ "<STR_LIT:success>" ] ) <EOL> self . assertTrue ( sla2 . result ( ) [ "<STR_LIT:success>" ] ) <EOL> self . assertEqual ( "<STR_LIT>" , sla1 . status ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" , sla2 . status ( ) ) <EOL> def test_result_min_max ( self ) : <EOL> sla1 = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT:50> , "<STR_LIT>" : <NUM_LIT> } ) <EOL> sla2 = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT:5> , "<STR_LIT>" : <NUM_LIT:20> } ) <EOL> sla3 = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : <NUM_LIT> } ) <EOL> for sla in [ sla1 , sla2 , sla3 ] : <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] } ) <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ ] } ) <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ ] } ) <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ ] } ) <EOL> self . assertFalse ( sla1 . result ( ) [ "<STR_LIT:success>" ] ) <EOL> self . assertFalse ( sla2 . result ( ) [ "<STR_LIT:success>" ] ) <EOL> self . assertTrue ( sla3 . result ( ) [ "<STR_LIT:success>" ] ) <EOL> self . assertEqual ( "<STR_LIT>" , sla1 . status ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" , sla2 . status ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" , sla3 . status ( ) ) <EOL> def test_result_no_iterations ( self ) : <EOL> sla = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> } ) <EOL> self . assertTrue ( sla . result ( ) [ "<STR_LIT:success>" ] ) <EOL> def test_add_iteration ( self ) : <EOL> sla = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> } ) <EOL> self . assertTrue ( sla . add_iteration ( { "<STR_LIT:error>" : [ ] } ) ) <EOL> self . assertTrue ( sla . add_iteration ( { "<STR_LIT:error>" : [ ] } ) ) <EOL> self . assertTrue ( sla . add_iteration ( { "<STR_LIT:error>" : [ ] } ) ) <EOL> self . assertTrue ( sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] } ) ) <EOL> self . assertFalse ( sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] } ) ) <EOL> @ ddt . data ( [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] ) <EOL> def test_merge ( self , errors ) : <EOL> single_sla = failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> } ) <EOL> for ee in errors : <EOL> for e in ee : <EOL> single_sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] if e else [ ] } ) <EOL> slas = [ failure_rate . FailureRate ( { "<STR_LIT>" : <NUM_LIT> } ) for _ in errors ] <EOL> for idx , sla in enumerate ( slas ) : <EOL> for e in errors [ idx ] : <EOL> sla . add_iteration ( { "<STR_LIT:error>" : [ "<STR_LIT:error>" ] if e else [ ] } ) <EOL> merged_sla = slas [ <NUM_LIT:0> ] <EOL> for sla in slas [ <NUM_LIT:1> : ] : <EOL> merged_sla . merge ( sla ) <EOL> self . assertEqual ( single_sla . success , merged_sla . success ) <EOL> self . assertEqual ( single_sla . errors , merged_sla . errors ) <EOL> self . assertEqual ( single_sla . total , merged_sla . total ) </s>
