#NEWLINE# def test_portage_available( ) : #NEWLINE# #INDENT# if ( not is_gentoo ( ) ) : #NEWLINE# #INDENT# print ( 'Skipping not Gentoo' ) #NEWLINE# return #NEWLINE# #UNINDENT# from rosdep2.platforms.gentoo import portage_available #NEWLINE# original_exists = os . path . exists #NEWLINE# path_overrides = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# def mock_path( path ) : #NEWLINE# #INDENT# if ( path in path_overrides ) : #NEWLINE# #INDENT# return path_overrides [ path ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return original_exists ( path ) #NEWLINE# #UNINDENT# #UNINDENT# m = Mock ( side_effect = mock_path ) #NEWLINE# os . path . exists = m #NEWLINE# m . reset_mock ( ) #NEWLINE# path_overrides = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# path_overrides [ '/usr/bin/portageq' ] = False #NEWLINE# path_overrides [ '/usr/bin/emerge' ] = True #NEWLINE# val = portage_available ( ) #NEWLINE# assert ( val == False ) , 'Portage should not be available without portageq' #NEWLINE# m . reset_mock ( ) #NEWLINE# path_overrides = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# path_overrides [ '/usr/bin/portageq' ] = True #NEWLINE# path_overrides [ '/usr/bin/emerge' ] = False #NEWLINE# val = portage_available ( ) #NEWLINE# assert ( val == False ) , 'Portage should not be available without emerge' #NEWLINE# m . reset_mock ( ) #NEWLINE# path_overrides = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# path_overrides [ '/usr/bin/portageq' ] = True #NEWLINE# path_overrides [ '/usr/bin/emerge' ] = True #NEWLINE# val = portage_available ( ) #NEWLINE# assert ( val == True ) , 'Portage should be available' #NEWLINE# os . path . exists = mock_path