<s> import unittest <EOL> from mock import patch <EOL> class ThrowAway ( object ) : <EOL> @ classmethod <EOL> def run_me ( cls ) : <EOL> cls . i_was_ran = True <EOL> class TestGetFunctionPathAndOptions ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_valid_name ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import get_function_path_and_options <EOL> good_names = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:Name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for name in good_names : <EOL> cleansed_path , options = get_function_path_and_options ( name ) <EOL> self . assertEqual ( name , cleansed_path ) <EOL> self . assertIsNone ( options ) <EOL> def test_bad_function_path ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . errors import BadObjectPathError <EOL> from furious . job_utils import get_function_path_and_options <EOL> bad_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> for bad_name in bad_names : <EOL> self . assertRaises ( <EOL> BadObjectPathError , get_function_path_and_options , bad_name ) <EOL> def test_none_as_function_path ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . errors import BadObjectPathError <EOL> from furious . job_utils import get_function_path_and_options <EOL> self . assertRaises ( <EOL> BadObjectPathError , get_function_path_and_options , None ) <EOL> def test_gets_callable_path ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import get_function_path_and_options <EOL> def some_function ( ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> path , options = get_function_path_and_options ( some_function ) <EOL> self . assertEqual ( '<STR_LIT>' , path ) <EOL> self . assertIsNone ( options ) <EOL> def test_gets_class_method_path ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import get_function_path_and_options <EOL> path , options = get_function_path_and_options ( <EOL> TestGetFunctionPathAndOptions . test_gets_class_method_path ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , path ) <EOL> self . assertIsNone ( options ) <EOL> def test_gets_logging_path ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import get_function_path_and_options <EOL> import logging <EOL> path , options = get_function_path_and_options ( logging . info ) <EOL> self . assertEqual ( '<STR_LIT>' , path ) <EOL> self . assertIsNone ( options ) <EOL> def test_gets_builtin_path ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import get_function_path_and_options <EOL> path , options = get_function_path_and_options ( eval ) <EOL> self . assertEqual ( '<STR_LIT>' , path ) <EOL> self . assertIsNone ( options ) <EOL> def test_gets_default_options ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . async import defaults <EOL> from furious . job_utils import get_function_path_and_options <EOL> default_options = { <EOL> '<STR_LIT:test>' : '<STR_LIT>' <EOL> } <EOL> @ defaults ( ** default_options ) <EOL> def method_with_options ( ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> path , options = get_function_path_and_options ( method_with_options ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> path ) <EOL> self . assertEqual ( default_options , options ) <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def test_gets_default_options_from_path ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . async import FunctionPath <EOL> from furious . job_utils import get_function_path_and_options <EOL> default_options = { <EOL> '<STR_LIT:test>' : '<STR_LIT>' <EOL> } <EOL> function_path = FunctionPath ( "<STR_LIT>" ) <EOL> function_path . update_options ( default_options . copy ( ) ) <EOL> path , options = get_function_path_and_options ( function_path ) <EOL> self . assertEqual ( '<STR_LIT>' , path ) <EOL> self . assertEqual ( default_options , options ) <EOL> def test_damaged_method_raises ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . errors import BadObjectPathError <EOL> from furious . job_utils import get_function_path_and_options <EOL> class FakeFunk ( object ) : <EOL> def __call__ ( ) : <EOL> pass <EOL> some_method = FakeFunk ( ) <EOL> self . assertRaisesRegexp ( <EOL> BadObjectPathError , "<STR_LIT>" , <EOL> get_function_path_and_options , some_method ) <EOL> class TestReferenceToPath ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_gets_class ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import reference_to_path <EOL> path = reference_to_path ( ThrowAway ) <EOL> self . assertEqual ( '<STR_LIT>' , path ) <EOL> class TestPathToReference ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_runs_builtin ( self , dir_mock ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import path_to_reference <EOL> function = path_to_reference ( "<STR_LIT>" ) <EOL> self . assertIs ( dir_mock , function ) <EOL> def test_runs_classmethod ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import path_to_reference <EOL> ThrowAway . i_was_ran = False <EOL> function = path_to_reference ( <EOL> '<STR_LIT>' ) <EOL> function ( ) <EOL> self . assertTrue ( ThrowAway . i_was_ran ) <EOL> def test_raises_on_bogus_builtin ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import path_to_reference <EOL> from furious . errors import BadObjectPathError <EOL> self . assertRaisesRegexp ( <EOL> BadObjectPathError , "<STR_LIT>" , <EOL> path_to_reference , "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_runs_std_imported ( self , parser_mock ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import path_to_reference <EOL> function = path_to_reference ( "<STR_LIT>" ) <EOL> self . assertIs ( parser_mock , function ) <EOL> def test_raises_on_bogus_std_imported ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import path_to_reference <EOL> from furious . errors import BadObjectPathError <EOL> self . assertRaisesRegexp ( <EOL> BadObjectPathError , "<STR_LIT>" , <EOL> path_to_reference , "<STR_LIT>" ) <EOL> def test_casts_unicode_name_to_str ( self ) : <EOL> """<STR_LIT>""" <EOL> from furious . job_utils import path_to_reference <EOL> imported_module = path_to_reference ( <EOL> u'<STR_LIT>' ) <EOL> from furious . tests . dummy_module import dumb <EOL> self . assertIs ( dumb , imported_module ) </s>
