Download simple_test.py from VAH6002/TFA: direct link, hf CLI and curl.
- Browser
- Download file 5.45 kB
-
https://huggingface.co/spaces/VAH6002/TFA/resolve/main/simple_test.py
- Command line
-
hf download hf://spaces/VAH6002/TFA/simple_test.py
-
curl -L -o simple_test.py https://huggingface.co/spaces/VAH6002/TFA/resolve/main/simple_test.py
5.45 kB
| """Simple test runner for TFA functionality without full agent system.""" | |
| import os | |
| import json | |
| # Set dummy API key | |
| os.environ.setdefault("GOOGLE_API_KEY", "test-key-for-mock") | |
| def test_sponge_tools(): | |
| """Test Sponge tools with mock data.""" | |
| print("π§ͺ Testing Sponge Tools...") | |
| from tfa_agents.tools.sponge_mock import use_mock_client | |
| from tfa_agents.tools.sponge_tools import ( | |
| get_invocation_data, | |
| get_failed_actions, | |
| search_historical_failures, | |
| ) | |
| # Configure mock client | |
| use_mock_client("code_regression") | |
| # Test invocation data | |
| result = get_invocation_data("fe3e0b7f-7bb9-4524-8a79-3c62cf028243") | |
| data = json.loads(result) | |
| print(f"β Invocation Status: {data['invocation']['status']}") | |
| print(f"β Pass Rate: {data['summary']['pass_rate']:.0%}") | |
| # Test failed actions | |
| result = get_failed_actions("fe3e0b7f-7bb9-4524-8a79-3c62cf028243") | |
| actions = json.loads(result) | |
| print(f"β Failed Actions: {len(actions)}") | |
| # Test historical failures | |
| result = search_historical_failures("//gmail/android/copycat:mark_multiple_emails_as_read") | |
| history = json.loads(result) | |
| print(f"β Historical Pass Rate: {history['statistics']['pass_rate']:.1%}") | |
| def test_metrics_system(): | |
| """Test metrics system.""" | |
| print("\nπ Testing Metrics System...") | |
| from tfa_agents.tools.metrics_client import get_metrics_client | |
| from tfa_agents.shared.models import Platform | |
| client = get_metrics_client() | |
| # Test daily metrics | |
| daily_metrics = client.get_daily_failure_percentage() | |
| print("β Daily Failure Percentages:") | |
| for platform, rate in daily_metrics.items(): | |
| status = "π’" if rate < 10 else "π‘" if rate < 20 else "π΄" | |
| print(f" {status} {platform.value}: {rate:.1f}%") | |
| # Test trends | |
| trends = client.get_platform_trends("7d") | |
| print("β Platform Trends (7 days):") | |
| for platform, trend in trends.items(): | |
| trend_emoji = {"improving": "π", "degrading": "π", "stable": "β‘οΈ"}.get(trend.trend_direction, "β") | |
| print(f" {trend_emoji} {platform.value}: {trend.average_failure_rate:.1f}% ({trend.trend_direction})") | |
| def test_metrics_tools(): | |
| """Test metrics tools functions.""" | |
| print("\nπ§ Testing Metrics Tools...") | |
| from tfa_agents.tools.metrics_tools import ( | |
| get_daily_failure_percentages, | |
| get_platform_trends, | |
| get_platform_health_score, | |
| ) | |
| # Test daily percentages | |
| result = get_daily_failure_percentages(platforms="Android,Web") | |
| data = json.loads(result) | |
| print(f"β Daily Metrics: {len(data['failure_percentages'])} platforms") | |
| print(f" Average: {data['summary']['average_failure_rate']:.1f}%") | |
| # Test trends | |
| result = get_platform_trends("7d", "Android") | |
| data = json.loads(result) | |
| android_trend = data['platform_trends']['Android'] | |
| print(f"β Android Trend: {android_trend['average_failure_rate']:.1f}% ({android_trend['trend_direction']})") | |
| # Test health score | |
| result = get_platform_health_score("Android", "7d") | |
| data = json.loads(result) | |
| if 'error' not in data: | |
| print(f"β Android Health: {data['health_score']}/100 ({data['status']})") | |
| def main(): | |
| """Run all tests.""" | |
| print(""" | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β TFA Simple Test Runner β | |
| β Testing core functionality without agents β | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| """) | |
| try: | |
| test_sponge_tools() | |
| test_metrics_system() | |
| test_metrics_tools() | |
| print(""" | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β β ALL TESTS PASSED! β | |
| β β | |
| β π Your TFA application is ready to use! β | |
| β β | |
| β Next steps: β | |
| β β’ Run: streamlit run tfa_ui/app.py (for web interface) β | |
| β β’ Run: python -m tfa_agents.metrics_cli daily (for CLI) β | |
| β β’ Check the metrics dashboard in the web UI β | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| """) | |
| except Exception as e: | |
| print(f"\nβ Test failed: {type(e).__name__}: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| if __name__ == "__main__": | |
| main() |