|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Basic tests for the CLI module.""" |
| 3 | + |
| 4 | +import os |
| 5 | +import subprocess |
| 6 | +import sys |
| 7 | + |
| 8 | + |
| 9 | +def test_cli_help(): |
| 10 | + """Test that the CLI shows help.""" |
| 11 | + result = subprocess.run( |
| 12 | + [sys.executable, "cli.py", "--help"], |
| 13 | + capture_output=True, |
| 14 | + text=True, |
| 15 | + cwd=os.path.dirname(__file__), |
| 16 | + ) |
| 17 | + assert result.returncode == 0 |
| 18 | + assert "101 Linux Commands CLI" in result.stdout |
| 19 | + |
| 20 | + |
| 21 | +def test_hello_command(): |
| 22 | + """Test the hello command.""" |
| 23 | + result = subprocess.run( |
| 24 | + [sys.executable, "cli.py", "hello", "greet"], |
| 25 | + capture_output=True, |
| 26 | + text=True, |
| 27 | + cwd=os.path.dirname(__file__), |
| 28 | + ) |
| 29 | + assert result.returncode == 0 |
| 30 | + assert "Hello, World!" in result.stdout |
| 31 | + |
| 32 | + |
| 33 | +def test_hello_command_with_name(): |
| 34 | + """Test the hello command with a custom name.""" |
| 35 | + result = subprocess.run( |
| 36 | + [sys.executable, "cli.py", "hello", "greet", "--name", "Linux"], |
| 37 | + capture_output=True, |
| 38 | + text=True, |
| 39 | + cwd=os.path.dirname(__file__), |
| 40 | + ) |
| 41 | + assert result.returncode == 0 |
| 42 | + assert "Hello, Linux!" in result.stdout |
| 43 | + |
| 44 | + |
| 45 | +def test_hello_help(): |
| 46 | + """Test the hello command help.""" |
| 47 | + result = subprocess.run( |
| 48 | + [sys.executable, "cli.py", "hello", "--help"], |
| 49 | + capture_output=True, |
| 50 | + text=True, |
| 51 | + cwd=os.path.dirname(__file__), |
| 52 | + ) |
| 53 | + assert result.returncode == 0 |
| 54 | + assert "Hello command group" in result.stdout |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + test_cli_help() |
| 59 | + test_hello_command() |
| 60 | + test_hello_command_with_name() |
| 61 | + test_hello_help() |
| 62 | + print("✅ All tests passed!") |
0 commit comments