|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +from unittest.mock import patch |
| 4 | + |
| 5 | +from click.testing import CliRunner |
| 6 | + |
| 7 | +from rapids_cli.cli import debug, doctor, rapids |
| 8 | + |
| 9 | + |
| 10 | +def test_rapids_cli_help(): |
| 11 | + """Test rapids CLI help output.""" |
| 12 | + runner = CliRunner() |
| 13 | + result = runner.invoke(rapids, ["--help"]) |
| 14 | + assert result.exit_code == 0 |
| 15 | + assert "The Rapids CLI is a command-line interface for RAPIDS" in result.output |
| 16 | + |
| 17 | + |
| 18 | +def test_doctor_command_help(): |
| 19 | + """Test doctor command help output.""" |
| 20 | + runner = CliRunner() |
| 21 | + result = runner.invoke(rapids, ["doctor", "--help"]) |
| 22 | + assert result.exit_code == 0 |
| 23 | + assert "Run health checks" in result.output |
| 24 | + |
| 25 | + |
| 26 | +def test_debug_command_help(): |
| 27 | + """Test debug command help output.""" |
| 28 | + runner = CliRunner() |
| 29 | + result = runner.invoke(rapids, ["debug", "--help"]) |
| 30 | + assert result.exit_code == 0 |
| 31 | + assert "Gather debugging information" in result.output |
| 32 | + |
| 33 | + |
| 34 | +def test_doctor_command_success(): |
| 35 | + """Test doctor command with successful checks.""" |
| 36 | + runner = CliRunner() |
| 37 | + with patch("rapids_cli.cli.doctor_check", return_value=True): |
| 38 | + result = runner.invoke(rapids, ["doctor"]) |
| 39 | + assert result.exit_code == 0 |
| 40 | + |
| 41 | + |
| 42 | +def test_doctor_command_failure(): |
| 43 | + """Test doctor command with failed checks.""" |
| 44 | + runner = CliRunner() |
| 45 | + with patch("rapids_cli.cli.doctor_check", return_value=False): |
| 46 | + result = runner.invoke(rapids, ["doctor"]) |
| 47 | + assert result.exit_code == 1 |
| 48 | + assert "Health checks failed" in result.output |
| 49 | + |
| 50 | + |
| 51 | +def test_doctor_command_verbose(): |
| 52 | + """Test doctor command with verbose flag.""" |
| 53 | + runner = CliRunner() |
| 54 | + with patch("rapids_cli.cli.doctor_check", return_value=True) as mock_check: |
| 55 | + result = runner.invoke(rapids, ["doctor", "--verbose"]) |
| 56 | + assert result.exit_code == 0 |
| 57 | + mock_check.assert_called_once_with(True, False, ()) |
| 58 | + |
| 59 | + |
| 60 | +def test_doctor_command_dry_run(): |
| 61 | + """Test doctor command with dry-run flag.""" |
| 62 | + runner = CliRunner() |
| 63 | + with patch("rapids_cli.cli.doctor_check", return_value=True) as mock_check: |
| 64 | + result = runner.invoke(rapids, ["doctor", "--dry-run"]) |
| 65 | + assert result.exit_code == 0 |
| 66 | + mock_check.assert_called_once_with(False, True, ()) |
| 67 | + |
| 68 | + |
| 69 | +def test_doctor_command_with_filters(): |
| 70 | + """Test doctor command with filters.""" |
| 71 | + runner = CliRunner() |
| 72 | + with patch("rapids_cli.cli.doctor_check", return_value=True) as mock_check: |
| 73 | + result = runner.invoke(rapids, ["doctor", "cudf", "cuml"]) |
| 74 | + assert result.exit_code == 0 |
| 75 | + mock_check.assert_called_once_with(False, False, ("cudf", "cuml")) |
| 76 | + |
| 77 | + |
| 78 | +def test_debug_command_console(): |
| 79 | + """Test debug command with console output.""" |
| 80 | + runner = CliRunner() |
| 81 | + with patch("rapids_cli.cli.run_debug") as mock_debug: |
| 82 | + result = runner.invoke(rapids, ["debug"]) |
| 83 | + assert result.exit_code == 0 |
| 84 | + mock_debug.assert_called_once_with(output_format="console") |
| 85 | + |
| 86 | + |
| 87 | +def test_debug_command_json(): |
| 88 | + """Test debug command with JSON output.""" |
| 89 | + runner = CliRunner() |
| 90 | + with patch("rapids_cli.cli.run_debug") as mock_debug: |
| 91 | + result = runner.invoke(rapids, ["debug", "--json"]) |
| 92 | + assert result.exit_code == 0 |
| 93 | + mock_debug.assert_called_once_with(output_format="json") |
| 94 | + |
| 95 | + |
| 96 | +def test_doctor_standalone(): |
| 97 | + """Test doctor command as standalone function.""" |
| 98 | + runner = CliRunner() |
| 99 | + with patch("rapids_cli.cli.doctor_check", return_value=True): |
| 100 | + result = runner.invoke(doctor) |
| 101 | + assert result.exit_code == 0 |
| 102 | + |
| 103 | + |
| 104 | +def test_debug_standalone(): |
| 105 | + """Test debug command as standalone function.""" |
| 106 | + runner = CliRunner() |
| 107 | + with patch("rapids_cli.cli.run_debug"): |
| 108 | + result = runner.invoke(debug) |
| 109 | + assert result.exit_code == 0 |
0 commit comments