-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Summary
The PyTensor integration tests in test_helpers.py are unconditionally skipped with skipif(True, ...), meaning they never run even when PyTensor is installed. Given that PyTensor compatibility was a key design goal (mentioned in the helpers module docstring), these tests should run when PyTensor is available.
Current Behavior
@pytest.mark.skipif(True, reason="PyTensor not required for core functionality")
class TestPyTensorOps:
"""Test PyTensor operations (skipped if PyTensor not available)."""
def test_pytensor_ops_lazy_import(self):
# This NEVER runs
...Expected Behavior
Tests should be conditionally skipped based on PyTensor availability:
pytensor_available = False
try:
import pytensor
pytensor_available = True
except ImportError:
pass
@pytest.mark.skipif(not pytensor_available, reason="PyTensor not installed")
class TestPyTensorOps:
"""Test PyTensor operations."""
def test_pytensor_ops_work_with_helpers(self):
import pytensor.tensor as pt
from conjugate.helpers import poisson_gamma_inputs, pytensor_ops
# Test that pytensor_ops can be used with helpers
data = pt.as_tensor_variable([1, 2, 3, 4, 5])
inputs = poisson_gamma_inputs(data, **pytensor_ops)
# Verify the result is a PyTensor expression
...Why This Matters
-
PyTensor integration is a key feature - The helpers module docstring specifically mentions PyTensor compatibility:
"""For PyTensor compatibility: from conjugate.helpers import poisson_gamma_inputs, pytensor_ops inputs = poisson_gamma_inputs(observations, **pytensor_ops) """
-
The feedback document highlights this - PyMC integration (which uses PyTensor) was the primary motivation for creating the helpers module.
-
Untested code paths - Without tests, regressions in PyTensor support could go unnoticed.
Suggested Fix
import pytest
try:
import pytensor
import pytensor.tensor as pt
PYTENSOR_AVAILABLE = True
except ImportError:
PYTENSOR_AVAILABLE = False
@pytest.mark.skipif(not PYTENSOR_AVAILABLE, reason="PyTensor not installed")
class TestPyTensorOps:
"""Test PyTensor operations when PyTensor is available."""
def test_pytensor_ops_contains_expected_keys(self):
from conjugate.helpers import pytensor_ops
assert "sum_fn" in pytensor_ops
assert "len_fn" in pytensor_ops
assert "prod_fn" in pytensor_ops
assert callable(pytensor_ops["sum_fn"])
def test_pytensor_ops_with_poisson_gamma(self):
from conjugate.helpers import poisson_gamma_inputs, pytensor_ops
data = pt.as_tensor_variable([1.0, 2.0, 3.0, 4.0, 5.0])
relevant_ops = {k: v for k, v in pytensor_ops.items() if k in ["sum_fn", "len_fn"]}
result = poisson_gamma_inputs(data, **relevant_ops)
# Compile and evaluate
import pytensor
x_total_fn = pytensor.function([], result["x_total"])
n_fn = pytensor.function([], result["n"])
assert x_total_fn() == 15.0
assert n_fn() == 5Optional: CI Integration
Consider adding a CI job that installs PyTensor and runs these tests:
# In .github/workflows/tests.yml
jobs:
test-pytensor:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install with PyTensor
run: |
pip install pytensor
pip install -e .
- name: Run PyTensor tests
run: pytest tests/test_helpers.py -k "PyTensor" -v