|
| 1 | +name: Rust Backend Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'rust/**' |
| 8 | + - 'diff_diff/**' |
| 9 | + - 'tests/**' |
| 10 | + - 'pyproject.toml' |
| 11 | + - '.github/workflows/rust-test.yml' |
| 12 | + pull_request: |
| 13 | + branches: [main] |
| 14 | + paths: |
| 15 | + - 'rust/**' |
| 16 | + - 'diff_diff/**' |
| 17 | + - 'tests/**' |
| 18 | + - 'pyproject.toml' |
| 19 | + - '.github/workflows/rust-test.yml' |
| 20 | + |
| 21 | +env: |
| 22 | + CARGO_TERM_COLOR: always |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Run Rust unit tests |
| 26 | + rust-tests: |
| 27 | + name: Rust Unit Tests |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Install Rust toolchain |
| 33 | + uses: dtolnay/rust-toolchain@stable |
| 34 | + |
| 35 | + - name: Install OpenBLAS |
| 36 | + run: sudo apt-get update && sudo apt-get install -y libopenblas-dev |
| 37 | + |
| 38 | + - name: Run Rust tests |
| 39 | + working-directory: rust |
| 40 | + run: cargo test --verbose |
| 41 | + |
| 42 | + # Build and test with Python on multiple platforms |
| 43 | + python-tests: |
| 44 | + name: Python Tests (${{ matrix.os }}) |
| 45 | + runs-on: ${{ matrix.os }} |
| 46 | + strategy: |
| 47 | + fail-fast: false |
| 48 | + matrix: |
| 49 | + os: [ubuntu-latest, macos-latest] |
| 50 | + # Windows excluded due to Intel MKL build complexity |
| 51 | + |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v4 |
| 54 | + |
| 55 | + - name: Set up Python |
| 56 | + uses: actions/setup-python@v5 |
| 57 | + with: |
| 58 | + python-version: '3.11' |
| 59 | + |
| 60 | + - name: Install OpenBLAS (Ubuntu) |
| 61 | + if: matrix.os == 'ubuntu-latest' |
| 62 | + run: sudo apt-get update && sudo apt-get install -y libopenblas-dev |
| 63 | + |
| 64 | + - name: Install OpenBLAS (macOS) |
| 65 | + if: matrix.os == 'macos-latest' |
| 66 | + run: brew install openblas |
| 67 | + |
| 68 | + - name: Set OpenBLAS paths (macOS) |
| 69 | + if: matrix.os == 'macos-latest' |
| 70 | + run: | |
| 71 | + echo "OPENBLAS_DIR=$(brew --prefix openblas)" >> $GITHUB_ENV |
| 72 | + echo "PKG_CONFIG_PATH=$(brew --prefix openblas)/lib/pkgconfig" >> $GITHUB_ENV |
| 73 | +
|
| 74 | + - name: Install Rust toolchain |
| 75 | + uses: dtolnay/rust-toolchain@stable |
| 76 | + |
| 77 | + - name: Install test dependencies |
| 78 | + run: pip install pytest numpy pandas scipy |
| 79 | + |
| 80 | + - name: Build and install with maturin |
| 81 | + run: | |
| 82 | + pip install maturin |
| 83 | + maturin build --release -o dist |
| 84 | + echo "=== Built wheels ===" |
| 85 | + ls -la dist/ |
| 86 | + # --no-index ensures we install from local wheel, not PyPI |
| 87 | + pip install --no-index --find-links=dist diff-diff |
| 88 | +
|
| 89 | + - name: Verify Rust backend is available |
| 90 | + # Run from /tmp to avoid source directory shadowing installed package |
| 91 | + working-directory: /tmp |
| 92 | + run: | |
| 93 | + python -c "import diff_diff; print('Location:', diff_diff.__file__)" |
| 94 | + python -c "from diff_diff import HAS_RUST_BACKEND; print('HAS_RUST_BACKEND:', HAS_RUST_BACKEND); assert HAS_RUST_BACKEND, 'Rust backend not available'" |
| 95 | +
|
| 96 | + - name: Copy tests to isolated location |
| 97 | + run: cp -r tests /tmp/tests |
| 98 | + |
| 99 | + - name: Run Rust backend tests |
| 100 | + working-directory: /tmp |
| 101 | + run: pytest tests/test_rust_backend.py -v |
| 102 | + |
| 103 | + - name: Run tests with Rust backend |
| 104 | + working-directory: /tmp |
| 105 | + run: DIFF_DIFF_BACKEND=rust pytest tests/ -x -q |
| 106 | + |
| 107 | + # Test pure Python fallback (without Rust extension) |
| 108 | + python-fallback: |
| 109 | + name: Pure Python Fallback |
| 110 | + runs-on: ubuntu-latest |
| 111 | + steps: |
| 112 | + - uses: actions/checkout@v4 |
| 113 | + |
| 114 | + - name: Set up Python |
| 115 | + uses: actions/setup-python@v5 |
| 116 | + with: |
| 117 | + python-version: '3.11' |
| 118 | + |
| 119 | + - name: Install dependencies |
| 120 | + run: pip install numpy pandas scipy pytest |
| 121 | + |
| 122 | + - name: Verify pure Python mode |
| 123 | + run: | |
| 124 | + # Use PYTHONPATH to import directly (skips maturin build) |
| 125 | + PYTHONPATH=. python -c "from diff_diff import HAS_RUST_BACKEND; print(f'HAS_RUST_BACKEND: {HAS_RUST_BACKEND}'); assert not HAS_RUST_BACKEND" |
| 126 | +
|
| 127 | + - name: Run tests in pure Python mode |
| 128 | + run: PYTHONPATH=. DIFF_DIFF_BACKEND=python pytest tests/ -x -q --ignore=tests/test_rust_backend.py |
0 commit comments