Spaces:
Sleeping
Sleeping
Download tests/test_rules.py from danielxdata/YELY_AI_Module: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/spaces/danielxdata/YELY_AI_Module/resolve/main/tests/test_rules.py
- Command line
-
hf download hf://spaces/danielxdata/YELY_AI_Module/tests/test_rules.py
-
curl -L -o test_rules.py https://huggingface.co/spaces/danielxdata/YELY_AI_Module/resolve/main/tests/test_rules.py
2.14 kB
| import unittest | |
| from app import rules | |
| VALID_QUALITY = {"image_quality": "valid", "quality_score": 0.95} | |
| class TestRulesGate(unittest.TestCase): | |
| def test_consistent_reading_succeeds(self): | |
| parsed = { | |
| "detected_liters": 14.28, "detected_amount": 10000.0, "fuel_price": 700.0, | |
| "is_consistent": True, "ocr_confidence": 0.95, "raw_numbers": [("10000", 10000.0)], | |
| } | |
| gate = rules.evaluate(parsed, VALID_QUALITY, fuel_price=700.0) | |
| self.assertTrue(gate["success"]) | |
| def test_blurry_image_blocks(self): | |
| parsed = {"raw_numbers": [("1", 1.0)], "ocr_confidence": 0.9} | |
| gate = rules.evaluate(parsed, {"image_quality": "blurry", "quality_score": 0.35}) | |
| self.assertFalse(gate["success"]) | |
| self.assertIn("floue", gate["message"]) | |
| def test_inconsistent_data_blocks(self): | |
| parsed = { | |
| "detected_liters": 20.0, "detected_amount": 10000.0, "fuel_price": 875.0, | |
| "is_consistent": False, "ocr_confidence": 0.95, "raw_numbers": [("20", 20.0)], | |
| } | |
| gate = rules.evaluate(parsed, VALID_QUALITY, fuel_price=875.0) | |
| self.assertFalse(gate["success"]) | |
| self.assertIn("Incohérence", gate["message"]) | |
| def test_missing_price_blocks(self): | |
| parsed = { | |
| "detected_liters": 20.0, "detected_amount": None, "fuel_price": None, | |
| "is_consistent": None, "ocr_confidence": 0.9, "raw_numbers": [("20", 20.0)], | |
| } | |
| gate = rules.evaluate(parsed, VALID_QUALITY) | |
| self.assertFalse(gate["success"]) | |
| self.assertIn("Prix du litre manquant", gate["message"]) | |
| def test_low_confidence_blocks(self): | |
| parsed = { | |
| "detected_liters": 14.28, "detected_amount": 10000.0, "fuel_price": 700.0, | |
| "is_consistent": True, "ocr_confidence": 0.05, "raw_numbers": [("10000", 10000.0)], | |
| } | |
| gate = rules.evaluate(parsed, {"image_quality": "valid", "quality_score": 0.2}, fuel_price=700.0) | |
| self.assertFalse(gate["success"]) | |
| self.assertIn("Confiance", gate["message"]) | |
| if __name__ == "__main__": | |
| unittest.main() | |