1+ name : Comprehensive Tests
2+
3+ on :
4+ push :
5+ branches : [ "*" ]
6+ pull_request :
7+ branches : [ "*" ]
8+ schedule :
9+ # Run tests weekly on Sundays at 2 AM UTC
10+ - cron : ' 0 2 * * 0'
11+
12+ jobs :
13+ test-matrix :
14+ name : Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
15+ runs-on : ${{ matrix.os }}
16+ strategy :
17+ fail-fast : false
18+ matrix :
19+ os : [ubuntu-latest, macos-latest]
20+ python-version : ["3.9", "3.10", "3.11", "3.12"]
21+ exclude :
22+ # Skip some combinations to reduce CI time
23+ - os : macos-latest
24+ python-version : " 3.9"
25+ - os : macos-latest
26+ python-version : " 3.10"
27+
28+ steps :
29+ - name : Checkout code
30+ uses : actions/checkout@v4
31+
32+ - name : Set up Python ${{ matrix.python-version }}
33+ uses : actions/setup-python@v4
34+ with :
35+ python-version : ${{ matrix.python-version }}
36+
37+ - name : Cache pip dependencies
38+ uses : actions/cache@v3
39+ with :
40+ path : ~/.cache/pip
41+ key : ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
42+ restore-keys : |
43+ ${{ runner.os }}-pip-${{ matrix.python-version }}-
44+ ${{ runner.os }}-pip-
45+
46+ - name : Install system dependencies (Ubuntu)
47+ if : matrix.os == 'ubuntu-latest'
48+ run : |
49+ sudo apt-get update
50+ sudo apt-get install -y build-essential
51+
52+ - name : Install Python dependencies
53+ run : |
54+ python -m pip install --upgrade pip wheel setuptools
55+ pip install pytest pytest-cov pytest-xdist
56+
57+ - name : Install jaxonometrics
58+ run : |
59+ pip install -e .
60+
61+ - name : Install test dependencies
62+ run : |
63+ pip install pyfixest pandas
64+
65+ - name : Verify installation
66+ run : |
67+ python -c "import jaxonometrics; print('jaxonometrics version:', jaxonometrics.__version__)"
68+ python -c "import jax; print('JAX version:', jax.__version__)"
69+ python -c "import pyfixest; print('pyfixest available')"
70+
71+ - name : Run basic tests
72+ run : |
73+ python -m pytest tests/test_linear.py -v
74+
75+ - name : Run fixed effects tests
76+ run : |
77+ python -m pytest tests/test_fe.py -v
78+
79+ - name : Run all tests with coverage
80+ run : |
81+ python -m pytest tests/ -v --cov=jaxonometrics --cov-report=xml --cov-report=term
82+
83+ - name : Upload coverage to Codecov
84+ if : matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
85+ uses : codecov/codecov-action@v3
86+ with :
87+ file : ./coverage.xml
88+ flags : unittests
89+ name : codecov-umbrella
90+
91+ test-performance :
92+ name : Performance Tests
93+ runs-on : ubuntu-latest
94+ steps :
95+ - name : Checkout code
96+ uses : actions/checkout@v4
97+
98+ - name : Set up Python 3.11
99+ uses : actions/setup-python@v4
100+ with :
101+ python-version : " 3.11"
102+
103+ - name : Install dependencies
104+ run : |
105+ python -m pip install --upgrade pip
106+ pip install pytest pytest-benchmark
107+ pip install -e .
108+ pip install pyfixest pandas
109+
110+ - name : Run performance benchmarks
111+ run : |
112+ python -c "
113+ import numpy as np
114+ import time
115+ import jax.numpy as jnp
116+ from jaxonometrics import LinearRegression
117+
118+ # Performance test
119+ print('Running performance test...')
120+ np.random.seed(42)
121+
122+ n_obs = 10000
123+ X = jnp.asarray(np.random.randn(n_obs, 5))
124+ y = jnp.asarray(np.random.randn(n_obs))
125+
126+ model = LinearRegression(solver='lineax')
127+
128+ start_time = time.time()
129+ model.fit(X, y)
130+ end_time = time.time()
131+
132+ print(f'Linear regression on {n_obs} obs took {end_time - start_time:.4f} seconds')
133+ print('Performance test passed!')
134+ "
135+
136+ test-examples :
137+ name : Test Examples and Documentation
138+ runs-on : ubuntu-latest
139+ steps :
140+ - name : Checkout code
141+ uses : actions/checkout@v4
142+
143+ - name : Set up Python 3.11
144+ uses : actions/setup-python@v4
145+ with :
146+ python-version : " 3.11"
147+
148+ - name : Install dependencies
149+ run : |
150+ python -m pip install --upgrade pip
151+ pip install jupyter nbconvert
152+ pip install -e .
153+ pip install pyfixest pandas matplotlib seaborn
154+
155+ - name : Test example notebooks (if any)
156+ run : |
157+ # Test any Jupyter notebooks in nb/ directory
158+ if [ -d "nb" ]; then
159+ echo "Testing notebooks..."
160+ for notebook in nb/*.ipynb; do
161+ if [ -f "$notebook" ]; then
162+ echo "Testing $notebook"
163+ jupyter nbconvert --to script --execute "$notebook"
164+ fi
165+ done
166+ else
167+ echo "No notebooks directory found, skipping notebook tests"
168+ fi
169+
170+ - name : Test README examples
171+ run : |
172+ python -c "
173+ # Test basic API examples from README
174+ import numpy as np
175+ import jax.numpy as jnp
176+ from jaxonometrics import LinearRegression
177+
178+ print('Testing basic LinearRegression API...')
179+
180+ # Generate sample data
181+ np.random.seed(42)
182+ X = jnp.asarray(np.random.randn(100, 3))
183+ y = jnp.asarray(np.random.randn(100))
184+
185+ # Test basic fitting
186+ model = LinearRegression(solver='lineax')
187+ model.fit(X, y)
188+
189+ # Test prediction
190+ y_pred = model.predict(X)
191+
192+ print(f'Coefficients shape: {model.params[\"coef\"].shape}')
193+ print(f'Predictions shape: {y_pred.shape}')
194+ print('README examples test passed!')
195+ "
0 commit comments