refactor: Convert to UV Python project with proper package structure
- Restructured project to use src/stocktool package layout - Migrated to UV for dependency management - Added pyproject.toml with all dependencies (sv-ttk, pillow, requests, pyyaml) - Organized test files into tests/ directory - Updated .gitignore for UV projects - Comprehensive README with installation and usage instructions - Removed old unused files (main.py, stock_tool_gui.py, duplicate copy) - Added CLI entry point: stock-tool command 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
77
tests/test_stock_level.py
Normal file
77
tests/test_stock_level.py
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test script to verify find_stock_item and get_stock_level work correctly."""
|
||||
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
def find_stock_item(data_response: Any) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Simulate find_stock_item parsing logic.
|
||||
|
||||
Args:
|
||||
data_response: The response from the API
|
||||
|
||||
Returns:
|
||||
Stock item dictionary or None if not found
|
||||
"""
|
||||
data = data_response
|
||||
results = data.get('results', data) if isinstance(data, dict) else data
|
||||
return results[0] if results else None
|
||||
|
||||
|
||||
def get_stock_level(item: Optional[Dict[str, Any]]) -> float:
|
||||
"""
|
||||
Get stock level from item.
|
||||
|
||||
Args:
|
||||
item: Stock item dictionary
|
||||
|
||||
Returns:
|
||||
Stock quantity
|
||||
"""
|
||||
return item.get('quantity', 0) if item else 0
|
||||
|
||||
|
||||
# Test cases
|
||||
print("Test 1: API returns dict with 'results' key")
|
||||
api_response_1 = {
|
||||
'results': [
|
||||
{'pk': 123, 'quantity': 50, 'part': 456, 'location': 789}
|
||||
]
|
||||
}
|
||||
item = find_stock_item(api_response_1)
|
||||
stock = get_stock_level(item)
|
||||
print(f" Item: {item}")
|
||||
print(f" Stock level: {stock}")
|
||||
print(f" Expected: 50, Got: {stock} - {'PASS' if stock == 50 else 'FAIL'}")
|
||||
print()
|
||||
|
||||
print("Test 2: API returns dict with empty results")
|
||||
api_response_2 = {'results': []}
|
||||
item = find_stock_item(api_response_2)
|
||||
stock = get_stock_level(item)
|
||||
print(f" Item: {item}")
|
||||
print(f" Stock level: {stock}")
|
||||
print(f" Expected: 0, Got: {stock} - {'PASS' if stock == 0 else 'FAIL'}")
|
||||
print()
|
||||
|
||||
print("Test 3: API returns list directly")
|
||||
api_response_3 = [
|
||||
{'pk': 124, 'quantity': 100, 'part': 456, 'location': 789}
|
||||
]
|
||||
item = find_stock_item(api_response_3)
|
||||
stock = get_stock_level(item)
|
||||
print(f" Item: {item}")
|
||||
print(f" Stock level: {stock}")
|
||||
print(f" Expected: 100, Got: {stock} - {'PASS' if stock == 100 else 'FAIL'}")
|
||||
print()
|
||||
|
||||
print("Test 4: API returns empty list")
|
||||
api_response_4 = []
|
||||
item = find_stock_item(api_response_4)
|
||||
stock = get_stock_level(item)
|
||||
print(f" Item: {item}")
|
||||
print(f" Stock level: {stock}")
|
||||
print(f" Expected: 0, Got: {stock} - {'PASS' if stock == 0 else 'FAIL'}")
|
||||
print()
|
||||
|
||||
print("All tests completed!")
|
||||
Reference in New Issue
Block a user