|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | +import sys |
| 4 | +import pytest |
| 5 | +from unittest.mock import patch |
| 6 | + |
| 7 | +def test_module_import(): |
| 8 | + """Test that pearbot module can be imported successfully.""" |
| 9 | + try: |
| 10 | + from src import pearbot |
| 11 | + assert True, "pearbot module imported successfully" |
| 12 | + except ImportError as e: |
| 13 | + pytest.fail(f"Failed to import pearbot module: {e}") |
| 14 | + |
| 15 | +def test_help_command(): |
| 16 | + """Test that --help command works.""" |
| 17 | + # Set dummy environment variables like in CI |
| 18 | + env = os.environ.copy() |
| 19 | + env.update({ |
| 20 | + 'GITHUB_APP_ID': 'dummy_id', |
| 21 | + 'GITHUB_PRIVATE_KEY': 'dummy_key', |
| 22 | + 'GITHUB_APP_WEBHOOK_SECRET': 'dummy_secret' |
| 23 | + }) |
| 24 | + |
| 25 | + result = subprocess.run( |
| 26 | + [sys.executable, '-m', 'src.pearbot', '--help'], |
| 27 | + capture_output=True, |
| 28 | + text=True, |
| 29 | + env=env |
| 30 | + ) |
| 31 | + |
| 32 | + assert result.returncode == 0, f"Help command failed with: {result.stderr}" |
| 33 | + assert "Pearbot Code Review" in result.stdout, "Help text should contain 'Pearbot Code Review'" |
| 34 | + assert "--server" in result.stdout, "Help should show --server option" |
| 35 | + assert "--diff" in result.stdout, "Help should show --diff option" |
| 36 | + |
| 37 | +def test_server_startup(): |
| 38 | + """Test that server can start (with timeout like in CI).""" |
| 39 | + # Set dummy environment variables like in CI |
| 40 | + env = os.environ.copy() |
| 41 | + env.update({ |
| 42 | + 'GITHUB_APP_ID': 'dummy_id', |
| 43 | + 'GITHUB_PRIVATE_KEY': 'dummy_key', |
| 44 | + 'GITHUB_APP_WEBHOOK_SECRET': 'dummy_secret' |
| 45 | + }) |
| 46 | + |
| 47 | + # Use timeout like in CI - expect it to timeout (exit code 124) or succeed (exit code 0) |
| 48 | + result = subprocess.run( |
| 49 | + ['timeout', '5s', sys.executable, '-m', 'src.pearbot', '--server'], |
| 50 | + capture_output=True, |
| 51 | + text=True, |
| 52 | + env=env |
| 53 | + ) |
| 54 | + |
| 55 | + # Exit code 124 means timeout (expected), 0 means success, anything else is failure |
| 56 | + assert result.returncode in [0, 124], f"Server startup failed with exit code {result.returncode}: {result.stderr}" |
0 commit comments