|
| 1 | +"""Integration test to verify dependency compatibility.""" |
| 2 | + |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +import tempfile |
| 6 | +import os |
| 7 | +import pytest |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | + |
| 11 | +def test_dependency_compatibility(): |
| 12 | + """Test that all dependencies in pyproject.toml are compatible.""" |
| 13 | + # Get project root |
| 14 | + project_root = Path(__file__).parent.parent.parent |
| 15 | + pyproject_path = project_root / "pyproject.toml" |
| 16 | + |
| 17 | + assert pyproject_path.exists(), "pyproject.toml not found" |
| 18 | + |
| 19 | + with tempfile.TemporaryDirectory() as temp_dir: |
| 20 | + # Create a fresh virtual environment |
| 21 | + venv_path = os.path.join(temp_dir, "test_env") |
| 22 | + subprocess.run([sys.executable, "-m", "venv", venv_path], check=True) |
| 23 | + |
| 24 | + # Get pip path for the virtual environment |
| 25 | + if sys.platform == "win32": |
| 26 | + pip_path = os.path.join(venv_path, "Scripts", "pip") |
| 27 | + else: |
| 28 | + pip_path = os.path.join(venv_path, "bin", "pip") |
| 29 | + |
| 30 | + # Install dependencies |
| 31 | + result = subprocess.run( |
| 32 | + [pip_path, "install", "-e", str(project_root)], capture_output=True, text=True |
| 33 | + ) |
| 34 | + |
| 35 | + if result.returncode != 0: |
| 36 | + pytest.fail(f"Dependency installation failed:\n{result.stderr}") |
| 37 | + |
| 38 | + # Check for conflicts |
| 39 | + check_result = subprocess.run([pip_path, "check"], capture_output=True, text=True) |
| 40 | + |
| 41 | + if check_result.returncode != 0: |
| 42 | + pytest.fail(f"Dependency conflicts found:\n{check_result.stdout}") |
| 43 | + |
| 44 | + |
| 45 | +def test_numpy_pandas_compatibility(): |
| 46 | + """Test specific NumPy-pandas compatibility.""" |
| 47 | + try: |
| 48 | + import numpy as np |
| 49 | + import pandas as pd |
| 50 | + |
| 51 | + # Test basic operations |
| 52 | + arr = np.array([1, 2, 3]) |
| 53 | + df = pd.DataFrame({"col": arr}) |
| 54 | + |
| 55 | + # This should not raise the dtype size error |
| 56 | + result = df.values |
| 57 | + assert isinstance(result, np.ndarray) |
| 58 | + |
| 59 | + except ImportError: |
| 60 | + pytest.skip("NumPy or pandas not available") |
| 61 | + except ValueError as e: |
| 62 | + if "numpy.dtype size changed" in str(e): |
| 63 | + pytest.fail(f"NumPy-pandas compatibility issue: {e}") |
| 64 | + raise |
| 65 | + |
| 66 | + |
| 67 | +def test_critical_imports(): |
| 68 | + """Test that critical packages can be imported without conflicts.""" |
| 69 | + critical_packages = ["numpy", "pandas", "boto3", "sagemaker_core", "protobuf", "cloudpickle"] |
| 70 | + |
| 71 | + failed_imports = [] |
| 72 | + |
| 73 | + for package in critical_packages: |
| 74 | + try: |
| 75 | + __import__(package) |
| 76 | + except ImportError: |
| 77 | + # Skip if package not installed |
| 78 | + continue |
| 79 | + except Exception as e: |
| 80 | + failed_imports.append(f"{package}: {e}") |
| 81 | + |
| 82 | + if failed_imports: |
| 83 | + pytest.fail(f"Import failures:\n" + "\n".join(failed_imports)) |
0 commit comments