o
    Ďi                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ ddd	d
dddgddddZG dd de jZdS )    N)UnidentifiedImageError)	HTTPError)OBJECT_DETECTION_URL)ObjectDetectionModel)PredictionGroupg     g@d         helmetg rh?)xywidthheightclass
confidencei   i[  )r   r   )predictionsimagec                       s   e Zd ZdZdZdZdZe de de Zedddd	d
ddZ	 fddZ
dd Zejdd Zejdd Zejdd Zdd Zejdd Zejdd Zejdd Z  ZS )TestObjectDetectionz
my-api-keyroboflowztest-12323/40jsonfalsezYOUR_IMAGE.jpg301)api_keyr   formatlabelsnameoverlapstrokec                    s*   t    | j d| j d| j | _d S )Nr   )supersetUp	workspace
dataset_idversion
version_id)self	__class__ ^/home/jeff/fluffinator/venv/lib/python3.10/site-packages/tests/models/test_object_detection.pyr#   ,   s   
 zTestObjectDetection.setUpc                 C   s(   t | j| j| jd}| |j| j d S )Nr&   )r   r   r'   r&   assertEqualid)r(   instancer+   r+   r,   test_init_sets_attributes0   s   z-TestObjectDetection.test_init_sets_attributesc                 C   sP   t | j d}t| j| j| jd}tjtj| jt	d |
|}| |t d S )Ntests/images/rabbit.JPGr-   r   )printapi_urlr   r   r'   r&   	responsesaddPOSTMOCK_RESPONSEpredictassertIsInstancer   )r(   
image_pathr0   groupr+   r+   r,   %test_predict_returns_prediction_group7   s   

z9TestObjectDetection.test_predict_returns_prediction_groupc                 C   s   d}t | j| j| jd}tjtj| jtd |	| tj
d j}| |jd | |jd| j  | |j| j | |j d S )Nr2   r-   r3   r   r8   ^)r   r   r'   r&   r6   r7   r8   r5   r9   r:   callsrequestr.   methodassertRegexurlassertDictEqualparams_default_paramsassertIsNotNonebody)r(   r<   r0   rA   r+   r+   r,   %test_predict_with_local_image_requestC   s   
z9TestObjectDetection.test_predict_with_local_image_requestc                 C   s   dd l }|jd|jd}t| j| j| jd}tjtj	| j
td || tjd j}| |jd | |jd| j
  | |j| j | |j d S )Nr   )r   r      )dtyper-   r3   r8   r?   )numpyonesuint8r   r   r'   r&   r6   r7   r8   r5   r9   r:   r@   rA   r.   rB   rC   rD   rE   rF   rG   rH   rI   )r(   npnp_arrayr0   rA   r+   r+   r,   'test_predict_with_a_numpy_array_requestS   s   
z;TestObjectDetection.test_predict_with_a_numpy_array_requestc                 C   s,   d}t | j| j| jd}| t|j| d S )Nztests/images/not_an_image.txtr-   )r   r   r'   r&   assertRaisesr   r:   r(   r<   r0   r+   r+   r,   +test_predict_with_local_wrong_image_requeste   s   z?TestObjectDetection.test_predict_with_local_wrong_image_requestc                 C   s   d}i | j d|i}t| j| j| jd}tjtj| jt	d |j
|dd tjd j}| |jd | |jd	| j  | |j| | |j d S )
Nzhttps://example.com/racoon.JPGr   r-   r3   T)hostedr   r8   r?   )rG   r   r   r'   r&   r6   r7   r8   r5   r9   r:   r@   rA   r.   rB   rC   rD   rE   rF   assertIsNonerI   )r(   r<   expected_paramsr0   rA   r+   r+   r,   &test_predict_with_hosted_image_requestj   s   z:TestObjectDetection.test_predict_with_hosted_image_requestc                 C   s   d}d}i | j d|i}t| j| j| jd}tjtj| jt	d |j
||d tjd j}| |jd | |jd	| j  | |j| | |j d S )
N100r2   r   r-   r3   )r   r   r8   r?   )rG   r   r   r'   r&   r6   r7   r8   r5   r9   r:   r@   rA   r.   rB   rC   rD   rE   rF   rH   rI   )r(   r   r<   rX   r0   rA   r+   r+   r,   $test_predict_with_confidence_request   s   z8TestObjectDetection.test_predict_with_confidence_requestc                 C   sf   d}t jt j| jdd t| j| j| jd}| t	 |
| W d    d S 1 s,w   Y  d S )Nr2   i  )statusr-   )r6   r7   r8   r5   r   r   r'   r&   rS   r   r:   rT   r+   r+   r,   4test_predict_with_non_200_response_raises_http_error   s   "zHTestObjectDetection.test_predict_with_non_200_response_raises_http_error)__name__
__module____qualname__r   r$   r%   r&   r   r5   rG   r#   r1   r6   activater>   rJ   rR   rU   rY   r[   r]   __classcell__r+   r+   r)   r,   r      s:    





r   )unittestr6   PILr   requests.exceptionsr   roboflow.configr    roboflow.models.object_detectionr   roboflow.util.predictionr   r9   TestCaser   r+   r+   r+   r,   <module>   s$    
