<s> import mock <EOL> from rally . common . plugin import discover <EOL> from tests . unit import test <EOL> DISCOVER = "<STR_LIT>" <EOL> class IterSubclassesTestCase ( test . TestCase ) : <EOL> def test_itersubclasses ( self ) : <EOL> class A ( object ) : <EOL> pass <EOL> class B ( A ) : <EOL> pass <EOL> class C ( A ) : <EOL> pass <EOL> class D ( C ) : <EOL> pass <EOL> self . assertEqual ( [ B , C , D ] , list ( discover . itersubclasses ( A ) ) ) <EOL> class LoadExtraModulesTestCase ( test . TestCase ) : <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , return_value = True ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , <EOL> return_value = ( mock . MagicMock ( ) , None , None ) ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , return_value = [ <EOL> ( "<STR_LIT>" , ( "<STR_LIT>" , ) , ( "<STR_LIT>" , ) ) , <EOL> ( "<STR_LIT>" , ( "<STR_LIT>" , ) , ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , [ ] , ( "<STR_LIT>" , ) ) ] ) <EOL> def test_load_plugins_from_dir_successful ( self , mock_os_walk , <EOL> mock_find_module , <EOL> mock_load_module , mock_isdir ) : <EOL> test_path = "<STR_LIT>" <EOL> discover . load_plugins ( test_path ) <EOL> expected = [ <EOL> mock . call ( "<STR_LIT>" , [ "<STR_LIT>" ] ) , <EOL> mock . call ( "<STR_LIT>" , [ "<STR_LIT>" ] ) , <EOL> mock . call ( "<STR_LIT>" , [ "<STR_LIT>" ] ) <EOL> ] <EOL> self . assertEqual ( expected , mock_find_module . mock_calls ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( mock_load_module . mock_calls ) ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , return_value = True ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER ) <EOL> def test_load_plugins_from_file_successful ( self , mock_load_source , <EOL> mock_isfile ) : <EOL> discover . load_plugins ( "<STR_LIT>" ) <EOL> expected = [ mock . call ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> self . assertEqual ( expected , mock_load_source . mock_calls ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER ) <EOL> def test_load_plugins_from_nonexisting_and_empty_dir ( self , mock_os ) : <EOL> mock_os . path . isdir . return_value = False <EOL> discover . load_plugins ( "<STR_LIT>" ) <EOL> mock_os . path . isdir . return_value = True <EOL> mock_os . walk . return_value = [ ] <EOL> discover . load_plugins ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , return_value = True ) <EOL> def test_load_plugins_from_file_fails ( self , mock_isfile ) : <EOL> discover . load_plugins ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , return_value = False ) <EOL> def test_load_plugins_from_nonexisting_file ( self , mock_isfile ) : <EOL> discover . load_plugins ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , side_effect = Exception ( ) ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , return_value = True ) <EOL> @ mock . patch ( "<STR_LIT>" % DISCOVER , <EOL> return_value = [ ( "<STR_LIT>" , [ ] , ( "<STR_LIT>" , ) ) ] ) <EOL> def test_load_plugins_fails ( self , mock_os_walk , mock_os_path , <EOL> mock_find_module , mock_load_module ) : <EOL> discover . load_plugins ( "<STR_LIT>" ) </s>
