Skip to content

Commit ae45ae9

Browse files
author
Roja Reddy Sareddy
committed
Add numpy 2.0 support
1 parent 621d069 commit ae45ae9

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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))
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""Test dependency resolution using pip-tools."""
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_pip_compile_resolution():
12+
"""Test that pip-compile can resolve all dependencies without conflicts."""
13+
project_root = Path(__file__).parent.parent.parent
14+
pyproject_path = project_root / "pyproject.toml"
15+
16+
with tempfile.TemporaryDirectory() as temp_dir:
17+
# Install pip-tools
18+
subprocess.run(
19+
[sys.executable, "-m", "pip", "install", "pip-tools"], check=True, capture_output=True
20+
)
21+
22+
# Try to compile dependencies
23+
result = subprocess.run(
24+
[
25+
sys.executable,
26+
"-m",
27+
"piptools",
28+
"compile",
29+
str(pyproject_path),
30+
"--dry-run",
31+
"--quiet",
32+
],
33+
capture_output=True,
34+
text=True,
35+
cwd=temp_dir,
36+
)
37+
38+
if result.returncode != 0:
39+
# Check for specific conflict patterns
40+
stderr = result.stderr.lower()
41+
if "could not find a version" in stderr or "incompatible" in stderr:
42+
pytest.fail(f"Dependency resolution failed:\n{result.stderr}")
43+
# Other errors might be acceptable (missing extras, etc.)
44+
45+
46+
def test_pipdeptree_conflicts():
47+
"""Test using pipdeptree to detect conflicts."""
48+
try:
49+
subprocess.run(
50+
[sys.executable, "-m", "pip", "install", "pipdeptree"], check=True, capture_output=True
51+
)
52+
53+
result = subprocess.run(
54+
[sys.executable, "-m", "pipdeptree", "--warn", "conflict"],
55+
capture_output=True,
56+
text=True,
57+
)
58+
59+
if "Warning!!" in result.stdout:
60+
pytest.fail(f"Dependency conflicts detected:\n{result.stdout}")
61+
62+
except subprocess.CalledProcessError:
63+
pytest.skip("pipdeptree installation failed")
64+
65+
66+
if __name__ == "__main__":
67+
test_pip_compile_resolution()
68+
test_pipdeptree_conflicts()
69+
print("✅ Dependency resolution tests passed")

0 commit comments

Comments
 (0)