<s> import ddt <EOL> import mock <EOL> from rally . common . plugin import plugin <EOL> from rally . task import sla <EOL> from tests . unit import test <EOL> @ plugin . configure ( name = "<STR_LIT>" ) <EOL> class TestCriterion ( sla . SLA ) : <EOL> CONFIG_SCHEMA = { "<STR_LIT:type>" : "<STR_LIT>" } <EOL> def add_iteration ( self , iteration ) : <EOL> self . success = self . criterion_value == iteration <EOL> return self . success <EOL> def merge ( self , other ) : <EOL> raise NotImplementedError ( ) <EOL> def details ( self ) : <EOL> return "<STR_LIT>" <EOL> @ ddt . ddt <EOL> class SLACheckerTestCase ( test . TestCase ) : <EOL> def test_add_iteration_and_results ( self ) : <EOL> sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT> } } ) <EOL> iteration = { "<STR_LIT:key>" : { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:0> } , "<STR_LIT:data>" : <NUM_LIT> } <EOL> self . assertTrue ( sla_checker . add_iteration ( iteration [ "<STR_LIT:data>" ] ) ) <EOL> expected_result = [ { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:success>" : True } ] <EOL> self . assertEqual ( expected_result , sla_checker . results ( ) ) <EOL> iteration [ "<STR_LIT:data>" ] = <NUM_LIT> <EOL> self . assertFalse ( sla_checker . add_iteration ( iteration [ "<STR_LIT:data>" ] ) ) <EOL> expected_result = [ { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:success>" : False } ] <EOL> self . assertEqual ( expected_result , sla_checker . results ( ) ) <EOL> def test_set_unexpected_failure ( self ) : <EOL> exc = "<STR_LIT>" <EOL> sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> self . assertEqual ( [ ] , sla_checker . results ( ) ) <EOL> sla_checker . set_unexpected_failure ( exc ) <EOL> self . assertEqual ( [ { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:success>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" % exc } ] , <EOL> sla_checker . results ( ) ) <EOL> def test_set_aborted_on_sla ( self ) : <EOL> sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> self . assertEqual ( [ ] , sla_checker . results ( ) ) <EOL> sla_checker . set_aborted_on_sla ( ) <EOL> self . assertEqual ( <EOL> [ { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:success>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" } ] , <EOL> sla_checker . results ( ) ) <EOL> def test_set_aborted_manually ( self ) : <EOL> sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> self . assertEqual ( [ ] , sla_checker . results ( ) ) <EOL> sla_checker . set_aborted_manually ( ) <EOL> self . assertEqual ( <EOL> [ { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:success>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" } ] , <EOL> sla_checker . results ( ) ) <EOL> def test__format_result ( self ) : <EOL> name = "<STR_LIT>" <EOL> success = True <EOL> detail = "<STR_LIT>" <EOL> self . assertEqual ( { "<STR_LIT>" : name , <EOL> "<STR_LIT:success>" : success , <EOL> "<STR_LIT>" : detail } , <EOL> sla . _format_result ( name , success , detail ) ) <EOL> def test__validate_config_positive ( self ) : <EOL> sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> another_sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> sla_checker . _validate_config ( another_sla_checker ) <EOL> def test__validate_config_negative ( self ) : <EOL> sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> another_sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { "<STR_LIT>" : <NUM_LIT> } } ) <EOL> self . assertRaises ( TypeError , sla_checker . _validate_config , <EOL> another_sla_checker ) <EOL> def test__validate_sla_types ( self ) : <EOL> sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> mock_sla1 = mock . MagicMock ( ) <EOL> mock_sla2 = mock . MagicMock ( ) <EOL> sla_checker . sla_criteria = [ mock_sla1 , mock_sla2 ] <EOL> another_sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> mock_sla3 = mock . MagicMock ( ) <EOL> mock_sla4 = mock . MagicMock ( ) <EOL> another_sla_checker . sla_criteria = [ mock_sla3 , mock_sla4 ] <EOL> sla_checker . _validate_sla_types ( another_sla_checker ) <EOL> mock_sla1 . assert_has_calls ( [ <EOL> mock . call . validate_type ( mock_sla3 ) <EOL> ] ) <EOL> mock_sla1 . validate_type . assert_called_once_with ( mock_sla3 ) <EOL> mock_sla2 . validate_type . assert_called_once_with ( mock_sla4 ) <EOL> @ ddt . data ( { "<STR_LIT>" : True , "<STR_LIT>" : True , <EOL> "<STR_LIT:result>" : True } , <EOL> { "<STR_LIT>" : True , "<STR_LIT>" : False , <EOL> "<STR_LIT:result>" : False } , <EOL> { "<STR_LIT>" : False , "<STR_LIT>" : False , <EOL> "<STR_LIT:result>" : False } ) <EOL> @ ddt . unpack <EOL> def test_merge ( self , merge_result1 , merge_result2 , result ) : <EOL> sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> mock_sla1 = mock . MagicMock ( ) <EOL> mock_sla2 = mock . MagicMock ( ) <EOL> sla_checker . sla_criteria = [ mock_sla1 , mock_sla2 ] <EOL> mock_sla1 . merge . return_value = merge_result1 <EOL> mock_sla2 . merge . return_value = merge_result2 <EOL> another_sla_checker = sla . SLAChecker ( { "<STR_LIT>" : { } } ) <EOL> mock_sla3 = mock . MagicMock ( ) <EOL> mock_sla4 = mock . MagicMock ( ) <EOL> another_sla_checker . sla_criteria = [ mock_sla3 , mock_sla4 ] <EOL> sla_checker . _validate_config = mock . MagicMock ( ) <EOL> sla_checker . _validate_sla_types = mock . MagicMock ( ) <EOL> self . assertEqual ( result , sla_checker . merge ( another_sla_checker ) ) <EOL> mock_sla1 . merge . assert_called_once_with ( mock_sla3 ) <EOL> mock_sla2 . merge . assert_called_once_with ( mock_sla4 ) <EOL> class SLATestCase ( test . TestCase ) : <EOL> def test_validate_type_positive ( self ) : <EOL> sla1 = TestCriterion ( <NUM_LIT:0> ) <EOL> sla2 = TestCriterion ( <NUM_LIT:0> ) <EOL> sla1 . validate_type ( sla2 ) <EOL> def test_validate_type_negative ( self ) : <EOL> sla1 = TestCriterion ( <NUM_LIT:0> ) <EOL> class AnotherTestCriterion ( TestCriterion ) : <EOL> pass <EOL> sla2 = AnotherTestCriterion ( <NUM_LIT:0> ) <EOL> self . assertRaises ( TypeError , sla1 . validate_type , sla2 ) </s>
