- Move test scripts to tests/ directory for better organization - Add improved YOLOv5 postprocessing with reference implementation - Update gitignore to exclude *.mflow files and include main.spec - Add debug capabilities and coordinate scaling improvements - Enhance multi-series support with proper validation - Add AGENTS.md documentation and example utilities 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify ClassificationResult formatting fix
|
|
"""
|
|
import sys
|
|
import os
|
|
|
|
# Add core functions to path
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
parent_dir = os.path.dirname(current_dir)
|
|
sys.path.append(os.path.join(parent_dir, 'core', 'functions'))
|
|
|
|
from Multidongle import ClassificationResult
|
|
|
|
def test_classification_result_formatting():
|
|
"""Test that ClassificationResult can be formatted without errors"""
|
|
|
|
# Create a test classification result
|
|
result = ClassificationResult(
|
|
probability=0.85,
|
|
class_name="Fire",
|
|
class_num=1,
|
|
confidence_threshold=0.5
|
|
)
|
|
|
|
print("Testing ClassificationResult formatting...")
|
|
|
|
# Test __str__ method
|
|
print(f"str(result): {str(result)}")
|
|
|
|
# Test __format__ method with empty format spec
|
|
print(f"format(result, ''): {format(result, '')}")
|
|
|
|
# Test f-string formatting (this was causing the original error)
|
|
print(f"f-string: {result}")
|
|
|
|
# Test string formatting that was likely causing the error
|
|
try:
|
|
formatted = f"Error updating inference results: {result}"
|
|
print(f"Complex formatting test: {formatted}")
|
|
print("✓ All formatting tests passed!")
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Formatting test failed: {e}")
|
|
return False
|
|
|
|
def test_is_positive_property():
|
|
"""Test the is_positive property"""
|
|
|
|
# Test positive case
|
|
positive_result = ClassificationResult(
|
|
probability=0.85,
|
|
class_name="Fire",
|
|
confidence_threshold=0.5
|
|
)
|
|
|
|
# Test negative case
|
|
negative_result = ClassificationResult(
|
|
probability=0.3,
|
|
class_name="No Fire",
|
|
confidence_threshold=0.5
|
|
)
|
|
|
|
print(f"\nTesting is_positive property...")
|
|
print(f"Positive result (0.85 > 0.5): {positive_result.is_positive}")
|
|
print(f"Negative result (0.3 > 0.5): {negative_result.is_positive}")
|
|
|
|
assert positive_result.is_positive == True
|
|
assert negative_result.is_positive == False
|
|
print("✓ is_positive property tests passed!")
|
|
|
|
if __name__ == "__main__":
|
|
print("Running ClassificationResult formatting tests...")
|
|
|
|
try:
|
|
test_classification_result_formatting()
|
|
test_is_positive_property()
|
|
print("\n🎉 All tests passed! The format string error should be fixed.")
|
|
except Exception as e:
|
|
print(f"\n❌ Test failed with error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|