#NEWLINE# def test_remove( self ) : #NEWLINE# #INDENT# '\n        Test if it remove a package and all its dependencies\n        which are not in use by other packages.\n        ' #NEWLINE# mock_pkg = MagicMock ( side_effect = MinionError ) #NEWLINE# with patch . dict ( pkgutil . __salt__ , { #NEWLINE# #INDENT# 'pkg_resource.parse_targets' : mock_pkg , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertRaises ( CommandExecutionError , pkgutil . remove ) #NEWLINE# #UNINDENT# mock_ret = MagicMock ( return_value = True ) #NEWLINE# mock_run = MagicMock ( return_value = 'A\t B\t SAME' ) #NEWLINE# mock_run_all = MagicMock ( return_value = { #NEWLINE# #INDENT# 'stdout' : '' , #NEWLINE# #UNINDENT# } ) #NEWLINE# mock_pkg = MagicMock ( return_value = [ '' ] ) #NEWLINE# with patch . dict ( pkgutil . __salt__ , { #NEWLINE# #INDENT# 'pkg_resource.parse_targets' : mock_pkg , #NEWLINE# 'pkg_resource.stringify' : mock_pkg , #NEWLINE# 'pkg_resource.sort_pkglist' : mock_pkg , #NEWLINE# 'cmd.run_all' : mock_run_all , #NEWLINE# 'cmd.run' : mock_run , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# with patch . dict ( pkgutil . __context__ , { #NEWLINE# #INDENT# 'pkg.list_pkgs' : mock_ret , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertDictEqual ( pkgutil . remove ( ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# mock_pkg = MagicMock ( return_value = [ { #NEWLINE# #INDENT# 'bar' : '1.2.3' , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# with patch . dict ( pkgutil . __salt__ , { #NEWLINE# #INDENT# 'pkg_resource.parse_targets' : mock_pkg , #NEWLINE# 'pkg_resource.stringify' : mock_pkg , #NEWLINE# 'pkg_resource.sort_pkglist' : mock_pkg , #NEWLINE# 'cmd.run_all' : mock_run_all , #NEWLINE# 'cmd.run' : mock_run , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# with patch . dict ( pkgutil . __context__ , { #NEWLINE# #INDENT# 'pkg.list_pkgs' : mock_ret , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# with patch . object ( pkgutil , 'list_pkgs' , return_value = { #NEWLINE# #INDENT# 'bar' : '1.2.3' , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertDictEqual ( pkgutil . remove ( pkgs = '["foo", "bar"]' ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } )