#!/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)