|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Simple test script for QuantResearch CLI |
| 4 | +This demonstrates all the CLI functionality |
| 5 | +""" |
| 6 | + |
| 7 | +import subprocess |
| 8 | +import sys |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | + |
| 12 | +def run_command(cmd): |
| 13 | + """Run a command and print the result""" |
| 14 | + print(f"\n{'='*60}") |
| 15 | + print(f"Running: {cmd}") |
| 16 | + print('='*60) |
| 17 | + result = subprocess.run(cmd, shell=True, capture_output=True, text=True) |
| 18 | + |
| 19 | + if result.stdout: |
| 20 | + print(result.stdout) |
| 21 | + if result.stderr and result.returncode != 0: |
| 22 | + print(f"ERROR: {result.stderr}") |
| 23 | + return False |
| 24 | + |
| 25 | + return result.returncode == 0 |
| 26 | + |
| 27 | + |
| 28 | +def main(): |
| 29 | + """Run all CLI tests""" |
| 30 | + print("\n🧪 Testing QuantResearch CLI") |
| 31 | + print("="*60) |
| 32 | + |
| 33 | + # Define test directories |
| 34 | + test_data_dir = Path("test_data") |
| 35 | + test_output_dir = Path("test_output") |
| 36 | + |
| 37 | + # Create test directories |
| 38 | + test_data_dir.mkdir(exist_ok=True) |
| 39 | + test_output_dir.mkdir(exist_ok=True) |
| 40 | + |
| 41 | + # Test 1: Show help |
| 42 | + success = run_command("python -m quant_research_starter.cli --help") |
| 43 | + if not success: |
| 44 | + print("\n❌ Test 1 FAILED: Help command") |
| 45 | + sys.exit(1) |
| 46 | + |
| 47 | + # Test 2: Generate data |
| 48 | + success = run_command( |
| 49 | + "python -m quant_research_starter.cli generate-data " |
| 50 | + "-o test_data/data.csv -s 5 -d 100" |
| 51 | + ) |
| 52 | + if not success: |
| 53 | + print("\n❌ Test 2 FAILED: Generate data") |
| 54 | + sys.exit(1) |
| 55 | + |
| 56 | + # Test 3: Compute factors |
| 57 | + success = run_command( |
| 58 | + "python -m quant_research_starter.cli compute-factors " |
| 59 | + "-d test_data/data.csv -f momentum -f value -o test_output/factors.csv" |
| 60 | + ) |
| 61 | + if not success: |
| 62 | + print("\n❌ Test 3 FAILED: Compute factors") |
| 63 | + sys.exit(1) |
| 64 | + |
| 65 | + # Test 4: Run backtest |
| 66 | + success = run_command( |
| 67 | + "python -m quant_research_starter.cli backtest " |
| 68 | + "-d test_data/data.csv -s test_output/factors.csv " |
| 69 | + "-o test_output/backtest_results.json" |
| 70 | + ) |
| 71 | + if not success: |
| 72 | + print("\n❌ Test 4 FAILED: Run backtest") |
| 73 | + sys.exit(1) |
| 74 | + |
| 75 | + # Verify output files exist |
| 76 | + print("\n📁 Checking output files...") |
| 77 | + files_to_check = [ |
| 78 | + test_data_dir / "data.csv", |
| 79 | + test_output_dir / "factors.csv", |
| 80 | + test_output_dir / "backtest_results.json", |
| 81 | + test_output_dir / "backtest_plot.png" |
| 82 | + ] |
| 83 | + |
| 84 | + all_exist = True |
| 85 | + for file_path in files_to_check: |
| 86 | + if file_path.exists(): |
| 87 | + print(f"✅ {file_path} exists ({file_path.stat().st_size} bytes)") |
| 88 | + else: |
| 89 | + print(f"❌ {file_path} missing!") |
| 90 | + all_exist = False |
| 91 | + |
| 92 | + if not all_exist: |
| 93 | + print("\n❌ Some output files are missing") |
| 94 | + sys.exit(1) |
| 95 | + |
| 96 | + # Summary |
| 97 | + print("\n" + "="*60) |
| 98 | + print("✅ ALL TESTS PASSED!") |
| 99 | + print("="*60) |
| 100 | + print(f"\n📂 Test files created in:") |
| 101 | + print(f" - {test_data_dir}/") |
| 102 | + print(f" - {test_output_dir}/") |
| 103 | + print("\n💡 You can view the results and plots in the test_output directory.") |
| 104 | + |
| 105 | + |
| 106 | +if __name__ == "__main__": |
| 107 | + main() |
0 commit comments