CoolFace
Apppublic

S-Kavin-Raj/Helmet-Detection

sourceHugging Faceupdated 9mo agoView on Hugging Face
1likes
run_backend_smoke.py43 linesDownload Raw Back to tests
1import io2import base643import sys, os4 5sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))6from app import app7 8SAMPLE_DETECTIONS = [9    {'label': 'With Helmet', 'confidence': 0.95, 'bbox': [10, 10, 100, 150], 'class_id': 0}10]11 12 13import app as app_module14 15def fake_process_image(image_data, mode='image'):16    fake_jpeg = base64.b64encode(b'\xff\xd8\xff\xd9').decode('utf-8')17    return fake_jpeg, SAMPLE_DETECTIONS18 19app_module.process_image = fake_process_image20 21with app.test_client() as client:22 23    file_bytes = io.BytesIO(b'test')24    resp = client.post('/detect', data={'image': (file_bytes, 'test.jpg'), 'mode': 'image'}, content_type='multipart/form-data')25    assert resp.status_code == 20026    data = resp.get_json()27    assert data['success'] is True28    assert 'detections' in data29    assert 'image' not in data30    print('Compact JSON test passed')31 32 33    file_bytes = io.BytesIO(b'test')34    resp = client.post('/detect', data={'image': (file_bytes, 'test.jpg'), 'mode': 'image', 'annotated': 'true'}, content_type='multipart/form-data')35    assert resp.status_code == 20036    data = resp.get_json()37    assert data['success'] is True38    assert 'detections' in data39    assert 'image' in data40    print('Annotated image test passed')41 42print('All backend smoke tests passed')43