示例#1
0
    def _locate_nuget_path(self, nuget_path):
        """
        Locates NuGet executable path from user input or NuGet facade.
        @:raises click.UsageError
        """
        # If NuGet path is provided, check if it's valid
        if nuget_path:
            if not NuGetRunner.valid_nuget_executable(nuget_path):
                raise click.UsageError(nuget_path + " is not a valid NuGet executable.")
            else:
                return nuget_path

        # NuGet is not provided, locate
        nuget_path = NuGetRunner.locate_nuget()
        if nuget_path:
            return nuget_path

        # Failed to locate
        if not self.quiet:
            if sys.platform == 'win32':
                click.secho('You can install NuGet from the official website: https://www.nuget.org/downloads')
                click.secho('You might need to add NuGet installation folder to your PATH variable.')
            elif sys.platform == 'darwin':
                click.secho('You can install NuGet using Homebrew ("brew install nuget") or '
                            'download from the official website')
                click.secho('You might need to add NuGet installation folder to your PATH variable.')
        raise click.UsageError('Failed to locate NuGet executable.')
示例#2
0
 def test_nuget_runner_valid_nuget_executable(self, mock_call, mock_open,
                                              mock_escape_exe_path):
     """Test NuGetRunner.valid_nuget_executable """
     mock_call.return_value = 0
     with open(os.devnull, "w") as devnull:
         mock_open_handler = MagicMock()
         mock_open.return_value = mock_open_handler
         mock_open_handler.__enter__.return_value = devnull
         mock_escape_exe_path.return_value = "nuget.exe"
         assert NuGetRunner.valid_nuget_executable("nuget.exe")
         mock_call.assert_called_with("nuget.exe help",
                                      shell=True,
                                      stderr=devnull,
                                      stdout=devnull)