A Python package for analyzing function behavior and edge cases through static analysis and automated testing.
- Static analysis of function parameters and return types
- Automated edge case testing
- Detailed analysis reports
- Support for complex type hints
- Command-line interface
- Rich console output
- Python 3.8 or higher
- Dependencies:
- typing-extensions
- inspect2
- rich
- click
- pytest (for development)
pip install whatif-analyzer
git clone https://github.com/Arjunmehta312/what-if-python-package.git
cd what-if-python-package
pip install -e .
For development installation with all dependencies:
pip install -e ".[dev]"
from whatif_analyzer import analyze
@analyze()
def calculate_discount(price: float, discount_percent: float) -> float:
"""Calculate the final price after applying a discount."""
if discount_percent < 0 or discount_percent > 100:
raise ValueError("Discount must be between 0 and 100")
return price * (1 - discount_percent / 100)
whatif analyze path/to/your/module.py
from whatif_analyzer import analyze_function
def my_function(x: int, y: float) -> str:
return str(x + y)
report = analyze_function(my_function)
print(report)
Function: calculate_discount
Parameters:
- price: float
- discount_percent: float
Return Type: float
Test Results:
✓ Test 1: price=0.0, discount_percent=0.0 → 0.0
✓ Test 2: price=100.0, discount_percent=50.0 → 50.0
✗ Test 3: price=-1.0, discount_percent=0.0 → ValueError
✓ Test 4: price=0.0, discount_percent=100.0 → 0.0
from whatif_analyzer import analyze, EdgeCase
@analyze(edge_cases=[
EdgeCase("price", [0, 100, 1000]),
EdgeCase("discount_percent", [0, 50, 100])
])
def calculate_discount(price: float, discount_percent: float) -> float:
return price * (1 - discount_percent / 100)
@analyze(
max_depth=3,
include_none=True,
timeout=5.0
)
def complex_function(x: int, y: float) -> str:
# Your function here
pass
Run the test suite:
pytest
Run with coverage:
pytest --cov=whatif_analyzer
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
This package is available on PyPI: whatif-analyzer