|
| 1 | +"""Basic CLI tests to verify core functionality.""" |
| 2 | + |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | + |
| 8 | +def test_cli_help_works(): |
| 9 | + """Test that the CLI can show help without credentials.""" |
| 10 | + # Run the CLI help command |
| 11 | + result = subprocess.run( |
| 12 | + [sys.executable, "-m", "codegen.cli.cli", "--help"], |
| 13 | + capture_output=True, |
| 14 | + text=True, |
| 15 | + cwd=Path(__file__).parent.parent.parent.parent, # Go to project root |
| 16 | + ) |
| 17 | + |
| 18 | + # Should exit with code 0 (success) |
| 19 | + assert result.returncode == 0 |
| 20 | + |
| 21 | + # Should contain basic help text |
| 22 | + assert "Codegen CLI - Transform your code with AI" in result.stdout |
| 23 | + assert "Commands" in result.stdout |
| 24 | + assert "init" in result.stdout |
| 25 | + assert "login" in result.stdout |
| 26 | + assert "profile" in result.stdout |
| 27 | + |
| 28 | + |
| 29 | +def test_cli_version_works(): |
| 30 | + """Test that the CLI can show version without credentials.""" |
| 31 | + result = subprocess.run( |
| 32 | + [sys.executable, "-m", "codegen.cli.cli", "--version"], |
| 33 | + capture_output=True, |
| 34 | + text=True, |
| 35 | + cwd=Path(__file__).parent.parent.parent.parent, # Go to project root |
| 36 | + ) |
| 37 | + |
| 38 | + # Should exit with code 0 (success) |
| 39 | + assert result.returncode == 0 |
| 40 | + |
| 41 | + # Should show some version information |
| 42 | + assert len(result.stdout.strip()) > 0 |
| 43 | + |
| 44 | + |
| 45 | +def test_cli_command_help(): |
| 46 | + """Test that individual commands can show help.""" |
| 47 | + commands = ["init", "login", "logout", "profile", "config", "update"] |
| 48 | + |
| 49 | + for command in commands: |
| 50 | + result = subprocess.run( |
| 51 | + [sys.executable, "-m", "codegen.cli.cli", command, "--help"], |
| 52 | + capture_output=True, |
| 53 | + text=True, |
| 54 | + cwd=Path(__file__).parent.parent.parent.parent, # Go to project root |
| 55 | + ) |
| 56 | + |
| 57 | + # Should exit with code 0 (success) for help |
| 58 | + assert result.returncode == 0, f"Command '{command} --help' failed with code {result.returncode}" |
| 59 | + |
| 60 | + # Should contain usage information |
| 61 | + assert "Usage:" in result.stdout, f"Command '{command} --help' doesn't show usage" |
| 62 | + |
| 63 | + |
| 64 | +def test_cli_imports_work(): |
| 65 | + """Test that we can import the CLI module without errors.""" |
| 66 | + # This test verifies that all imports in the CLI work |
| 67 | + try: |
| 68 | + from codegen.cli.cli import main |
| 69 | + |
| 70 | + assert main is not None |
| 71 | + |
| 72 | + # Test Agent import still works |
| 73 | + from codegen.agents.agent import Agent |
| 74 | + |
| 75 | + assert Agent is not None |
| 76 | + |
| 77 | + except ImportError as e: |
| 78 | + assert False, f"Failed to import CLI modules: {e}" |
0 commit comments