o
    OZhX                    @   s  d dl Z d dlZd dlZ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 ed ZZed ZZd	Zd
d Zdd Zdd Zdd ZdKddZdd ZG dd dZG dd dejZG dd dejZG dd dZG dd  d eeZG d!d" d"ZG d#d$ d$eZ G d%d& d&e eZ!G d'd( d(eZ"G d)d* d*e"eZ#G d+d, d,eZ$G d-d. d.e$eZ%G d/d0 d0eZ&G d1d2 d2e&eZ'd d gd3d gd3d3gd d3gfZ(g d4Z)d5d gd6d gd6d5gd7d5gd7d6gd6d6gd6d7gd5d7gd5d6gd d6gd d5gd5d5gfZ*G d8d9 d9Z+G d:d; d;e+eZ,G d<d= d=Z-G d>d? d?e-eZ.G d@dA dAZ/G dBdC dCe/eZ0G dDdE dEZ1G dFdG dGe1eZ2G dHdI dIejZ3e4dJkr[e5  dS dS )L    N)draw)draw_py)SRCALPHA)
test_utils)Vector2redgreen	topleftmidtoptoprightmidrightbottomright	midbottom
bottomleftmidleftcenterc                    sh   fddt D }fddt  D }fddt  D } fddt D }||||gS )zRReturns a list containing lists with the values of the surface's
    borders.
    c                    s   g | ]	}  |d fqS r   get_at.0xsurface E/var/www/auris/lib/python3.10/site-packages/pygame/tests/draw_test.py
<listcomp>#       z%get_border_values.<locals>.<listcomp>c                    s   g | ]	}  d |fqS r   r   r   yr   r   r   r   $   r   c                    s   g | ]}  d  |fqS    r   r   )r   widthr   r   r   %       c                    s   g | ]} | d  fqS r!   r   r   )heightr   r   r   r   &   r$   range)r   r#   r%   Z
border_topZborder_leftZborder_rightZborder_bottomr   )r%   r   r#   r   get_border_values   s
   r(   c                 C   s4   |   \}}d|d df|d |d fd|d ffS )zmReturns a tuple with the corner positions of the given surface.

    Clockwise from the top left corner.
    r   r   r"   r   )get_size)r   r#   r%   r   r   r   corners+   s   (r+   c              	   C   s(   | j | j| j| j| j| j| j| j| jf	S )zReturns a tuple with each corner, mid, and the center for a given rect.

    Clockwise from the top left corner and ending with the center point.
    r	   )rectr   r   r   rect_corners_mids_and_center4   s   r-   c                 c   s    |   \}}|d |d }}t|D ]}|df}|| |fV  qtd|D ]}||f}|| |fV  q(t|d ddD ]}||f}|| |fV  q?t|d ddD ]}d|f}|| |fV  qVdS )zlYields each border position and its color for a given surface.

    Clockwise from the top left corner.
    r"   r   N)r*   r'   r   )r   r#   r%   rightbottomr   posr    r   r   r   border_pos_and_colorF   s    r2   Tc                    s   | j |du rt|  }t|  nt|j|j}t|j|j|   |r4 fdd|D }n fdd|D }| 	  |S )a  Get all the points of a given color on the surface within the given
    bounds.

    If bounds_rect is None the full surface is checked.
    If match_color is True, all points matching the color are returned,
        otherwise all points not matching the color are returned.
    Nc                    s.   g | ]}D ]}||f kr||fqqS r   r   r   r   r    colorr   Zy_ranger   r   r   z      . z$get_color_points.<locals>.<listcomp>c                    s.   g | ]}D ]}||f kr||fqqS r   r   r3   r4   r   r   r   |   r6   )
r   r'   	get_width
get_heightleftr/   topr0   lockunlock)r   r5   bounds_rectZmatch_colorZx_rangeptsr   r4   r   get_color_pointsf   s   r?   c                 C   s   |   j\}}||}}d\}}| j}	|   t|D ]%}
t|D ]}|	||
f|kr?t||}t||}t|
|}t|
|}q!q|   d|krOt	|dS t	||f|| d || d fS )zCreate a rect to bound all the pixels that don't match surf_color.

    The default_pos parameter is used to position the bounding rect for the
    case where all pixels match the surf_color.
    r.   r.   r.   r)   r"   )
Zget_clipsizer   r;   r'   minmaxr<   pygameRect)r   
surf_colorZdefault_posr#   r%   ZxminZyminZxmaxZymaxr   r    r   r   r   r   create_bounding_rect   s$   




$rG   c                   @   s   e Zd ZdZdZdS )InvalidBoolz!To help test invalid bool values.N)__name__
__module____qualname____doc____bool__r   r   r   r   rH      s    rH   c                   @   sj   e Zd ZdZeejZeejZ	eej
ZeejZeejZeejZeejZeejZeejZdS )DrawTestCasez)Base class to test draw module functions.N)rI   rJ   rK   rL   staticmethodr   r,   	draw_rectpolygondraw_polygoncircledraw_circleellipsedraw_ellipsearcdraw_arcline	draw_linelines
draw_linesaalinedraw_aalineaalinesdraw_aalinesr   r   r   r   rN      s    







rN   c                   @   sB   e Zd ZdZeejZeejZeejZeej	Z	eej
Z
dS )PythonDrawTestCasez,Base class to test draw_py module functions.N)rI   rJ   rK   rL   rO   r   rR   rZ   r\   r^   r`   r   r   r   r   ra      s    



ra   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<S )=DrawEllipseMixinzfMixin tests for drawing ellipses.

    This class contains all the general ellipse drawing tests.
    c                 C   s0   |  tddtddd}| |tj dS )z.Ensures draw ellipse accepts the correct args.   rd   r   
   r   2   r)   rd      r"   NrV   rD   SurfacerE   assertIsInstanceselfr=   r   r   r   test_ellipse__args   s   z#DrawEllipseMixin.test_ellipse__argsc                 C   s.   |  tddtdd}| |tj dS )z6Ensures draw ellipse accepts the args without a width.ri   ri   r"   r"   r"   c   r"   r"   Nrj   rm   r   r   r    test_ellipse__args_without_width      z1DrawEllipseMixin.test_ellipse__args_without_widthc              	   C   sH   |  tddtddd}| |tj | |tdddd d	S )
z:Ensures draw ellipse accepts the args with negative width.rc   re   ri   rd   rh   r.   ri   rd   r   N)rV   rD   rk   rE   rl   assertEqualrm   r   r   r   &test_ellipse__args_with_negative_width   s
   z7DrawEllipseMixin.test_ellipse__args_with_negative_widthc                 C   sl   t dd}| t dd||jd d }| |t j | t dd||jd d }| |t j dS )zhEnsures draw ellipse accepts the args with
        width > rect.w // 2 and width > rect.h // 2.
        r)      rz   rc   re   ri   r"   N)rD   rE   rV   rk   wrl   hrn   r,   r=   r   r   r   'test_ellipse__args_with_width_gt_radius   s   z8DrawEllipseMixin.test_ellipse__args_with_width_gt_radiusc                 C   s`   t dt dt ddddt ddd	d
g}|D ]}| jdi |}| |t j qdS )z^Ensures draw ellipse accepts the correct kwargs
        with and without a width arg.
        ry   yellowr)   rh   r"   r   r5   r,   r#   ri   r"   r   rf      r   r   r"   r"   r   r5   r,   Nr   )rD   rk   ColorrE   rV   rl   rn   kwargs_listkwargsr=   r   r   r   test_ellipse__kwargs   s   
z%DrawEllipseMixin.test_ellipse__kwargsc                 C   s2   | j dtddtddd}| |tj dS )z6Ensures draw ellipse's kwargs are not order dependent.r"   ri   rd   rh   r   r"   r   rs   )r5   r   r#   r,   Nrj   rm   r   r   r   &test_ellipse__kwargs_order_independent  s   
z7DrawEllipseMixin.test_ellipse__kwargs_order_independentc                 C      t d}| t | |t d}W d   n1 sw   Y  | t | |}W d   n1 s8w   Y  | t |  }W d   dS 1 sRw   Y  dS )z7Ensures draw ellipse detects any missing required args.rs   r   N)rD   rk   assertRaises	TypeErrorrV   r   rn   r   r=   r   r   r   test_ellipse__args_missing     

"z+DrawEllipseMixin.test_ellipse__args_missingc              	   C   s|   t dt dt dddd}dD ](}t|}|| | t | jd	i |}W d   n1 s6w   Y  qdS )
z9Ensures draw ellipse detects any missing required kwargs.r"   ri   r   r   rp   ri   r   r,   r5   r   Nr   )	rD   rk   r   rE   dictpopr   r   rV   rn   r   nameinvalid_kwargsr=   r   r   r   test_ellipse__kwargs_missing$  s   

z-DrawEllipseMixin.test_ellipse__kwargs_missingc                 C   s  t d}t d}t dd}| t | |||d}W d   n1 s(w   Y  | t | ||dd}W d   n1 sEw   Y  | t | |d|d	}W d   n1 sbw   Y  | t | |||d
}W d   dS 1 sw   Y  dS )z/Ensures draw ellipse detects invalid arg types.rp   bluers   1Nr"   ri   rd   rz      r"   ffffff@r   ri   rD   rk   r   rE   r   r   rV   rn   r   r5   r,   r=   r   r   r   test_ellipse__arg_invalid_types4  s   

"z0DrawEllipseMixin.test_ellipse__arg_invalid_typesc              	   C   s   t d}t d}t dd}t j||dd|d|dd||ddd|||d	dg}|D ]}| t | jdi |}W d
   n1 sGw   Y  q-d
S )z1Ensures draw ellipse detects invalid kwarg types.rc   r   r   r"   rs   r"   r   r   r   r   r   皙?Nr   r   rn   r   r5   r,   r   r   r=   r   r   r   !test_ellipse__kwarg_invalid_typesJ  s4   

z2DrawEllipseMixin.test_ellipse__kwarg_invalid_typesc              	   C   s   t d}t d}t dd}|||ddd|||ddg}|D ]}| t | jd	i |}W d   n1 s;w   Y  q!dS )
z1Ensures draw ellipse detects invalid kwarg names.rv   cyanr   rp   r"   )r   r5   r,   r#   invalidr   r5   r,   r   Nr   r   r   r   r   r    test_ellipse__kwarg_invalid_namei  s"   

z1DrawEllipseMixin.test_ellipse__kwarg_invalid_namec                 C      t d}d}t dd}d}||||d}dD ]G}|| d|kr-| j|fi |}n+d|kr<| j||fi |}nd	|krL| j|||fi |}n| j||||fi |}| |t j qd
S )z9Ensures draw ellipse accepts a combination of args/kwargsrd   r"      r   r   r   r   r   r   r   r   r5   r,   N)rD   rk   rE   r   rV   rl   rn   r   r5   r,   r#   r   r   r=   r   r   r   test_ellipse__args_and_kwargs}  s    

z.DrawEllipseMixin.test_ellipse__args_and_kwargsc           	      C      d}t d}t d}d}||t |ddd}dD ]+}|| ||d	< |d
kr,|n|}| jdi |}| ||| | |t j qdS )z4Ensures draw ellipse accepts different width values.rs   whiterd   rz   rf   r      r   rh   Nr   ir.   r   r"   rf   i  r#   r   r   	rD   r   rk   rE   fillrV   rw   r   rl   	rn   r1   surface_colorr   r5   r   r#   expected_colorr=   r   r   r    test_ellipse__valid_width_values  "   



z1DrawEllipseMixin.test_ellipse__valid_width_valuesc           	      C   s   d}t d}t d}t d}||ddd}t |d|d	f|d |d
 d
d
ff}|D ]#}|| ||d< | jdi |}| ||| | |t j q-dS )z4Ensures draw ellipse accepts different rect formats.rs   r   blackry   Nr   r   r"   rd   r   r"   r,   r   r   	rn   r1   r   r   r   r   rectsr,   r=   r   r   r    test_ellipse__valid_rect_formats  s   


&
z1DrawEllipseMixin.test_ellipse__valid_rect_formatsc           
      C   s   d}t d}t d}t d}|dt |ddd}d	d
|||f}|D ]0}|| ||d< t|tr=||}n|}| j	di |}	| 
||| | |	t j q'dS )z5Ensures draw ellipse accepts different color formats.rs   r   r   r   Nr   r   r   r   r   r   r   r   r   r   r5   r   )rD   r   rk   rE   map_rgbr   
isinstanceint	unmap_rgbrV   rw   r   rl   )
rn   r1   green_colorr   r   r   redsr5   r   r=   r   r   r   !test_ellipse__valid_color_formats  s0   





z2DrawEllipseMixin.test_ellipse__valid_color_formatsc              	   C   sx   d}t d}|dt |ddd}d|fD ]#}||d< | t | jd	i |}W d   n1 s4w   Y  qdS )
z=Ensures draw ellipse handles invalid color formats correctly.rs   rz   rd   Nrp   r"   r   r   r5   r   )rD   rk   rE   r   r   rV   rn   r1   r   r   r   r=   r   r   r   #test_ellipse__invalid_color_formats     

z4DrawEllipseMixin.test_ellipse__invalid_color_formatsc           
   	      sv   g d}g d}d  fdd} fdd}|D ]\}}dD ]}|||| |D ]\}}	||||||	 q*q qd	S )
zTests ellipses of differing sizes on surfaces of differing sizes.

        Checks if the number of sides touching the border of the surface is
        correct.
        )r)   r   r   rs   )ry   r   rz   rz   r   r   r   )r"         r   c                    sN   t | |f}| dd| |f| t|| |}|D ]	} |v  qdS )z4Test for ellipses with the same size as the surface.r   N)rD   rk   rV   r(   
assertTrue)r#   r%   border_widthr   bordersborderr5   rn   r   r   	same_size  s   z0DrawEllipseMixin.test_ellipse.<locals>.same_sizec              	      sb   t | |f}| ||| d |d f| t|| |} fdd|D d}|d dS )z;Test for ellipses that aren't the same size as the surface.r"   c                    s   g | ]} |v qS r   r   )r   r   )r5   r   r   r         zHDrawEllipseMixin.test_ellipse.<locals>.not_same_size.<locals>.<listcomp>Tri   N)rD   rk   rV   r(   countrw   )r#   r%   r   r9   r:   r   r   Zsides_touchingr   r   r   not_same_size  s   z4DrawEllipseMixin.test_ellipse.<locals>.not_same_sizer   Nr   )
rn   Zleft_topsizesr   r   r#   r%   r   r9   r:   r   r   r   test_ellipse  s   zDrawEllipseMixin.test_ellipsec           
      C   s   d}d}d}t d| }t d| }t||f}| |ddd||f| d}t|D ]}|||fdkr:|d7 }q+t|D ]}	||	|fdkrN|d7 }q?| ||d  dS )z5Test for big ellipse that could overflow in algorithmi  r"   g?r   r   r   r   rz   N)r   rD   rk   rV   r'   r   rw   )
rn   r#   r%   r   Zx_value_testZy_value_testr   Zcolored_pixelsr    r   r   r   r   test_ellipse__big_ellipse  s"   z*DrawEllipseMixin.test_ellipse__big_ellipsec                 C   s~  t d}t d}t d}t dd}| j|_tdt|j d d D ]}|	| | 
|||| |  |j}|j}|j| d }t||d D ]}	| |||	f|| qO| |||d f|| | |||d f|| |j}|j| }|jd }t||d D ]}	| |||	f|| q| |||d f|| | |||d f|| |j}
|j| d }|j}	t|
|d D ]}| |||	f|| q| ||
d |	f|| | ||d |	f|| |j| }
|jd }|j}	t|
|d D ]}| |||	f|| q| ||
d |	f|| | ||d |	f|| |  q'dS )	z1Ensures a thick lined ellipse is drawn correctly.r   r   (   r   r)   )      r"   ri   N)rD   r   rk   rE   get_rectr   r'   rB   rA   r   rV   r;   centerxr:   rw   r   r0   r9   centeryr/   r<   )rn   ellipse_colorr   r   r,   	thicknessr   Zy_startZy_endr    Zx_startZx_endr   r   r   test_ellipse__thick_line*  sN   








z)DrawEllipseMixin.test_ellipse__thick_linec           
      C   s   d}d}t |d |f}t dd||}tdddD ]_}|d | |d|| t|D ]K}d}d	}t|d D ]%}	|sJ||	|ft dksX|r_||	|ft dkr_| }|d7 }q:||k sl||| d krs| |d
 q.| |d q.qd S )NP   F   r"   r   %   r   BLACKREDFri   rz   )	rD   rk   rE   r'   r   rV   r   r   rw   )
rn   r#   r%   r   r,   r   r    Znumber_of_changesZdrawn_pixelr   r   r   r   test_ellipse__no_holesn  s2   
z'DrawEllipseMixin.test_ellipse__no_holesc           	      C   sZ  t d}t d}t d}t dd}| j|_t|j d d }t||d D ]}|	| | 
|||| |  t|j|jD ]}| ||j|f| qEt|j|jD ]}| |||jf| q[| ||j|jd f| | ||j|jd f| | ||jd |jf| | ||jd |jf| |  q+d	S )
zCEnsures an ellipse with max width (and greater) is drawn correctly.r   r   r   r)   )r      r"   ri   rd   N)rD   r   rk   rE   r   r   rB   rA   r'   r   rV   r;   r:   r0   rw   r   r   r9   r/   r   r<   )	rn   r   r   r   r,   Zmax_thicknessr   r    r   r   r   r   test_ellipse__max_width  s8   




z(DrawEllipseMixin.test_ellipse__max_widthc              	      sp   |  \ }|   fddt|D D ]}||r|}n|}| |||d| d|  q|  d S )Nc                 3   s&    | ]}t  D ]}||fV  qqd S Nr&   )r   r    r   surf_wr   r   	<genexpr>     $ z@DrawEllipseMixin._check_1_pixel_sized_ellipse.<locals>.<genexpr>zcollide_rect=z, pos=)r*   r;   r'   Zcollidepointrw   r   r<   )rn   r   collide_rectr   r   surf_hr1   r   r   r   r   _check_1_pixel_sized_ellipse  s   
z-DrawEllipseMixin._check_1_pixel_sized_ellipsec                 C   s6  t d}t d}d\}}t ||f}t dd}| }d}|}	|}
|d }|d }tdd	D ]f}||_||_|d
  }|d  }||d  }||f||f||f||f||
f||f||f||f||f||
f|	|f|	|f|	|f|	|f|	|
ff}|D ]}|| ||_||_| 	||| | 
|||| q{q2dS )zEnsures an ellipse with a width of 1 is drawn correctly.

        An ellipse with a width of 1 pixel is a vertical line.
        r   r   rf   r   r)   r   r.   ri      rf   r"   N)rD   r   rk   rE   copyr'   r|   r   r
   rV   r   )rn   r   r   r   r   r   r,   r   off_left	off_right
off_bottomcenter_xcenter_yZ	ellipse_hoff_topZhalf_off_topZhalf_off_bottom	positionsrect_posr   r   r   test_ellipse__1_pixel_width  V   




z,DrawEllipseMixin.test_ellipse__1_pixel_widthc           	      C   s   t d}t d}d\}}t ||f}t dd|d f}dd|d d	f|d d	f|d	ff}|D ]}|| ||_| ||| | |||| q2d
S )zEnsures an ellipse with a width of 1 is drawn correctly
        when spanning the height of the surface.

        An ellipse with a width of 1 pixel is a vertical line.
        r   r   r   r)   r"   ri   r@   r   r.   r.   NrD   r   rk   rE   r   r
   rV   r   	rn   r   r   r   r   r   r,   r  r	  r   r   r   ,test_ellipse__1_pixel_width_spanning_surface  &   




z=DrawEllipseMixin.test_ellipse__1_pixel_width_spanning_surfacec                 C   s6  t d}t d}d\}}t ||f}t dd}| }|}d}	|}
|d }|d }tdd	D ]f}||_||_|d
  }|d  }||d  }||	f||	f||	f||	f||	f||f||f||f||f||f||
f||
f||
f||
f||
ff}|D ]}|| ||_||_| 	||| | 
|||| q{q2dS )zEnsures an ellipse with a height of 1 is drawn correctly.

        An ellipse with a height of 1 pixel is a horizontal line.
        r   r   r   rf   r)   r   r.   ri   r   rf   r"   N)rD   r   rk   rE   r  r'   r{   r   r
   rV   r   )rn   r   r   r   r   r   r,   r   r  r  r  r  r  Z	ellipse_wr  Zhalf_off_leftZhalf_off_rightr  r	  r   r   r   test_ellipse__1_pixel_height'  r  z-DrawEllipseMixin.test_ellipse__1_pixel_heightc           	      C   s   t d}t d}d\}}t ||f}t d|d df}ddd	|d fd	|d fd	|ff}|D ]}|| ||_| ||| | |||| q2d
S )zEnsures an ellipse with a height of 1 is drawn correctly
        when spanning the width of the surface.

        An ellipse with a height of 1 pixel is a horizontal line.
        r   r   r  r)   ri   r"   r@   r.   r   r.   Nr  r  r   r   r   -test_ellipse__1_pixel_height_spanning_surfaced  r  z>DrawEllipseMixin.test_ellipse__1_pixel_height_spanning_surfacec                 C   sD  t d}t d}d\}}t ||f}t dd}d}|}d}	|}
d}|d }d}|d }|d	 }|d	 }||	f||f||f||f||
f||	f||f||f||f||
f||	f||f||f||f||
f||	f||f||f||f||
f||	f||f||f||f||
ff}|D ]}|| ||_| ||| | |||| qd
S )zEnsures an ellipse with a width and height of 1 is drawn correctly.

        An ellipse with a width and height of 1 pixel is a single pixel.
        r   r   rf   rf   r)   rs   r.   r   r"   ri   Nr  )rn   r   r   r   r   r   r,   r  r  r  r  Z	left_edgeZ
right_edgeZtop_edgeZbottom_edger  r  r  r	  r   r   r   &test_ellipse__1_pixel_width_and_height  sb   


z7DrawEllipseMixin.test_ellipse__1_pixel_width_and_heightc              
   C   s  t d}t d}d }}d }}||f||ff}t ddd}| }	|	|d d	 |d d	 }
t|	t|
 D ]C}tD ]>}|D ]9\}}t d
||f}t||| dd	ddt	||fD ]}|
| | ||||}t|||j}| || q_qCq?q;dS )zEnsures draw ellipse returns the correct bounding rect.

        Tests ellipses on and off the surface and a range of width/thickness
        values.
        r   r   r      r   r   r       ri   r"   r)   rd   N)rD   r   rk   r   inflater-   RECT_POSITION_ATTRIBUTESrE   setattrrB   r   rV   rG   r
   rw   )rn   r   rF   	min_width
min_height	max_width
max_heightr   r   	surf_rectbig_rectr1   attrr#   r%   Zellipse_rectr   bounding_rectexpected_rectr   r   r   test_ellipse__bounding_rect  s<   


z,DrawEllipseMixin.test_ellipse__bounding_rectc                      d } t d}t d}t | f}|| t dd}| j|_| }dD ]_}t|D ]X}||_|	d || | 
|||| t|||}	|| |	| | 
|||| |   fdd	t|D D ]}
|
|	v ry|}n|}| ||
||
 qp|  q2q,dS )
zuEnsures draw ellipse respects a surface's clip area.

        Tests drawing the ellipse filled and unfilled.
        r   r   r   r)      r)  r   Nc                 3   &    | ]}t  D ]}||fV  qqd S r   r&   r3   surfhr   r   r     r   z>DrawEllipseMixin.test_ellipse__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r  r-   set_cliprV   r?   r;   r'   rw   r   r<   )rn   surfwr   r   r   	clip_rectpos_rectr#   r   expected_ptsptr   r   r+  r   test_ellipse__surface_clip  6   







z+DrawEllipseMixin.test_ellipse__surface_clipN)!rI   rJ   rK   rL   ro   rt   rx   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  r  r  r  r&  r3  r   r   r   r   rb      s>    	!)D*= = @+rb   c                   @      e Zd ZdZdS )DrawEllipseTestzTest draw module function ellipse.

    This class inherits the general tests from DrawEllipseMixin. It is also
    the class to add any draw.ellipse specific tests to.
    NrI   rJ   rK   rL   r   r   r   r   r6        r6  c                   @   s,   e Zd ZdZdZedd Zedd ZdS )BaseLineMixinzMixin base for drawing various lines.

    This class contains general helper methods and setup for testing the
    different types of lines.
    )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   r   r   r   c                  C   sR   g } dD ]"}dD ]}dt fD ]}tj|||}| | | |  qqq| S )N))1   r;  rg   rg   )      r   r  r   )r   rD   displayset_modeappendZconvert_alpha)ZsurfacesrA   depthflagsr   r   r   r   _create_surfacesG  s   
zBaseLineMixin._create_surfacesc                 c   s>    t | D ]}|| j| jfv rq| j|fV  || jfV  qd S r   )r-   r   r   )r,   r2  r   r   r   _rect_linesS  s   zBaseLineMixin._rect_linesN)rI   rJ   rK   rL   COLORSrO   rD  rE  r   r   r   r   r9  5  s    
r9  c                   @      e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0S )1	LineMixinznMixin test for drawing a single line.

    This class contains all the general single line drawing tests.
    c                 C   *   |  tddddd}| |tj dS )z+Ensures draw line accepts the correct args.rc   re   r)   rs   r"   NrZ   rD   rk   rl   rE   rm   r   r   r   test_line__argsh     zLineMixin.test_line__argsc                 C   (   |  tdddd}| |tj dS )z3Ensures draw line accepts the args without a width.rp   r   r   r   rg   r)   NrJ  rm   r   r   r   test_line__args_without_widthp     z'LineMixin.test_line__args_without_widthc                 C   sf   t d}t d}d}d}||||dd||||dg}|D ]}| jd	i |}| |t j qdS )
z[Ensures draw line accepts the correct kwargs
        with and without a width arg.
        ry   r   rs   rp   r"   r   r5   	start_posend_posr#   r   r5   rR  rS  Nr   )rD   rk   r   rZ   rl   rE   rn   r   r5   rR  rS  r   r   r=   r   r   r   test_line__kwargsx  s(   

zLineMixin.test_line__kwargsc                 C   ,   | j ddddtdd}| |tj dS )z3Ensures draw line's kwargs are not order dependent.r   r   ri   rf   r   r   rh   )rR  rS  r#   r5   r   NrJ  rm   r   r   r   #test_line__kwargs_order_independent     z-LineMixin.test_line__kwargs_order_independentc                 C      t d}t d}| t | ||d}W d   n1 s!w   Y  | t | ||}W d   n1 s<w   Y  | t | |}W d   n1 sVw   Y  | t |  }W d   dS 1 spw   Y  dS )z4Ensures draw line detects any missing required args.rs   r   r)   NrD   rk   r   r   r   rZ   rn   r   r5   r=   r   r   r   test_line__args_missing     


"z!LineMixin.test_line__args_missingc              	   C   sv   t dt ddddd}dD ](}t|}|| | t | jd	i |}W d   n1 s3w   Y  qdS )
z6Ensures draw line detects any missing required kwargs.rh   r   r   rp   r"   rQ  rS  rR  r5   r   Nr   )rD   rk   r   r   r   r   r   rZ   r   r   r   r   test_line__kwargs_missing     
z#LineMixin.test_line__kwargs_missingc                 C   sF  t d}t d}d}d}| t | ||||d}W d   n1 s'w   Y  | t | |||d}W d   n1 sDw   Y  | t | ||d|}W d   n1 saw   Y  | t | |d	||}W d   n1 s~w   Y  | t | d
|||}W d   dS 1 sw   Y  dS )z,Ensures draw line detects invalid arg types.rp   r   r   r   r   Nr   r!   r   r"   ri   rd   rz   r\  rn   r   r5   rR  rS  r=   r   r   r   test_line__arg_invalid_types  s&   

"z&LineMixin.test_line__arg_invalid_typesc           	   
   C   s   t d}t d}d}d}d}t j||||d|d|||d||d||d|||d	|d||||d
dg}|D ]}| t | jdi |}W d   n1 sRw   Y  q8dS )z.Ensures draw line detects invalid kwarg types.rc   r   r   ri   r   r"   rQ  r   r   r   333333?Nr   r\  )	rn   r   r5   rR  rS  r#   r   r   r=   r   r   r   test_line__kwarg_invalid_types  sT   

&z(LineMixin.test_line__kwarg_invalid_typesc              	   C   s   t d}t d}d}d}||||ddd||||ddg}|D ]}| t | jd	i |}W d   n1 s;w   Y  q!dS )
z.Ensures draw line detects invalid kwarg names.rv   r   rs   rf  r"   )r   r5   rR  rS  r#   r   r   r5   rR  rS  r   Nr   r\  rU  r   r   r   test_line__kwarg_invalid_name  0   

	z'LineMixin.test_line__kwarg_invalid_namec           	      C      t d}d}d}d}d}|||||d}dD ]Y}|| d|kr,| j|fi |}n=d|kr;| j||fi |}n.d	|krK| j|||fi |}nd
|kr\| j||||fi |}n| j|||||fi |}| |t j qdS )z6Ensures draw line accepts a combination of args/kwargsrh   r   r   r   r   rQ  r   r5   rR  rS  N)rD   rk   r   rZ   rl   rE   )	rn   r   r5   rR  rS  r#   r   r   r=   r   r   r   test_line__args_and_kwargs+  s@   


z$LineMixin.test_line__args_and_kwargsc           	      C   s   t d}t d}t d}d}|||ddd}dD ]+}|| ||d	< |d
kr,|n|}| jdi |}| ||| | |t j qdS )z1Ensures draw line accepts different width values.r   r   r   r   rp   NrQ  ir   r.   r   r"   rf   d   r#   r   r   )	rD   r   rk   r   rZ   rw   r   rl   rE   	rn   
line_colorr   r   r1   r   r#   r   r=   r   r   r   test_line__valid_width_valuesN  s$   



z'LineMixin.test_line__valid_width_valuesc           
      C   s   t d}t d}t d}||dddd}d\}}||f|d	 |f||d	 f|d	 |d	 ffD ]/}tttfD ]'}|| |||d
< | jdi |}	| |	||f| | 
|	t j q8q1dS )z6Ensures draw line accepts different start_pos formats.r   r   ry   Nrp   ri   rQ  r   皙?rR  r   rD   r   rk   tuplelistr   r   rZ   rw   r   rl   rE   )
rn   r   r   r   r   r   r    rR  seq_typer=   r   r   r   "test_line__valid_start_pos_formatsf  &   


0
z,LineMixin.test_line__valid_start_pos_formatsc           
      C   s   t d}t d}t d}||dddd}d\}}||f|d	 |f||d	 f|d	 |d	 ffD ]/}tttfD ]'}|| |||d
< | jdi |}	| |	||f| | 
|	t j q8q1dS )z4Ensures draw line accepts different end_pos formats.r   r   ry   r   Nri   rQ  rp   g?rS  r   rt  )
rn   r   r   r   r   r   r    rS  rw  r=   r   r   r    test_line__valid_end_pos_formats  ry  z*LineMixin.test_line__valid_end_pos_formatsc              	   C   s   t dt ddddd}ddd	d
dhd
dif}|D ]#}||d< | t | jdi |}W d   n1 s9w   Y  qdS )z>Ensures draw line handles invalid start_pos formats correctly.ry   r   Nrp   r"   rQ  ri   ri   r"   r   ri   r   ri   rR  r   r\  rn   r   Zstart_pos_fmtsrR  r=   r   r   r   $test_line__invalid_start_pos_formats  &   	z.LineMixin.test_line__invalid_start_pos_formatsc              	   C   s   t dt ddddd}ddd	d
dhd
dif}|D ]#}||d< | t | jdi |}W d   n1 s9w   Y  qdS )z<Ensures draw line handles invalid end_pos formats correctly.ry   r   rp   Nr"   rQ  r{  r|  r}  ri   rS  r   r\  rn   r   Zend_pos_fmtsrS  r=   r   r   r   "test_line__invalid_end_pos_formats  r  z,LineMixin.test_line__invalid_end_pos_formatsc           
      C   s   t d}t d}t d}d}|d|ddd}d	d
|||f}|D ]0}|| ||d< t|tr:||}n|}| jdi |}	| 	|
|| | |	t j q$dS )z2Ensures draw line accepts different color formats.r   r   r   rs   Nr   rd   rQ  r   r   r5   r   )rD   r   rk   r   r   r   r   r   rZ   rw   r   rl   rE   
rn   r   r   r   r1   r   greensr5   r   r=   r   r   r   test_line__valid_color_formats  s2   




z(LineMixin.test_line__valid_color_formatsc              	   C   j   t dddddd}d| fD ]#}||d< | t | jd	i |}W d   n1 s-w   Y  qdS )
z:Ensures draw line handles invalid color formats correctly.r   Nrs   r   r"   rQ  r   r5   r   )rD   rk   r   r   rZ   rn   r   r   r=   r   r   r    test_line__invalid_color_formats     z*LineMixin.test_line__invalid_color_formatsc                 C   L   d}|   D ]}| jD ]}| |||d | |||d|  qqdS )z-Tests if the line drawn is the correct color.r)   r   pos=NrD  rF  rZ   rw   r   rn   r1   r   r   r   r   r   test_line__color     
zLineMixin.test_line__colorc              	      sz   d dd|   D ]0}| jD ]*}| || ffd  fdddD D ]}| |||d|  q)qq
dS )z6Ensures a thick line is drawn using the correct color.r   rf   c                 3   s*    | ]} fD ]	}|| fV  qqd S r   r   )r   ir   Zfrom_xZto_xr    r   r   r     s   ( z<LineMixin.test_line__color_with_thickness.<locals>.<genexpr>)r   ri   r  Nr  )rn   r   r   r1   r   r  r   test_line__color_with_thickness  s   
z)LineMixin.test_line__color_with_thicknessc                 C   f   d}|   D ]*}| }| ||d|d df t|D ]}|df}| |||d|  qqdS )z*Tests if the line drawn contains any gaps.r:  r)   r"   r   r  NrD  r7   rZ   r'   rw   r   rn   r   r   r#   r   r1   r   r   r   test_line__gaps  s   zLineMixin.test_line__gapsc           
   	   C   s   d}d}|   D ]E}| d }|d }|d }| ||d|d| f| t|d D ]!}tddD ]}|||d d  f}	| ||	|d|	  q2q+qd	S )
z/Ensures a thick line is drawn without any gaps.r:  r   r"   r   r   rd   r=  ri   r  Nr  )
rn   r   r   r   r#   r|   r{   r   r    r1   r   r   r   test_line__gaps_with_thickness  s   z(LineMixin.test_line__gaps_with_thicknessc                 C   s  t | tr
| d td}td}d }}td||f}|d |d f|d |d ffD ]U}t|dd}| }t|D ]C}	|	|_	t
d	dD ]8}
| |D ]0\}}|| | |||||
}d|
k rot|||}nt|d}| ||d
||||
 qRqKqAq0dS )zEnsures draw line returns the correct bounding rect.

        Tests lines with endpoints on and off the surface and a range of
        width/thickness values.
        z1bounding rects not supported in draw_py.draw_liner   r   r   r)   r   r   r  r.   z'start={}, end={}, size={}, thickness={}N)r   ra   ZskipTestrD   r   rE   rk   r   r-   r   r'   rE  r   rZ   rG   rw   format)rn   rq  rF   r#   r%   helper_rectrA   r   r!  r1   r   startendr$  r%  r   r   r   test_line__bounding_rect*  sB   



$

z"LineMixin.test_line__bounding_rectc              	      s(  d } t d}t d}t | f}|| t dd}| j|_| }dD ]e}t|D ]^}||_|	d || | 
|||j|j| t|||}	|| |	| | 
|||j|j| |   fdd	t|D D ]}
|
|	v r|}n|}| ||
||
 qv|  q2q,dS )
z1Ensures draw line respects a surface's clip area.r   r   r   r)   r(  r   Nc                 3   r*  r   r&   r3   r+  r   r   r     r   z4LineMixin.test_line__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r  r-   r-  rZ   r   r   r?   r;   r'   rw   r   r<   )rn   r.  rq  r   r   r/  r0  r   r   r1  r2  r   r   r+  r   test_line__surface_clip_  s>   







z!LineMixin.test_line__surface_clipN)rI   rJ   rK   rL   rK  rO  rV  rY  r^  ra  re  rh  rj  rm  rr  rx  rz  r  r  r  r  r  r  r  r  r  r  r   r   r   r   rH  b  s2    1#"	5rH  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	DrawLineTestzTest draw module function line.

    This class inherits the general tests from LineMixin. It is also the class
    to add any draw.line specific tests to.
    c              	   C      dD ]O}t dd|}|t ddd | |t dddddd | |djdd	 |t ddd | |t dddddd | |djdd
 qdS ztest color component order)r   r  r   rd   r   r   r   r   r"   rs   zthere should be red herezthere should be blue hereN)	rD   rk   r   r   rZ   assertGreaterr   rbrn   rB  r   r   r   r   test_line_endianness     z!DrawLineTest.test_line_endiannessc                 C   s  d| _ t| j tj| _d| _t| j| jdd}| |j	dd t
|D ]}| | j|| j q&t
|D ]}| | j|| j q9d}d}||f}| j d	 | |d
 f}|d	 | j d
 | f}|d	 |d
 f}|d	 | |d
 f}	|d	 |d	 d f}
||f||f||f||f||f||f||f||f||	f|	|f||
f|
|f||fg}|D ]+\}}| d| }|d	 |d	 kr|}|}n|}|}| jd t| jd|||}d	 }}t|d	 |d	  t|d
 |d
  krd
}nd
}t|D ]8}|d	 ||  |d
 ||  f}| | j|d| |d	 ||  |d
 ||  f}| | j|d| q|d	 d
 |d
 f}| | j|d| |d	 ||  |d
 ||  f}| | j|d| |d	 ||  |d
 ||  f}| | j|d| |d	 |d	 k r|d	 }n|d	 }|d
 |d
 k r|d
 }n|d
 }t|d	 |d	  d
 ||d
   }t|d
 |d
  d
 ||d
   }|d| 7 }| |||||f| qd S )Ni@     r"   r   r      r   )r  r      z3end point arg should be (or at least was) inclusiveri   r   r   r"   z - r   r:  z, )	surf_sizerD   rk   r   surfr5   r   rY   rw   r/   r   rect_area_ptsr   rect_outer_boundsassertNotEqualr   absr'   )rn   drawnr2  
line_widthoffsetar  cdefr[   p1p2msgZplowZphighZrecZxincZyincr  prxZryr{   r|   r   r   r   	test_line  s   (    

$$zDrawLineTest.test_linec                    s\   dd t  ft jfdd fdd}|dd |dd |dd	 d S )
Nr  c                    s(   g d}d t  fdd|D S )N)r   r   r  r  )r   r   r   r   c                    s.   g | ]\}} | | f krd qS r!   r   )r   dxdy)WHITEr  r   r    r   r   r     r6   zTDrawLineTest.test_line_for_gaps.<locals>.white_surrounded_pixels.<locals>.<listcomp>)len)r   r    offsetsr  )r  r   r    r   white_surrounded_pixels  s
   z@DrawLineTest.test_line_for_gaps.<locals>.white_surrounded_pixelsc                    st    d tjd| |d d}tdd D ]}td d D ]}||f|kr6||dk  q!qd S )Nr   r:  r   r   r   r   r   r"   rd   )r   rD   r   rY   r'   r   r   )r  r  r   r   r    r%   rn   r  r  r#   r   r   check_white_line  s   
z9DrawLineTest.test_line_for_gaps.<locals>.check_white_liner<  )   r   )r   x   )      )rD   rk   r   )rn   r  r   r  r   test_line_for_gaps  s   


zDrawLineTest.test_line_for_gapsN)rI   rJ   rK   rL   r  r  r  r   r   r   r   r    s
    ^r  c                   @   rG  )1
LinesMixinz`Mixin test for drawing lines.

    This class contains all the general lines drawing tests.
    c                 C   rI  )z,Ensures draw lines accepts the correct args.rc   re   Fr)   rs   r"   Nr\   rD   rk   rl   rE   rm   r   r   r   test_lines__args4  rL  zLinesMixin.test_lines__argsc                 C   (   |  tdddd}| |tj dS )z4Ensures draw lines accepts the args without a width.rp   rN  Fr  Nr  rm   r   r   r   test_lines__args_without_width<  rP  z)LinesMixin.test_lines__args_without_widthc                 C   sb   t d}t d}d}||d|dd||d|dg}|D ]}| jd	i |}| |t j qdS )
z\Ensures draw lines accepts the correct kwargs
        with and without a width arg.
        ry   r   r)   rs   rp   Fr"   r   r5   closedpointsr#   r   r5   r  r  Nr   )rD   rk   r   r\   rl   rE   rn   r   r5   r  r   r   r=   r   r   r   test_lines__kwargsD  s   

zLinesMixin.test_lines__kwargsc                 C   rW  )z4Ensures draw lines's kwargs are not order dependent.r"   r  ri   rX  rh   )r  r  r#   r5   r   Nr  rm   r   r   r   $test_lines__kwargs_order_independent[  rZ  z/LinesMixin.test_lines__kwargs_order_independentc                 C   r[  )z5Ensures draw lines detects any missing required args.rs   r   r   NrD   rk   r   r   r   r\   r]  r   r   r   test_lines__args_missingg  r_  z#LinesMixin.test_lines__args_missingc              	   C   sv   t dt ddddd}dD ](}t|}|| | t | jdi |}W d   n1 s3w   Y  qdS )	z7Ensures draw lines detects any missing required kwargs.rh   r   r"   rp   rs   r  r  r  r5   r   Nr   )rD   rk   r   r   r   r   r   r\   r   r   r   r   test_lines__kwargs_missingx  rb  z%LinesMixin.test_lines__kwargs_missingc                 C   H  t d}t d}d}d}| t | ||||d}W d   n1 s'w   Y  | t | |||d}W d   n1 sDw   Y  | t | ||t |}W d   n1 sbw   Y  | t | |d||}W d   n1 sw   Y  | t | d	|||}W d   dS 1 sw   Y  dS )
z-Ensures draw lines detects invalid arg types.rp   r   r   r   r   r   Nr   r   rc  )rD   rk   r   r   r   r\   rH   rn   r   r5   r  r  r=   r   r   r   test_lines__arg_invalid_types  &   

"z(LinesMixin.test_lines__arg_invalid_typesc              	   C   s   t dt ddddd}t jdt dd	d}dD ])}t|}|| ||< | t | jdi |}W d
   n1 s>w   Y  qd
S )z/Ensures draw lines detects invalid kwarg types.rc   r   Fr  r"   r  r   r   rg  Nr   )rD   rk   r   rH   r   r   r   r\   rn   Zvalid_kwargsr   kwargr   r=   r   r   r   test_lines__kwarg_invalid_types  s(   	z*LinesMixin.test_lines__kwarg_invalid_typesc              	   C   s   t d}t d}d}d}||||ddd||||ddg}|D ]}| t | jdi |}W d   n1 s;w   Y  q!dS )	z/Ensures draw lines detects invalid kwarg names.rv   r   r"   r  )r   r5   r  r  r#   r   r   r5   r  r  r   Nr   r  rn   r   r5   r  r  r   r   r=   r   r   r   test_lines__kwarg_invalid_name  rk  z)LinesMixin.test_lines__kwarg_invalid_namec           	      C   rl  )z7Ensures draw lines accepts a combination of args/kwargsrh   r   r   r  r"   r  r   r5   r  r  N)rD   rk   r   r\   rl   rE   )	rn   r   r5   r  r  r#   r   r   r=   r   r   r   test_lines__args_and_kwargs  s8   


z&LinesMixin.test_lines__args_and_kwargsc           	      C   s   t d}t d}t d}d}||d|dfdd}d	D ]+}|| ||d
< |dkr.|n|}| jdi |}| ||| | |t j qdS )z2Ensures draw lines accepts different width values.r   r   r   rs   Fr   Nr  rn  r#   r   r   	rD   r   rk   r   r\   rw   r   rl   rE   rp  r   r   r   test_lines__valid_width_values  s$   



z)LinesMixin.test_lines__valid_width_valuesc                    s   d}t d}t d}||dddd}ttttfttttfttttfttttff}d}ttf}|D ]> |D ]9}|d	 }	 fd
dt|D }
|D ]%}|| ||
|d< | jdi |}| 	|
|	| | |t j qIq6q2dS )z4Ensures draw lines accepts different points formats.r   r   r   FNr"   r  rs   r   rp   r   )rs   )皙@r"    @r  )r"   r  r   c                       g | ]
\}} | |qS r   r   r   r  r2  Z
point_typer   r   r   3      z>LinesMixin.test_lines__valid_points_format.<locals>.<listcomp>r  r   )rD   r   rk   ru  rv  r   	enumerater   r\   rw   r   rl   rE   rn   r   r   r   r   Zpoint_typesZpoint_valuesZ	seq_typesvaluesZ	check_posr  rw  r=   r   r  r   test_lines__valid_points_format  s:   







z*LinesMixin.test_lines__valid_points_formatc              	   C   s   t dt ddddd}ddd	d
ddhfd
dddfd
dhdddf}|D ]#}||d< | t | jdi |}W d   n1 sEw   Y  q'dS )z<Ensures draw lines handles invalid points formats correctly.ry   r   FNr"   r  rs   r{  rs   ri   ri   ri   rs   ri   2rs   ri   rd   rv   r   rz   r"   rz   r  r   r  rn   r   points_fmtsr  r=   r   r   r   "test_lines__invalid_points_formats>  s*   	

z-LinesMixin.test_lines__invalid_points_formatsc              
   C   s   t dt ddddd}g dfD ],}ttfD ]%}|||d< | t | jd	i |}W d   n1 s8w   Y  qqdS )
z;Ensures draw lines handles invalid points values correctly.ry   r   FNr"   r  rs   r  r   )rD   rk   r   ru  rv  r   
ValueErrorr\   rn   r   r  rw  r=   r   r   r   !test_lines__invalid_points_valuesX  s   z,LinesMixin.test_lines__invalid_points_valuesc                 C   s   t d}t d}t d}d}||dddd}d	dd
ddddgdf}ddddg df}|| D ])}|| ||d< |r?|n|}	| jdi |}
| |||	 | |
t j q0dS )z3Ensures draw lines accepts different closed values.r   r   r   r   N)rs   r   rc   r   r"   r  rf   r  @rz   r   T r   r   Fr  r  rn   rq  r   r   r1   r   Ztrue_valuesZfalse_valuesr  r   r=   r   r   r   test_lines__valid_closed_valuesi  s(   



z*LinesMixin.test_lines__valid_closed_valuesc           
      C   s   t d}t d}t d}d}|dd|dfdd	}d
d|||f}|D ]0}|| ||d< t|tr<||}n|}| jdi |}	| 	|
|| | |	t j q&dS )z3Ensures draw lines accepts different color formats.r   r   r   rs   NFr   rd   r  r   r   r5   r   )rD   r   rk   r   r   r   r   r   r\   rw   r   rl   rE   r  r   r   r   test_lines__valid_color_formats  s2   




z*LinesMixin.test_lines__valid_color_formatsc              	   C   r  )
z;Ensures draw lines handles invalid color formats correctly.r   NFrs   r   r"   r  r   r5   r   )rD   rk   r   r   r\   r  r   r   r   !test_lines__invalid_color_formats  r  z,LinesMixin.test_lines__invalid_color_formatsc              	   C   X   |   D ]%}| jD ]}| ||dt| t|D ]\}}| ||d|  qq	qdS )zTests if the lines drawn are the correct color.

        Draws lines around the border of the given surface and checks if all
        borders of the surface only contain the given color.
        Tr  N)rD  rF  r\   r+   r2   rw   rn   r   r   r1   r5   r   r   r   test_lines__color     
zLinesMixin.test_lines__colorc                 C   s  d }}|   D ]x}| d }| d }||f||f||f||ff}| jD ]X}| ||d|d dD ]J}t||d D ]}	||fD ]}
|	|
| f}| |||d|  qCq=t||d D ]}
||fD ]}	|	| |
f}| |||d|  qgqaq4q'qdS )z6Ensures thick lines are drawn using the correct color.r   Trd   r.   r   r"   r"   r  N)rD  r7   r8   rF  r\   r'   rw   r   )rn   x_lefty_topr   x_righty_bottom	endpointsr   tr   r    r1   r   r   r    test_lines__color_with_thickness  sD   
z+LinesMixin.test_lines__color_with_thicknessc                 C   P   d}|   D ]}| ||dt| t|D ]\}}| ||d|  qqdS )zTests if the lines drawn contain any gaps.

        Draws lines around the border of the given surface and checks if
        all borders of the surface contain any gaps.
        r:  Tr  N)rD  r\   r+   r2   rw   rn   r   r   r1   r5   r   r   r   test_lines__gaps  s   zLinesMixin.test_lines__gapsc              	   C   s(  d}d }}|   D ]}| d d }|d }|| }|| }||f||f||ff}	| ||d|	d t||d D ]3}
dD ].}|
|| f}| |||d|  |
|| |
d d  f}| |||d|  q?q;t||d D ]}dD ]}|| |f}| |||d|  qzqvq
d	S )
z/Ensures thick lines are drawn without any gaps.r:  r   r)  Trd   r"   r  r  N)rD  r7   r\   r'   rw   r   )rn   r   r  r  r   r|   r{   r  r  r   r   r!  r1   r    r   r   r   test_lines__gaps_with_thickness  s.   z*LinesMixin.test_lines__gaps_with_thicknessc                 C   s   t d}t d}d }}t d||f}|d |d f|d |d ffD ]U}t |dd}| }t|D ]C}	|	|_|j|j|j	f}
|
d }	t
ddD ],}d	D ]'}|| | ||||
|}d|k rlt|||	}nt |	d}| || qQqMq7q&d
S )zEnsures draw lines returns the correct bounding rect.

        Tests lines with endpoints on and off the surface and a range of
        width/thickness values.
        r   r   r   r)   r   r   r  r.   TFN)rD   r   rE   rk   r   r-   r   r   r   r   r'   r   r\   rG   rw   )rn   rq  rF   r#   r%   r0  rA   r   r!  r1   r>   r   r  r$  r%  r   r   r   test_lines__bounding_rect	  s6   

$

z$LinesMixin.test_lines__bounding_rectc              
      s:  d } t d}t d}t | f}|| t dd}| j|_| }t|D ]l}||_|j	|j|j
f}dD ]\}	dD ]W}
|d || | |||	||
 t|||}|| || | |||	||
 |   fd	d
t|D D ]}||v r|}n|}| |||| q~|  qAq=q.dS )z2Ensures draw lines respects a surface's clip area.r   r   r   r)   r(  r'  r   Nc                 3   r*  r   r&   r3   r+  r   r   r   ]	  r   z6LinesMixin.test_lines__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r  r-   r   r   r-  r\   r?   r;   r'   rw   r   r<   )rn   r.  rq  r   r   r/  r0  r   r>   r  r   r1  r2  r   r   r+  r   test_lines__surface_clip7	  s<   







z#LinesMixin.test_lines__surface_clipN)rI   rJ   rK   rL   r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r"  r%  r&  r(  r)  r   r   r   r   r  .  s2    !,"!/r  c                   @   r5  )DrawLinesTestzTest draw module function lines.

    This class inherits the general tests from LinesMixin. It is also the class
    to add any draw.lines specific tests to.
    Nr7  r   r   r   r   r*  r	  r8  r*  c                   @      e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,S )-AALineMixinzrMixin test for drawing a single aaline.

    This class contains all the general single aaline drawing tests.
    c                 C   rI  )z-Ensures draw aaline accepts the correct args.rc   re   r)   rs   r"   Nr^   rD   rk   rl   rE   rm   r   r   r   test_aaline__args	  rL  zAALineMixin.test_aaline__argsc                 C   rM  )z5Ensures draw aaline accepts the args without a blend.rp   rN  r)   Nr-  rm   r   r   r   test_aaline__args_without_blend	  rP  z+AALineMixin.test_aaline__args_without_blendc                 C   sz   t jdd-}t d | tddddd | t|d | t	|d	 j
t W d
   d
S 1 s6w   Y  d
S );From pygame 2, blend=False should raise DeprecationWarning.Trecordalwaysrp   rN  r)   Fr"   r.   N)warningscatch_warningssimplefilterr^   rD   rk   rw   r  r   
issubclasscategoryDeprecationWarningrn   r{   r   r   r   test_aaline__blend_warning	     
"z&AALineMixin.test_aaline__blend_warningc                 C   sX   t d}t d}d}d}||||dg}|D ]}| jdi |}| |t j qdS )z.Ensures draw aaline accepts the correct kwargsry   r   rs   rp   rT  Nr   )rD   rk   r   r^   rl   rE   rU  r   r   r   test_aaline__kwargs	  s   

	zAALineMixin.test_aaline__kwargsc                 C   *   | j dddtdd}| |tj dS )z5Ensures draw aaline's kwargs are not order dependent.r   r   rX  rh   )rR  rS  r5   r   Nr-  rm   r   r   r   %test_aaline__kwargs_order_independent	     z1AALineMixin.test_aaline__kwargs_order_independentc                 C   r[  )z6Ensures draw aaline detects any missing required args.rs   r   r)   NrD   rk   r   r   r   r^   r]  r   r   r   test_aaline__args_missing	  r_  z%AALineMixin.test_aaline__args_missingc              	   C   t   t dt dddd}dD ](}t|}|| | t | jdi |}W d   n1 s2w   Y  qdS )	z8Ensures draw aaline detects any missing required kwargs.rh   r   r   rp   rT  r`  Nr   )rD   rk   r   r   r   r   r   r^   r   r   r   r   test_aaline__kwargs_missing	     
z'AALineMixin.test_aaline__kwargs_missingc                 C   s
  t d}t d}d}d}| t | |||d}W d   n1 s&w   Y  | t | ||d|}W d   n1 sCw   Y  | t | |d||}W d   n1 s`w   Y  | t | d	|||}W d   dS 1 s~w   Y  dS )
z.Ensures draw aaline detects invalid arg types.rp   r   r   r   r   Nr!   zinvalid-colorrc  )rD   rk   r   r   r   r^   r  rd  r   r   r   test_aaline__arg_invalid_types	  s    

"z*AALineMixin.test_aaline__arg_invalid_typesc              	   C      t d}t d}d}d}t j|||d|d||d||d|d|||ddg}|D ]}| t | jd
i |}W d	   n1 sEw   Y  q+d	S )z0Ensures draw aaline detects invalid kwarg types.rc   r   r   rf  rT  r   r   r   Nr   rA  rU  r   r   r    test_aaline__kwarg_invalid_types	  s>   

z,AALineMixin.test_aaline__kwarg_invalid_typesc              	   C   s   t d}t d}d}d}||||dd||||ddg}|D ]}| t | jdi |}W d   n1 s:w   Y  q dS )	z0Ensures draw aaline detects invalid kwarg names.rv   r   rs   rf  r"   ri  Nr   rA  rU  r   r   r   test_aaline__kwarg_invalid_name
  .   

z+AALineMixin.test_aaline__kwarg_invalid_namec                 C      t d}d}d}d}||||d}dD ]X}|| d|kr)| j|fi |}n<d|kr8| j||fi |}n-d|krH| j|||fi |}nd	|krY| j||||fi |}n| j||||fi |}| |t j qd
S )z8Ensures draw aaline accepts a combination of args/kwargsrh   r   r   r   rT  r   r5   rR  rS  N)rD   rk   r   r^   rl   rE   )rn   r   r5   rR  rS  r   r   r=   r   r   r   test_aaline__args_and_kwargs7
  <   

z(AALineMixin.test_aaline__args_and_kwargsc                 C   s   t d}t d}t d}||ddd}d\}}||f|d |f||d f|d |d ff}|D ]@}tttfD ]8}	|| |	||d	< | jdi |}
|||f}t	|D ]\}}| 
|| d
 || qY| |
t j| q9q2dS )z8Ensures draw aaline accepts different start_pos formats.r   r   ry   Nrp   rT  r   g{Gz?rR  r   r   rD   r   rk   ru  rv  r   r   r^   r   r  ZassertGreaterEqualrl   rE   )rn   r   r   r   r   r   r    r  rR  rw  r=   r5   r  	sub_colorr   r   r   $test_aaline__valid_start_pos_formatsX
  *   


,
z0AALineMixin.test_aaline__valid_start_pos_formatsc                 C   s   t d}t d}t d}||ddd}d\}}||f|d |f||d f|d |d ff}|D ]@}tttfD ]8}	|| |	||d	< | jdi |}
|||f}t	|D ]\}}| 
|| d
 || qY| |
t j| q9q2dS )z6Ensures draw aaline accepts different end_pos formats.r   r   ry   r   NrT  rp   g{Gz?rS     r   rN  )rn   r   r   r   r   r   r    r  rS  rw  r=   r5   r  rO  r   r   r   "test_aaline__valid_end_pos_formatst
  rQ  z.AALineMixin.test_aaline__valid_end_pos_formatsc              	   C   s   t dt dddd}dddd	d
hd	d
if}|D ]#}||d< | t | jdi |}W d   n1 s8w   Y  qdS )z@Ensures draw aaline handles invalid start_pos formats correctly.ry   r   Nrp   rT  r{  r|  r}  ri   r"   rR  r   rA  r~  r   r   r   &test_aaline__invalid_start_pos_formats
  $   z2AALineMixin.test_aaline__invalid_start_pos_formatsc              	   C   s   t dt dddd}dddd	d
hd	d
if}|D ]#}||d< | t | jdi |}W d   n1 s8w   Y  qdS )z>Ensures draw aaline handles invalid end_pos formats correctly.ry   r   rp   NrT  r{  r|  r}  ri   r"   rS  r   rA  r  r   r   r   $test_aaline__invalid_end_pos_formats
  rU  z0AALineMixin.test_aaline__invalid_end_pos_formatsc           
      C   s   t d}t d}t d}d}|d|dd}dd	|||f}|D ]0}|| ||d
< t|tr9||}n|}| jdi |}	| 	|
|| | |	t j q#dS )z4Ensures draw aaline accepts different color formats.r   r   r   rs   Nr   rT  r   r   r5   r   )rD   r   rk   r   r   r   r   r   r^   rw   r   rl   rE   r  r   r   r    test_aaline__valid_color_formats
  s0   




z,AALineMixin.test_aaline__valid_color_formatsc              	   C   h   t ddddd}d| fD ]#}||d< | t | jdi |}W d   n1 s,w   Y  qdS )	z<Ensures draw aaline handles invalid color formats correctly.r   Nrs   r   rT  r   r5   r   )rD   rk   r   r   r^   r  r   r   r   "test_aaline__invalid_color_formats
     z.AALineMixin.test_aaline__invalid_color_formatsc                 C   r  )z/Tests if the aaline drawn is the correct color.r)   r   r  N)rD  rF  r^   rw   r   r  r   r   r   test_aaline__color
  r  zAALineMixin.test_aaline__colorc                 C   r  )zHTests if the aaline drawn contains any gaps.

        See: #512
        r:  r)   r"   r   r  N)rD  r7   r^   r'   rw   r   r  r   r   r   test_aaline__gaps
  s   zAALineMixin.test_aaline__gapsc              	   C   s   t d}t d}d }}t d||f}|d |d f|d |d ffD ]:}t |dd}| }t|D ](}	|	|_| |D ]\}
}|| | 	|||
|}t
|||
}| || qAq7q&dS )	z{Ensures draw aaline returns the correct bounding rect.

        Tests lines with endpoints on and off the surface.
        r   r   r   r)   r   r   r  N)rD   r   rE   rk   r   r-   r   rE  r   r^   rG   rw   )rn   rq  rF   r#   r%   r  rA   r   r!  r1   r  r  r$  r%  r   r   r   test_aaline__bounding_rect  s"   

$
z&AALineMixin.test_aaline__bounding_rectc           
         s(  d } t d}t d}t | f}|| t dd}| j|_| }t|D ]c}||_|	d || | 
|||j|j t|||d}|| |	| | 
|||j|j |   fdd	t|D D ]}	|	|v r| ||	||	 qq| ||	||	 qq|  q.dS )
z3Ensures draw aaline respects a surface's clip area.r   r   r   r)   r(  NFc                 3   r*  r   r&   r3   r+  r   r   r   J  r   z8AALineMixin.test_aaline__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r  r-   r-  r^   r   r   r?   r;   r'   r  r   rw   r<   )
rn   r.  aaline_colorr   r   r/  r0  r   r1  r2  r   r+  r   test_aaline__surface_clip&  s0   







z%AALineMixin.test_aaline__surface_clipN)rI   rJ   rK   rL   r.  r/  r;  r=  r?  rB  rD  rF  rH  rI  rL  rP  rS  rT  rV  rW  rY  r[  r\  r]  r_  r   r   r   r   r,  }	  s.    %!!	!r,  c                   @   sD   e Zd ZdZdd Z	dddZdd Zd	d
 Zdd Zdd Z	dS )DrawAALineTestzTest draw module function aaline.

    This class inherits the general tests from AALineMixin. It is also the
    class to add any draw.aaline specific tests to.
    c              	   C   r  r  )	rD   rk   r   r   r^   r  r   r  r  r  r   r   r   test_aaline_endiannessd  r  z%DrawAALineTest.test_aaline_endiannessTc                    sJ   |r
t  ||< ||<  fdd}|||| ||kr#|||| dS dS )z@Draw a line between two points and check colors of check_points.c              	      s    jt| |d  D ]*}||t}j| ||d j|| W d    n1 s1w   Y  qt	jtdd d S )NT)from_ptr2  tor   r   rf   rf   r   )
r^   r   FG_GREENgetBG_REDsubTestrw   r   r   r,   )
from_pointto_pointshouldr2  r5   check_pointsrn   r   r   check_one_directiony  s   z?DrawAALineTest._check_antialiasing.<locals>.check_one_directionNre  )rn   ri  rj  rk  rm  set_endpointsrn  r   rl  r   _check_antialiasingr  s   z"DrawAALineTest._check_antialiasingc                    s   t d_tjtdd dd tddD   fdd	}|d
d
g  |ddg  |dddg |d
dg  |dddg |d
dg  |d
ddg |ddg  |ddd
g dS )z9test very short not anti aliased lines in all directions.r  rd  r   c                 S   $   g | ]}t d dD ]}||fq	qS rd   r=  r&   r   r  jr   r   r   r        $ zCDrawAALineTest.test_short_non_antialiased_lines.<locals>.<listcomp>rd   r=  c                    s"   dd |D } | ||  d S )Nc                 S   s   i | ]}|t qS r   ro  r   r2  r   r   r   
<dictcomp>  s    zbDrawAALineTest.test_short_non_antialiased_lines.<locals>.check_both_directions.<locals>.<dictcomp>rq  )rb  to_ptZother_pointsrk  rl  r   r   check_both_directions  s   zNDrawAALineTest.test_short_non_antialiased_lines.<locals>.check_both_directionsr   rz   r  r   r  r   r  rz   r   rz   r   r   r   r   r   r   )r  r  rz   r   NrD   rk   r   r   r,   rg  r'   )rn   r{  r   rl  r    test_short_non_antialiased_lines  s   z/DrawAALineTest.test_short_non_antialiased_linesc                    s$  t d_tjtdd dd tddD   fdd	}d
}d}d}|dd||d |dd||d |dd||d |dd||d dd tddD  ||||||d}|dd| ||||||d}|dd| ||||||d}|dd | ||||||d}|d!d"| d S )#Nr  rd  r   c                 S   rr  rs  r&   rt  r   r   r   r     rv  z@DrawAALineTest.test_short_line_anti_aliasing.<locals>.<listcomp>rd   r=  c                    s    | ||  d S r   ry  )rb  rz  rk  rl  r   r   r{    s   zKDrawAALineTest.test_short_line_anti_aliasing.<locals>.check_both_directions   r  r      ?   r   r  r  r   ry   r  )r   r   r   r  r  )r   r   r   r  c                 S   rr  )ri   	   r&   rt  r   r   r   r     rv  ri   r  r   r  )r   rd   ry   r   r  rc   r~  r   r  rd   )ry   r   r  r   r   r  r   r}  r  r|  r  )rn   r{  brownreddishgreenishrk  r   rl  r   test_short_line_anti_aliasing  sX   z,DrawAALineTest.test_short_line_anti_aliasingc                    s
  t d| _t| jtdd dd tdD }d d}d	}d
ti}| jdd||dd dti}| jdd||dd  td}| jdd
||dd  t d}| jdd||dd  td}| jdd||dd  |d}| jdd||dd  fddtddD }| jdd||dd  t d}| jdd||dd  |d}| jdd||dd  fdddD }| jdd ||dd  t d!}| jd"d#||dd  t d$}| jd%d&||dd     d'}| jdd(||dd ||||||d)}| jd*d+||dd d,S )-z-Float coordinates should be blended smoothly.r  rd  r   c                 S   "   g | ]}t d D ]}||fqqS r   r&   rt  r   r   r   r        " zGDrawAALineTest.test_anti_aliasing_float_coordinates.<locals>.<listcomp>r   r  r  r  rp   )      ?ri   F)rp  rv   )gQ@g@)r   rp   )r   rp   rh   )      @ri   )rp   r   r   )      ?ri   c                    s    i | ]}d D ]}||f qqS )r   r   r3   r  r   r   rx    s     zGDrawAALineTest.test_anti_aliasing_float_coordinates.<locals>.<dictcomp>ri   )ri   r  )rz   r  r   rp   rv   )ri   r  )r   rp   )ri   r  c                    s&   i | ]}t d dD ]}||f q	qS ri   r   r&   r3   r  r   r   rx  #     & )r  rz   )rs   rp   rc   r  r  )r  r  )r   rp   r   )r  r  )r  r  )r   rp   rh   rc   )rd   r  )r   rp   rh   rc   r   ry   )ri   g      ?)rz   g      
@N)	rD   rk   r   r   r,   rg  r'   re  rq  )rn   rm  r  r  expectedr   r  r   $test_anti_aliasing_float_coordinates  s   
















	

z3DrawAALineTest.test_anti_aliasing_float_coordinatesc                    s   t d| _t| jtdd dd tdD }d}d}d	}d
\}}||||||d}dD ]0\ |d   |d  f}|d   |d  f}	 fdd| D }
| ||	|
| q-dS )z:Ensures antialiasing works correct at a surface's borders.r  rd  r   c                 S   r  )rf   r&   rt  r   r   r   r   J  r  zODrawAALineTest.test_anti_aliasing_at_and_outside_the_border.<locals>.<listcomp>rf   r  r  r  )rc   r~  r  ))r   )rz   r   )r   )r   r  )r   r  )r   r   )r   r  )r  r  )r  r  )r  r  r"   c                    s&   i | ]\\}}}|  | f|qS r   r   )r   r   r    r5   r  r  r   r   rx  h  r  zODrawAALineTest.test_anti_aliasing_at_and_outside_the_border.<locals>.<dictcomp>N)	rD   rk   r   r   r,   rg  r'   itemsrq  )rn   rm  r  r  r  ri  rj  rk  firstsecondr  r   r  r   ,test_anti_aliasing_at_and_outside_the_borderD  s(   	z;DrawAALineTest.test_anti_aliasing_at_and_outside_the_borderN)T)
rI   rJ   rK   rL   ra  rq  r  r  r  r  r   r   r   r   r`  ]  s    
CZr`  c                   @   r+  )-AALinesMixinzdMixin test for drawing aalines.

    This class contains all the general aalines drawing tests.
    c                 C   rI  )z.Ensures draw aalines accepts the correct args.rc   re   Fr  r"   Nr`   rD   rk   rl   rE   rm   r   r   r   test_aalines__argsv  rL  zAALinesMixin.test_aalines__argsc                 C   r  )z6Ensures draw aalines accepts the args without a blend.rp   rN  Fr  Nr  rm   r   r   r    test_aalines__args_without_blend~  rP  z-AALinesMixin.test_aalines__args_without_blendc                 C   sz   t jdd-}t d | tddddd | t|d | t	|d	 j
t W d
   d
S 1 s6w   Y  d
S )r0  Tr1  r3  rp   rN  Fr  r"   r.   N)r4  r5  r6  r`   rD   rk   rw   r  r   r7  r8  r9  r:  r   r   r   test_aalines__blend_warning  r<  z(AALinesMixin.test_aalines__blend_warningc                 C   sT   t d}t d}d}||d|dg}|D ]}| jdi |}| |t j qdS )z0Ensures draw aalines accepts the correct kwargs.ry   r   r  Fr  Nr   )rD   rk   r   r`   rl   rE   r  r   r   r   test_aalines__kwargs  s   

z!AALinesMixin.test_aalines__kwargsc                 C   r>  )z6Ensures draw aalines's kwargs are not order dependent.r"   r  rX  rh   )r  r  r5   r   Nr  rm   r   r   r   &test_aalines__kwargs_order_independent  r@  z3AALinesMixin.test_aalines__kwargs_order_independentc                 C   r[  )z7Ensures draw aalines detects any missing required args.rs   r   r   NrD   rk   r   r   r   r`   r]  r   r   r   test_aalines__args_missing  r_  z'AALinesMixin.test_aalines__args_missingc              	   C   rC  )	z9Ensures draw aalines detects any missing required kwargs.rh   r   r"   r  r  r  Nr   )rD   rk   r   r   r   r   r   r`   r   r   r   r   test_aalines__kwargs_missing  rE  z)AALinesMixin.test_aalines__kwargs_missingc                 C   r  )
z/Ensures draw aalines detects invalid arg types.rp   r   r   r  r   Nr   r   rc  )rD   rk   r   r   r   r`   rH   r  r   r   r   test_aalines__arg_invalid_types  r  z,AALinesMixin.test_aalines__arg_invalid_typesc              	   C   s   t dt dddd}t jdt dd}dD ])}t|}|| ||< | t | jd	i |}W d   n1 s<w   Y  qdS )
z1Ensures draw aalines detects invalid kwarg types.rc   r   Fr  r  r   r   Nr   )rD   rk   r   rH   r   r   r   r`   r  r   r   r   !test_aalines__kwarg_invalid_types  s$   z.AALinesMixin.test_aalines__kwarg_invalid_typesc              	   C   s   t d}t d}d}d}||||dd||||ddg}|D ]}| t | jdi |}W d   n1 s:w   Y  q dS )z1Ensures draw aalines detects invalid kwarg names.rv   r   r"   r  r  Nr   r  r  r   r   r    test_aalines__kwarg_invalid_name  rJ  z-AALinesMixin.test_aalines__kwarg_invalid_namec                 C   rK  )z9Ensures draw aalines accepts a combination of args/kwargsrh   r   r   r  r  r   r5   r  r  N)rD   rk   r   r`   rl   rE   )rn   r   r5   r  r  r   r   r=   r   r   r   test_aalines__args_and_kwargs  rM  z*AALinesMixin.test_aalines__args_and_kwargsc                    s   d}t d}t d}||ddd}ttttfttttfttttfttttff}d}ttf}|D ]> |D ]9}|d }	 fd	d
t|D }
|D ]%}|| ||
|d< | jdi |}| 	|
|	| | |t j qHq5q1dS )z6Ensures draw aalines accepts different points formats.r   r   r   FNr  r  r   c                    r  r   r   r  r  r   r   r   [  r  zBAALinesMixin.test_aalines__valid_points_format.<locals>.<listcomp>r  r   )rD   r   rk   ru  rv  r   r  r   r`   rw   r   rl   rE   r  r   r  r   !test_aalines__valid_points_format;  8   


	



z.AALinesMixin.test_aalines__valid_points_formatc              	   C   s   t dt dddd}dddd	d
dhfd	d
ddfd	dhdddf}|D ]#}||d< | t | jdi |}W d   n1 sDw   Y  q&dS )z>Ensures draw aalines handles invalid points formats correctly.ry   r   FNr  r   r  r  rs   ri   rd   rv   r   r"   rz   r  r  r   r  r  r   r   r   $test_aalines__invalid_points_formatsf  s(   

z1AALinesMixin.test_aalines__invalid_points_formatsc              
   C   s   t dt dddd}g dfD ],}ttfD ]%}|||d< | t | jdi |}W d   n1 s7w   Y  qqdS )	z=Ensures draw aalines handles invalid points values correctly.ry   r   FNr  r
  r  r   )rD   rk   r   ru  rv  r   r  r`   r  r   r   r   #test_aalines__invalid_points_values  s   z0AALinesMixin.test_aalines__invalid_points_valuesc                 C   s   t d}t d}t d}d}||ddd}dd	d
ddddgdf}ddddg df}|| D ])}|| ||d< |r>|n|}	| jdi |}
| |||	 | |
t j q/dS )z5Ensures draw aalines accepts different closed values.r   r   r   r   N)rs   )rz   r"   ry   r  r  r  r"   rf   r  r  r  r   Tr  r   r   Fr  )	rD   r   rk   r   r`   rw   r   rl   rE   r  r   r   r   !test_aalines__valid_closed_values  s&   



z.AALinesMixin.test_aalines__valid_closed_valuesc           
      C   s   t d}t d}t d}d}|dd|dfd}d	d
|||f}|D ]0}|| ||d< t|tr;||}n|}| jdi |}	| 	|
|| | |	t j q%dS )z5Ensures draw aalines accepts different color formats.r   r   r   rs   NFr   r  r   r   r5   r   )rD   r   rk   r   r   r   r   r   r`   rw   r   rl   rE   r  r   r   r   !test_aalines__valid_color_formats  s0   




z.AALinesMixin.test_aalines__valid_color_formatsc              	   C   rX  )	z=Ensures draw aalines handles invalid color formats correctly.r   NFr  r  r   r5   r   )rD   rk   r   r   r`   r  r   r   r   #test_aalines__invalid_color_formats  rZ  z0AALinesMixin.test_aalines__invalid_color_formatsc              	   C   r  )zTests if the aalines drawn are the correct color.

        Draws aalines around the border of the given surface and checks if all
        borders of the surface only contain the given color.
        Tr  N)rD  rF  r`   r+   r2   rw   r  r   r   r   test_aalines__color  r  z AALinesMixin.test_aalines__colorc                 C   r#  )zTests if the aalines drawn contain any gaps.

        Draws aalines around the border of the given surface and checks if
        all borders of the surface contain any gaps.

        See: #512
        r:  Tr  N)rD  r`   r+   r2   rw   r$  r   r   r   test_aalines__gaps  s   zAALinesMixin.test_aalines__gapsc              	   C   s   t d}t d}d }}t d||f}|d |d f|d |d ffD ]A}t |dd}| }t|D ]/}	|	|_|j|j|j	f}
|
d }	dD ]}|
| | ||||
}t|||	}| || qJq7q&d	S )
zEnsures draw aalines returns the correct bounding rect.

        Tests lines with endpoints on and off the surface and blending
        enabled and disabled.
        r   r   r   r)   r   r   r  r'  N)rD   r   rE   rk   r   r-   r   r   r   r   r   r`   rG   rw   )rn   rq  rF   r#   r%   r0  rA   r   r!  r1   r>   r  r$  r%  r   r   r   test_aalines__bounding_rect  s&   

$
z(AALinesMixin.test_aalines__bounding_rectc                    s:  d } t d}t d}t | f}|| t dd}| j|_| }t|D ]l}||_|j	|j|j
f}dD ]\}	|d || | |||	| t|||d}
|| || | |||	| |   fd	d
t|D D ]}||
v r| |||| qy| |||| qy|  q=q.dS )z4Ensures draw aalines respects a surface's clip area.r   r   r   r)   r(  r'  NFc                 3   r*  r   r&   r3   r+  r   r   r   A  r   z:AALinesMixin.test_aalines__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r  r-   r   r   r-  r`   r?   r;   r'   r  r   rw   r<   )rn   r.  r^  r   r   r/  r0  r   r>   r  r1  r2  r   r+  r   test_aalines__surface_clip  s:   







z'AALinesMixin.test_aalines__surface_clipN)rI   rJ   rK   rL   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  p  s.    !+!%r  c                   @   r5  )DrawAALinesTestzTest draw module function aalines.

    This class inherits the general tests from AALinesMixin. It is also the
    class to add any draw.aalines specific tests to.
    Nr7  r   r   r   r   r  T  r8  r  rd   )r   rd   r   r  r   ri   rz   r   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6S )7DrawPolygonMixinzfMixin tests for drawing polygons.

    This class contains all the general polygon drawing tests.
    c                 C   s   t d| _d S )Nr  )rD   rk   r   rn   r   r   r   setUpv  s   zDrawPolygonMixin.setUpc                 C   r  )z.Ensures draw polygon accepts the correct args.rc   re   r  r"   NrR   rD   rk   rl   rE   rm   r   r   r   test_polygon__argsy  rP  z#DrawPolygonMixin.test_polygon__argsc                 C   s&   |  tddd}| |tj dS )z6Ensures draw polygon accepts the args without a width.rp   rN  r  Nr  rm   r   r   r    test_polygon__args_without_width  s   z1DrawPolygonMixin.test_polygon__args_without_widthc                 C   s^   t d}t d}d}|||dd|||dg}|D ]}| jdi |}| |t j qdS )	z^Ensures draw polygon accepts the correct kwargs
        with and without a width arg.
        ry   r   r  r"   r   r5   r  r#   )r   r5   r  Nr   )rD   rk   r   rR   rl   rE   r  r   r   r   test_polygon__kwargs  s   


z%DrawPolygonMixin.test_polygon__kwargsc                 C   s*   | j dtdddd}| |tj dS )z6Ensures draw polygon's kwargs are not order dependent.rX  rh   r   r   r   rv   )r5   r   r#   r  Nr  rm   r   r   r   &test_polygon__kwargs_order_independent  s   z7DrawPolygonMixin.test_polygon__kwargs_order_independentc                 C   s   t d}t d}| t | ||}W d   n1 s w   Y  | t | |}W d   n1 s:w   Y  | t |  }W d   dS 1 sTw   Y  dS )z7Ensures draw polygon detects any missing required args.rs   r   NrD   rk   r   r   r   rR   r]  r   r   r   test_polygon__args_missing  s   


"z+DrawPolygonMixin.test_polygon__args_missingc              	   C   rC  )	z9Ensures draw polygon detects any missing required kwargs.r   r   r  r"   r  )r  r5   r   Nr   )rD   rk   r   r   r   r   r   rR   r   r   r   r   test_polygon__kwargs_missing  rE  z-DrawPolygonMixin.test_polygon__kwargs_missingc                 C   s   t d}t d}d}| t | |||d}W d   n1 s$w   Y  | t | ||d}W d   n1 s@w   Y  | t | |d|}W d   n1 s\w   Y  | t | d||}W d   dS 1 syw   Y  dS )	z/Ensures draw polygon detects invalid arg types.rp   r   )r   r   r   r   Nr   r   rc  r  )rn   r   r5   r  r=   r   r   r   test_polygon__arg_invalid_types  s   

"z0DrawPolygonMixin.test_polygon__arg_invalid_typesc              	   C   rG  )z1Ensures draw polygon detects invalid kwarg types.rc   r   )r)   r   rf  r"   r  r   )r!   r!   r!   rg  Nr   r  )rn   r   r5   r  r#   r   r   r=   r   r   r   !test_polygon__kwarg_invalid_types  s6   

z2DrawPolygonMixin.test_polygon__kwarg_invalid_typesc              	   C   s~   t d}t d}d}|||ddd|||ddg}|D ]}| t | jdi |}W d   n1 s7w   Y  qdS )	z1Ensures draw polygon detects invalid kwarg names.rv   r   )rs   r   r   r"   )r   r5   r  r#   r   )r   r5   r  r   Nr   r  r  r   r   r    test_polygon__kwarg_invalid_name  s"   

z1DrawPolygonMixin.test_polygon__kwarg_invalid_namec                 C   s   t d}d}d}d}||||d}dD ]G}|| d|kr)| j|fi |}n+d|kr8| j||fi |}nd|krH| j|||fi |}n| j||||fi |}| |t j qd	S )
z9Ensures draw polygon accepts a combination of args/kwargsr   r   r  r   r  r   r5   r  N)rD   rk   r   rR   rl   rE   )rn   r   r5   r  r#   r   r   r=   r   r   r   test_polygon__args_and_kwargs  s    

z.DrawPolygonMixin.test_polygon__args_and_kwargsc           	      C   s   t d}t d}d}||ddd}|d d }d	D ]+}|| ||d
< |dkr,|n|}| jdi |}| ||| | |t j qdS )z4Ensures draw polygon accepts different width values.r   r   r   r  Nr  r  r   rn  r#   r   )	rD   r   rk   r   rR   rw   r   rl   rE   )	rn   r   r   r5   r   r1   r#   r   r=   r   r   r    test_polygon__valid_width_values#  s"   


z1DrawPolygonMixin.test_polygon__valid_width_valuesc                    s   d}t d}t d}||ddd}ttttfttttfttttfttttff}d}ttf}|D ]> |D ]9}|d }	 fdd	t|D }
|D ]%}|| ||
|d
< | jdi |}| 	|
|	| | |t j qHq5q1dS )z6Ensures draw polygon accepts different points formats.r   r   r   Nr   r  r  c                    r  r   r   r  r  r   r   r   Z  r  zFDrawPolygonMixin.test_polygon__valid_points_format.<locals>.<listcomp>r  r   )rD   r   rk   ru  rv  r   r  r   rR   rw   r   rl   rE   r  r   r  r   !test_polygon__valid_points_format:  r  z2DrawPolygonMixin.test_polygon__valid_points_formatc                 C   s   t dt dddd}dddd	d
ddhfd	d
dddfh ddddddf}|D ]#}||d< | t | jdi |}W d   n1 sHw   Y  q*dS )z>Ensures draw polygon handles invalid points formats correctly.ry   r   Nr   r  )rs   r   r{  )rs   r   r  )rs   r   r  rs   r   ri   rd   rv   >   rs   r   r   rp   r"   rz   rc  r  r   r  r  r   r   r   $test_polygon__invalid_points_formatse  s(   
z5DrawPolygonMixin.test_polygon__invalid_points_formatsc              
   C   s   t dt dddd}d}|D ],}ttfD ]%}|||d< | t | jdi |}W d   n1 s7w   Y  qqdS )	z=Ensures draw polygon handles invalid points values correctly.ry   r   Nr   r  )r   r
  )rs   r   r  r   )rD   rk   r   ru  rv  r   r  rR   )rn   r   r  r  rw  r=   r   r   r   #test_polygon__invalid_points_values~  s   z4DrawPolygonMixin.test_polygon__invalid_points_valuesc           
      C   s   t d}t d}t d}|dddd}|d d }d	d
|||f}|D ]0}|| ||d< t|tr=||}n|}| jdi |}	| 	|
|| | |	t j q'dS )z5Ensures draw polygon accepts different color formats.r   r   r   Nr  r   r  r  r   r   r5   r   )rD   r   rk   r   r   r   r   r   rR   rw   r   rl   rE   )
rn   r   r   r   r   r1   r  r5   r   r=   r   r   r   !test_polygon__valid_color_formats  s0   




z2DrawPolygonMixin.test_polygon__valid_color_formatsc              	   C   rX  )	z=Ensures draw polygon handles invalid color formats correctly.r   Nr  r   r  r   r5   r   )rD   rk   r   r   rR   r  r   r   r   #test_polygon__invalid_color_formats  rZ  z4DrawPolygonMixin.test_polygon__invalid_color_formatsc                 C   sJ   |  | jttd tdD ]}tdD ]}| | j||ft qqd S )Nr   rz   )rR   r   r   SQUAREr'   rw   r   rn   r   r    r   r   r   test_draw_square  s   z!DrawPolygonMixin.test_draw_squarec                 C   s   t j| jtdd | | jttd tD ]\}}| j| j	||ftt
||fd qtddD ]}tddD ]}| | j	||ft q8q1d S )Nrd  r   r  ri   r   )rD   r   r,   r   r   rR   GREENDIAMONDrw   r   strr'   r  r   r   r   test_draw_diamond  s   &z"DrawPolygonMixin.test_draw_diamondc                 C   s0  t j| jtdd | | jtdd tD d d}t|d D ]&}| 	| j
|dft | 	| j
|dft | 	| j
|dft q t j| jtdd | | jtd	d tD d t|d D ]&}| 	| j
|d
ft | 	| j
|dft | 	| j
|dft qet j| jtdd | | jtdd tD d t|d D ]&}| 	| j
d|ft | 	| j
d|ft | 	| j
d
|ft qt j| jtdd | | jtdd tD d t|d D ]&}| 	| j
d|ft | 	| j
d
|ft | 	| j
d|ft qd S )Nrd  r   c                 S      g | ]\}}|d fqS r{  r   r   r   Z_yr   r   r   r         zEDrawPolygonMixin.test_1_pixel_high_or_wide_shapes.<locals>.<listcomp>r   r"   ri   rd   c                 S   r  r  r   r  r   r   r   r     r  rz   r   c                 S      g | ]\}}d |fqS rd   r   r   Z_xr    r   r   r   r     r  c                 S   r  r  r   r  r   r   r   r     r  )rD   r   r,   r   r   rR   r  CROSSr'   rw   r   )rn   Z
cross_sizer   r    r   r   r    test_1_pixel_high_or_wide_shapes  s4   z1DrawPolygonMixin.test_1_pixel_high_or_wide_shapesc                 C   s  t j| jtdd | | jttd dd tddD dd tddD  }tdD ]K}tdD ]D}||f|v rF| 	| j
||ft q1|td	d
v rQ|dk s\|td	d
v ri|dk ri| 	| j
||ft q1| 	| j
||ft q1q+t j| jtdd | | jttd dd tddD dd tddD  }tdD ]>}tdD ]7}|td	d
v r|dk s|td	d
v r|dk r| j	| j
||ftt||fd q| 	| j
||ft qqdS )znon-regression on issue #234 : x and y where handled inconsistently.

        Also, the result is/was different whether we fill or not the polygon.
        rd  r   r"   c                 S      g | ]}|d fqS r  r   r   r   r   r   r     r   z=DrawPolygonMixin.test_draw_symetric_cross.<locals>.<listcomp>r   c                 S      g | ]}d |fqS r  r   r   r   r   r   r     r   rf   ri   r   r  c                 S   r  r  r   r   r   r   r   r     r   c                 S   r  r  r   r   r   r   r   r     r   r  N)rD   r   r,   r   r   rR   r  r  r'   rw   r   r  )rn   Zinsider   r    r   r   r   test_draw_symetric_cross  s.   (,(,z)DrawPolygonMixin.test_draw_symetric_crossc                 C   s$  t d}d|jd df|jd dfdd|jd fd|jd fg}t j| jtdd | | jt	|dd d t
d	D ]}| | j|dft	 q<t
d|jd d D ]}| | j|dft	 qUt j| jtdd | | jt	|d t
d|jd d D ]}| | j|dft	 qdS )
znon-regression on issue #313)r   r   r   r   r)   r"   r   r   rz   ry   Nr   )rD   rE   r#   r%   r   r,   r   r   rR   r  r'   rw   r   )rn   r,   Z	path_datar   r   r   r   test_illumine_shape  s&   
z$DrawPolygonMixin.test_illumine_shapec                    s     t fdd d S )Nc                      s      jtddS )N)r)   )r   r   r  r   r   )rR   r   r   r   r  r   r   <lambda>I  s    
z6DrawPolygonMixin.test_invalid_points.<locals>.<lambda>)r   r   r  r   r  r   test_invalid_pointsF  s   
z$DrawPolygonMixin.test_invalid_pointsc              
   C   s  t d}t d}d }}d }}||f||ff}t ddd}| }	|	|d d	 |d d	 }
t|	t|
 D ]J}tD ]E}|D ]@\}}t d
||f}t||| |j	|j
|jf}tdD ]!}|| | ||||}t|||d }| ||d|  qaqCq?q;dS )zEnsures draw polygon returns the correct bounding rect.

        Tests polygons on and off the surface and a range of width/thickness
        values.
        r   r   r   r  r  r   r  ri   r"   r)   rz   
thickness=N)rD   r   rk   r   r  r-   r  rE   r  r   r   r   r'   r   rR   rG   rw   )rn   polygon_colorrF   r  r  r  r   r   r   r!  r"  r1   r#  r#   r%   r0  verticesr   r$  r%  r   r   r   test_polygon__bounding_rectN  sL   



z,DrawPolygonMixin.test_polygon__bounding_rectc                    s0  d } t d}t d}t | f}|| t dd}| j|_| }dD ]i}t|D ]b}||_|j	|j
|j|jf}	|d || | |||	| t|||}
|| || | |||	| |   fdd	t|D D ]}||
v r|}n|}| |||| qz|  q2q,dS )
zuEnsures draw polygon respects a surface's clip area.

        Tests drawing the polygon filled and unfilled.
        r   r   r   r)   r=  rf   r   Nc                 3   r*  r   r&   r3   r+  r   r   r     r   z>DrawPolygonMixin.test_polygon__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r  r-   r
   r   r   r   r-  rR   r?   r;   r'   rw   r   r<   )rn   r.  r  r   r   r/  r0  r#   r   r  r1  r2  r   r   r+  r   test_polygon__surface_clip  s@   







z+DrawPolygonMixin.test_polygon__surface_clipc                    s  d}d}d}d}d}d}d }}t ||f d}	d	t j d
d
||fd
  fdd}
 fdd} fdd} fdd} fdd} fdd} fdd}|  |	|||f |
|  t j d
d
||fd
 |  |	|||f ||  ||  t j d
d
||fd
 |  |	|||f ||  ||  t j d
d
||fd
 |  |	|||f ||  ||  dS )zy
        Ensures draw polygon works correctly with large points.
        Testing the drawings of filled polygons
        )X  rg   )rg   r  )  順 )p`y)r  r  )r  r  i  r   r  r   c                    s(   |   d |   d d S )N)  rg   )rg   r  rw   r   r  r   r   r   r   extreme_points  s   zGDrawPolygonMixin.test_polygon_large_coords_3989.<locals>.extreme_pointsc                       |   d d S )N)r     r  r  r  r   r   extreme_negative_pass     zNDrawPolygonMixin.test_polygon_large_coords_3989.<locals>.extreme_negative_passc                    r  )Nr   r  r   r  r  r   r   extreme_negative_fail  r  zNDrawPolygonMixin.test_polygon_large_coords_3989.<locals>.extreme_negative_failc                    r  N)r  r  r  r  r  r   r   extreme_x_pass  r  zGDrawPolygonMixin.test_polygon_large_coords_3989.<locals>.extreme_x_passc                    r  )N)ro  r  r  r  r  r   r   extreme_x_fail  r  zGDrawPolygonMixin.test_polygon_large_coords_3989.<locals>.extreme_x_failc                    r  r  r  r  r  r   r   extreme_y_pass  r  zGDrawPolygonMixin.test_polygon_large_coords_3989.<locals>.extreme_y_passc                    r  )N),  r	  r  r  r  r   r   extreme_y_fail  r  zGDrawPolygonMixin.test_polygon_large_coords_3989.<locals>.extreme_y_failN)rD   rk   r   r,   rR   )rn   Zpoint_aZpoint_bZextreme_points_coordsZextreme_negative_coordsZextreme_negative_xZextreme_negative_yr   r   r   r  r  r  r  r  r  r
  r   r  r   test_polygon_large_coords_3989  s@   z/DrawPolygonMixin.test_polygon_large_coords_3989N)rI   rJ   rK   rL   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  p  s8     +!	
#-77r  c                   @   r5  )DrawPolygonTestzTest draw module function polygon.

    This class inherits the general tests from DrawPolygonMixin. It is also
    the class to add any draw.polygon specific tests to.
    Nr7  r   r   r   r   r     r8  r  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*S )+DrawRectMixinz`Mixin tests for drawing rects.

    This class contains all the general rect drawing tests.
    c                 C   s:   |  tddtdddddddd		}| |tj d
S )z+Ensures draw rect accepts the correct args.rp   )r   rf   r      r)   rs   ri   r"   rd   rz   r   NrP   rD   rk   rE   rl   rm   r   r   r   test_rect__args  s   
zDrawRectMixin.test_rect__argsc                 C   s.   |  tddtdd}| |tj dS )z?Ensures draw rect accepts the args without a width and borders.r  r  r)   rs   Nr  rm   r   r   r   test_rect__args_without_width,  ru   z+DrawRectMixin.test_rect__args_without_widthc              
   C   sj   t dt dt ddddddd	d
d	t ddddg}|D ]}| jdi |}| |t j q!dS )zmEnsures draw rect accepts the correct kwargs
        with and without a width and border_radius arg.
        r   r   r)   r   r"   rf   r   r   rR  r   	r   r5   r,   r#   border_radiusborder_top_left_radiusborder_top_right_radiusborder_bottom_left_radiusborder_bottom_right_radius)r   ro  r  r   r   Nr   )rD   rk   r   rE   rP   rl   r   r   r   r   test_rect__kwargs4  s&   
zDrawRectMixin.test_rect__kwargsc                 C   s<   | j ddtdddddtddd	d
	}| |tj dS )z3Ensures draw rect's kwargs are not order dependent.)r   r"   ri   rf   rv   r   r  r   r   r)   rR  )	r5   r  r   r  r#   r  r  r,   r  Nr  rm   r   r   r   #test_rect__kwargs_order_independentP  s   
z1DrawRectMixin.test_rect__kwargs_order_independentc                 C   r   )z4Ensures draw rect detects any missing required args.rs   r   N)rD   rk   r   r   rP   r   r   r   r   r   test_rect__args_missing`  r   z%DrawRectMixin.test_rect__args_missingc              
   C   s   t dt dt dddddddd	d
	}dD ](}t|}|| | t | jdi |}W d   n1 s;w   Y  qdS )z6Ensures draw rect detects any missing required kwargs.r   r   r)   rp   r   rf   r   rR  r   r  r   Nr   )	rD   rk   r   rE   r   r   r   r   rP   r   r   r   r   test_rect__kwargs_missingm  s$   

z'DrawRectMixin.test_rect__kwargs_missingc                 C   sL  t d}t d}t dd}| t | j|||ddd}W d   n1 s*w   Y  | t | j|||ddd}W d   n1 sIw   Y  | t | j|||ddd	}W d   n1 shw   Y  | t | j|||dd
d}W d   n1 sw   Y  | t | |||dd}W d   n1 sw   Y  | t | |||dd}W d   n1 sw   Y  | t | ||ddd}W d   n1 sw   Y  | t | |d|dd}W d   n1 sw   Y  | t | |||dd}W d   dS 1 sw   Y  dS )z,Ensures draw rect detects invalid arg types.rc   r   rs   ri   Zrad)r  N)r  )r  r   )r  r  rz   r   r   r   rd   r=  rf   rD   rk   r   rE   r   r   rP   r   r   r   r   test_rect__arg_invalid_types  sL   





$z*DrawRectMixin.test_rect__arg_invalid_typesc                 C   s4  t d}t d}t dd}t j||ddddd	d
d	|d|ddddd	d
d	||dddddd	d
d	|||ddddd	d
d	|||ddddd	d
d	|||ddddd	d
d	|||ddddd	d
d	|||dddddd
d	|||ddddd	dd	g	}|D ]}| t | jdi |}W d   n1 sw   Y  qxdS )z.Ensures draw rect detects invalid kwarg types.rv   r   r)   rs   r"   rf   r   r   rR  r   r  r   )r"   r"   ri   r   g      %@      @r  r  r  Nr   r  r   r   r   r   test_rect__kwarg_invalid_types  s   

fz,DrawRectMixin.test_rect__kwarg_invalid_typesc                 C   s   t d}t d}t dd}|||ddddd	d
dd
|||ddg}|D ]}| t | jdi |}W d   n1 s@w   Y  q&dS )z.Ensures draw rect detects invalid kwarg names.r   r   r)   rc   r"   rf   r   r   rR  r   )
r   r5   r,   r#   r  r  r  r  r  r   r   Nr   r  r   r   r   r   test_rect__kwarg_invalid_name#  s,   

z+DrawRectMixin.test_rect__kwarg_invalid_namec                 C   r   )z6Ensures draw rect accepts a combination of args/kwargsr   )r   r   r   r   r   r  r   r   r   r5   r,   N)rD   rk   rE   r   rP   rl   r   r   r   r   test_rect__args_and_kwargs<  s    

z(DrawRectMixin.test_rect__args_and_kwargsc           	      C   r   )z1Ensures draw rect accepts different width values.rs   r   r   )r"   ri   rd   r   rp   Nr   r   r#   r   r   	rD   r   rk   rE   r   rP   rw   r   rl   r   r   r   r   test_rect__valid_width_valuesQ  r   z+DrawRectMixin.test_rect__valid_width_valuesc           	      C   s   d}t d}t d}t d}||ddd}t |d|df|d |d	 d
d
f|dgf}|D ]#}|| ||d< | jdi |}| ||| | |t j q0dS )z1Ensures draw rect accepts different rect formats.rs   r   r   r   Nr   r   rp   r"   rd   r  r,   r   r"  r   r   r   r   test_rect__valid_rect_formatsh  s"   




z+DrawRectMixin.test_rect__valid_rect_formatsc              	   C   s   t dt dddd}g dgddgg dg d	h d
g df}|D ]#}||d< | t | jdi |}W d   n1 sAw   Y  q#dS )z9Ensures draw rect handles invalid rect formats correctly.ry   r   Nr   r   r"   ri   r   r   >   r"   ri   rd   rz   )r"   ri   rd   4r,   r   )rD   rk   r   r   r   rP   )rn   r   Zinvalid_fmtsr,   r=   r   r   r   test_rect__invalid_rect_formats  s(   
z-DrawRectMixin.test_rect__invalid_rect_formatsc           
      C   s   d}t d}t d}t d}|dt |ddd}dd	|||f}|D ]0}|| ||d
< t|tr=||}n|}| j	di |}	| 
||| | |	t j q'dS )z2Ensures draw rect accepts different color formats.rs   r   r   r   Nrd   r   r   r   r   r   r   r5   r   )rD   r   rk   rE   r   r   r   r   r   rP   rw   r   rl   )
rn   r1   Z	red_colorr   r   r   r   r5   r   r=   r   r   r   test_rect__valid_color_formats  s(   





z,DrawRectMixin.test_rect__valid_color_formatsc              	   C   sx   d}t d}|dt |ddd}d| fD ]#}||d< | t | jdi |}W d   n1 s4w   Y  qdS )	z:Ensures draw rect handles invalid color formats correctly.rs   r   Nr"   r   r   r5   r   )rD   rk   rE   r   r   rP   r   r   r   r    test_rect__invalid_color_formats  r   z.DrawRectMixin.test_rect__invalid_color_formatsc                 C   s*  d \| _ | _| _t| jtj| _d| _tdddd}| 	| j| j|d}| 
|| t|D ]}| j|}| 
|| j q2t|D ]}| j|}| || j qGtd}| j| tdd| j d	 d}tdd
d| jd }| 	| j| j|d}| 
|| |j\}}	|j\}
}| 
| j|d |	f| | 
| j||
 |	f| t|||
 D ]}| 
| j||	f| j q| 	| j| j|d}| 
|| |j\}}	|j\}
}| 
| j||	d f| | 
| j||	| f| t|	|	| D ]}| 
| j||f| j qd S )Nr  r  rf   r   r   r   r   r"   ri   rd   rz   )r   r   r  rD   rk   r   r  r5   rE   rP   rw   r   r  r   r  r  r   r   r
   rA   r'   )rn   r,   r  r2  color_at_ptbgcolorZhrectZvrectr   r    r{   r|   r  r   r   r   test_rect__fill  sB   




zDrawRectMixin.test_rect__fillc                 C   s   t dt j| _d| _t dddd}| | j| j|d}| || t	|D ]}| j
|}| || j q(t|D ]}| j
|}| || j q=d S )Nr  r  rf   8   r   r"   )rD   rk   r   r  r5   rE   rP   rw   r   Zrect_perimeter_ptsr   r  r  )rn   r,   r  r2  r*  r   r   r   test_rect__one_pixel_lines  s   z(DrawRectMixin.test_rect__one_pixel_linesc              
   C   sN  t d}|d t ddd}d}d}d}t j||t dd||| t|D ]>}| |	||f| | |	|| d |f| | |	||| d f| | |	|| d || d f| q*| |	||fd	 | |	|| d |fd	 | |	||| d fd	 | |	|| d || d fd	 d S )
Nro  ro  r   r   r   rg   rf   r   r"   r   )
rD   rk   r   r   r   r,   rE   r'   rw   r   )rn   r   r5   Z
rect_widthZrect_heightr  r  r   r   r   test_rect__draw_line_width  s6   

z(DrawRectMixin.test_rect__draw_line_widthc              
   C   s   t d}t d}d }}d }}||f||ff}t ddd}| }	|	|d d	 |d d	 }
t|	t|
 D ]A}tD ]<}|D ]7\}}t d
||f}t||| t	dD ] }|
| | ||||}t|||j}| ||d|  qYqCq?q;dS )zEnsures draw rect returns the correct bounding rect.

        Tests rects on and off the surface and a range of width/thickness
        values.
        r   r   r   r  r  r   r  ri   r"   r)   rz   r  N)rD   r   rk   r   r  r-   r  rE   r  r'   r   rP   rG   r
   rw   )rn   
rect_colorrF   r  r  r  r   r   r   r!  r"  r1   r#  r#   r%   r,   r   r$  r%  r   r   r   test_rect__bounding_rect+  sD   


z&DrawRectMixin.test_rect__bounding_rectc                    r'  )
zoEnsures draw rect respects a surface's clip area.

        Tests drawing the rect filled and unfilled.
        r   r   r   r)   r  r   Nc                 3   r*  r   r&   r3   r+  r   r   r     r   z8DrawRectMixin.test_rect__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r  r-   r-  rP   r?   r;   r'   rw   r   r<   )rn   r.  r1  r   r   r/  Z	test_rectr#   r   r1  r2  r   r   r+  r   test_rect__surface_clipZ  r4  z%DrawRectMixin.test_rect__surface_clipN)rI   rJ   rK   rL   r  r  r  r  r  r  r  r  r   r!  r#  r$  r&  r(  r)  r,  r.  r0  r2  r3  r   r   r   r   r    s,    2o3/r  c                   @   r5  )DrawRectTestzTest draw module function rect.

    This class inherits the general tests from DrawRectMixin. It is also the
    class to add any draw.rect specific tests to.
    Nr7  r   r   r   r   r4    r8  r4  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4S )5DrawCircleMixinzdMixin tests for drawing circles.

    This class contains all the general circle drawing tests.
    c                 C   s2   |  tddddddddd	}| |tj dS )z-Ensures draw circle accepts the correct args.rc   re   r)   rd   r"   r   NrT   rD   rk   rl   rE   rm   r   r   r   test_circle__args     z!DrawCircleMixin.test_circle__argsc                 C   r  )zKEnsures draw circle accepts the args without a width and
        quadrants.rp   rN  rs   r"   Nr6  rm   r   r   r   test_circle__args_without_width  s   z/DrawCircleMixin.test_circle__args_without_widthc              	   C   sB   |  tddddd}| |tj | |tdddd dS )z9Ensures draw circle accepts the args with negative width.rp   rN  rs   r"   r.   r   NrT   rD   rk   rl   rE   rw   rm   r   r   r   %test_circle__args_with_negative_width  s
   z5DrawCircleMixin.test_circle__args_with_negative_widthc                 C   sJ   |  tddddddddd	}| |tj | |tdddd dS )z9Ensures draw circle accepts the args with width > radius.rp   rN  rs   ri   rd   r   Nr:  rm   r   r   r   &test_circle__args_with_width_gt_radius  s
   z6DrawCircleMixin.test_circle__args_with_width_gt_radiusc              
   C   sd   t dt ddddddddd	t d	d
dddg}|D ]}| jdi |}| |t j qdS )zpEnsures draw circle accepts the correct kwargs
        with and without a width and quadrant arguments.
        ry   r   rp   ri   r"   TF	r   r5   r   radiusr#   draw_top_rightdraw_top_leftdraw_bottom_leftdraw_bottom_rightr   r   rs   )r   r5   r   r>  Nr   )rD   rk   r   rT   rl   rE   r   r   r   r   test_circle__kwargs  s(   z#DrawCircleMixin.test_circle__kwargsc                 C   s4   | j ddtdddddddd	}| |tj d	S )
z5Ensures draw circle's kwargs are not order dependent.FrX  rh   r   r   ri   T)	r?  r5   r   r#   rA  r   rB  r>  r@  Nr6  rm   r   r   r   %test_circle__kwargs_order_independent  s   z5DrawCircleMixin.test_circle__kwargs_order_independentc                 C   r[  )z6Ensures draw circle detects any missing required args.rs   r   r)   NrD   rk   r   r   r   rT   r]  r   r   r   test_circle__args_missing  r_  z)DrawCircleMixin.test_circle__args_missingc              
   C   s~   t dt ddddddddd	}d	D ](}t|}|| | t | jdi |}W d
   n1 s7w   Y  qd
S )z8Ensures draw circle detects any missing required kwargs.r   r   r   ri   r"   FTr=  )r>  r   r5   r   Nr   )rD   rk   r   r   r   r   r   rT   r   r   r   r   test_circle__kwargs_missing  s$   
z+DrawCircleMixin.test_circle__kwargs_missingc                 C   sZ  t d}t d}d}d}| t | ||||ddddd	}W d   n1 s+w   Y  | t | ||||ddddd	}W d   n1 sMw   Y  | t | ||||ddddd	}W d   n1 sow   Y  | t | ||||ddddd		}W d   n1 sw   Y  | t | ||||d
}W d   n1 sw   Y  | t | |||d}W d   n1 sw   Y  | t | ||d|}W d   n1 sw   Y  | t | |d||}W d   n	1 sw   Y  | t | d|||}W d   dS 1 s&w   Y  dS )z.Ensures draw circle detects invalid arg types.rp   r   rs   r"   r  Nr  r  r  r   r  r   r   rc  rE  )rn   r   r5   r   r>  r=   r   r   r   test_circle__arg_invalid_types  sN   

$z.DrawCircleMixin.test_circle__arg_invalid_typesc           
      C   s8  t d}t d}d}d}d}d}t j||||ddddd	|d|||ddddd	||d||ddddd	|||d	|ddddd	||||d
ddddd	|||||ddddd	|||||ddddd	|||||ddddd	|||||ddddd	g	}|D ]}| t | jdi |}	W d   n1 sw   Y  qzdS )z0Ensures draw circle detects invalid kwarg types.rc   r   r   r"   Tr=  r   )r"   r"   r"   r   rg  TrueQ	@quadrantNr   rE  )
rn   r   r5   r   r>  r#   rK  r   r   r=   r   r   r    test_circle__kwarg_invalid_typesM  s   

fz0DrawCircleMixin.test_circle__kwarg_invalid_typesc                 C   s   t d}t d}d}d}||||ddddddd
||||ddg}|D ]}| t | jd
i |}W d	   n1 s?w   Y  q%d	S )z0Ensures draw circle detects invalid kwarg names.rv   r   r)   ri   r"   T)
r   r5   r   r>  r#   rK  r?  r@  rA  rB  )r   r5   r   r>  r   Nr   rE  )rn   r   r5   r   r>  r   r   r=   r   r   r   test_circle__kwarg_invalid_name  s8   

z/DrawCircleMixin.test_circle__kwarg_invalid_namec                 C   s  t d}d}d}d}d}d}d}d}d}	|||||ddddd	}
dD ]}|
| d	|kr8| j|fi |
}nd
|krG| j||fi |
}nd|krW| j|||fi |
}npd|krh| j||||fi |
}n_d|krz| j|||||fi |
}nMd|kr| j||||||fi |
}n:d|kr| j|||||||fi |
}n&d|kr| j||||||||fi |
}n| j|||||||||	f	i |
}| |t j q#dS )z8Ensures draw circle accepts a combination of args/kwargsr   r   r   ri   r   TFr=  r   r5   r   r>  r#   r?  r@  rA  N)rD   rk   r   rT   rl   rE   )rn   r   r5   r   r>  r#   r?  r@  rA  rB  r   r   r=   r   r   r   test_circle__args_and_kwargs  s   



	
z,DrawCircleMixin.test_circle__args_and_kwargsc              
   C   s   d}d}|d | |d f}t d}t d}d}||||dddddd		}d
D ]+}|| ||d< |dkr9|n|}	| jdi |}
| |||	 | |
t j q(dS )z3Ensures draw circle accepts different width values.rp   r"   r   r   r   r   NTr=  rn  r#   r   	rD   r   rk   r   rT   rw   r   rl   rE   )rn   r   r>  r1   r   r   r5   r   r#   r   r=   r   r   r   test_circle__valid_width_values:  s0   


z/DrawCircleMixin.test_circle__valid_width_valuesc           
   
   C   s   d }}t d}t d}d}|||ddddddd	}d	D ]+}|| ||d
< |dkr/|n|}| jdi |}	| ||| | |	t j qdS )z4Ensures draw circle accepts different radius values.rp   r   r   r   Nr   Tr=  )r   r.   r   r"   rf   r>  r   rO  )
rn   r1   r   r   r   r5   r   r>  r   r=   r   r   r    test_circle__valid_radius_valuesX  s,   


z0DrawCircleMixin.test_circle__valid_radius_valuesc           
   
   C   s   t d}t d}t d}||dddddddd	}d	\}}||f|d
 |f||d
 f|d
 |d
 ffD ]/}tttfD ]'}|| |||d< | jdi |}	| |	||f| | 
|	t j q<q5dS )z5Ensures draw circle accepts different center formats.r   r   ry   Nr"   r   Tr=  rp   rs  r   r   )rD   r   rk   ru  rv  r   r   rT   rw   r   rl   rE   )
rn   r   r   r   r   r   r    r   rw  r=   r   r   r   !test_circle__valid_center_formatst  s.   


0
z1DrawCircleMixin.test_circle__valid_center_formatsc              
   C   s   d}d}|d | |d f}t d}t d}t d}|d||dddddd		}d
d|||f}|D ]0}	|| |	|d< t|	trJ||	}
n|}
| jdi |}| 	|
||
 | |t j q4dS )z4Ensures draw circle accepts different color formats.rp   r"   r   r   r   r   NTr=  r   r   r5   r   )rD   r   rk   r   r   r   r   r   rT   rw   r   rl   rE   )rn   r   r>  r1   r   r   r   r   r  r5   r   r=   r   r   r    test_circle__valid_color_formats  s>   




z0DrawCircleMixin.test_circle__valid_color_formatsc              
   C   sr   t dddddddddd	}d| fD ]#}||d	< | t | jd
i |}W d   n1 s1w   Y  qdS )z<Ensures draw circle handles invalid color formats correctly.r   Nr   r"   r   Tr=  r   r5   r   )rD   rk   r   r   rT   r  r   r   r   "test_circle__invalid_color_formats  s"   z2DrawCircleMixin.test_circle__invalid_color_formatsc                 C   sd   t jtdddddddddd	 t jtddtddddddddd	 t td	d
dd dS )z Ensure that floats are accepted.ry   )r   r   r  r  ?r   Tr=  r  rp   rN  )rU  rU  rg  N)r   rS   rD   rk   r   r  r   r   r   test_circle__floats  s.   z#DrawCircleMixin.test_circle__floatsc                 C   s   t d}t d}d}t ddd}| }||d d |d d }t|t| D ]H}t|d D ]?}t|d D ]6}	|| | |||||	}
t	|||}| j
|||||	d	 | |
| W d
   n1 snw   Y  q=q5q-d
S )zEnsures draw circle returns the correct bounding rect.

        Tests circles on and off the surface and a range of width/thickness
        values.
        r   r   rd   )r   r   r   r  ri   r"   )r   circle_colorr1   r>  r   N)rD   r   rk   r   r  r-   r'   r   rT   rG   rh  rw   )rn   rW  rF   Z
max_radiusr   r!  r"  r1   r>  r   r$  r%  r   r   r   test_circle__bounding_rect  s>   



z*DrawCircleMixin.test_circle__bounding_rectc                 C   sL   t d}d}| d | d f}| j|||ddd}| |jd dS )	z@Ensures negative radius circles return zero sized bounding rect.r  r  rN  ri   r.   r"   )r>  r#   r)   N)rD   rk   r8   rT   rw   rA   )rn   r  r5   r   r$  r   r   r   test_circle_negative_radius.  s
   
z+DrawCircleMixin.test_circle_negative_radiusc           	   	   C   sp   t d}t d}t d}d}d}d}| |||||}t|||}| || | |t dddd dS )	zEnsures zero radius circles does not draw a center pixel.

        NOTE: This is backwards incompatible behaviour with 1.9.x.
        rY  r   r   r/  r   r"   ro  N)rD   rk   r   rT   rG   rw   rE   )	rn   r  rW  rF   r   r>  r#   r$  r%  r   r   r   test_circle_zero_radius7  s   


z'DrawCircleMixin.test_circle_zero_radiusc              	      s   d } t d}t d}t | f}|| t dd}| j|_|jd d }dD ]^}t|D ]W}|	d	 || | 
||||| t|||}	|| |	| | 
||||| |   fd
dt|D D ]}
|
|	v r{|}n|}| ||
||
 qr|  q5q/d	S )zsEnsures draw circle respects a surface's clip area.

        Tests drawing the circle filled and unfilled.
        r   r   r   r)   r  ri   r"   r   Nc                 3   r*  r   r&   r3   r+  r   r   r   l  r   z<DrawCircleMixin.test_circle__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r{   r-   r-  rT   r?   r;   r'   rw   r   r<   )rn   r.  rW  r   r   r/  r>  r#   r   r1  r2  r   r   r+  r   test_circle__surface_clipH  s4   







z)DrawCircleMixin.test_circle__surface_clipc                 C   s  d }}t d}t d}t ||f}|| d \}}}d}	d}
| ||||	|
}t|D ]L}|\}}|| d || d  }|	|
 d d |  k rX|	d d k rcn n	| ||| ||	|
 d d k su||	d d kr~| ||| q2d	S )
zEnsures there are no holes in the circle, and no overdrawing.

        Tests drawing a thick circle.
        Measures the distance of the drawn pixels from the circle center.
        ro  r   r   r<  -   r   ri   r"   N)	rD   r   rk   r   rT   r   r  rw   r   )rn   r.  r,  rW  r   r   Zcxcyr   r>  r#   Z	dest_rectr2  r   r    Zsqr_distancer   r   r   test_circle_shapev  s&   


,z!DrawCircleMixin.test_circle_shapec                 C   sx   t d}d}| d | d f}d}d}tddD ]}| |||||}| |j|d  | |j|d  qdS )z:Ensures draw circle is twice size of radius high and wide.rY  rN  ri   r"   r   A   N)rD   rk   r8   r'   rT   rw   r#   r%   )rn   r  r5   r   r#   r>  r$  r   r   r   test_circle__diameter  s   
z%DrawCircleMixin.test_circle__diameterc              
   C   s  t d}d}|| d}d}d}d}| j||||d}| |t d|d | |d | |d	  | ||d dkrA|d nd|d f| | ||d | d |d f| | ||d | d |d f| || d
}| j||||d}| |t |d |d dd | |d| |d f| || | |d	  df}| j||||d}| |t |d |d dd | |d|d f| | |d|d	  |d f| | || d |d f| | || | |d f| || d}| j||||d}| |t d|d | |d | |d	  | ||d dkr<|d nd|d f| | ||d | |d f| | ||d | d |d f| dS )zJensures a circle is drawn properly when there is a negative x, or a big x.rY  r  r'  r"   rf   )r   r   )r>  r   ri   )gꌠ9Y>)r   r   )r.   r   N)rD   rk   r   rT   rw   rE   r   r7   )rn   r  r+  r5   r#   r>  whereZbounding_rect1r   r   r   test_x_bounds  sT   

"&&&
 
 """
"("*zDrawCircleMixin.test_x_boundsN)rI   rJ   rK   rL   r7  r9  r;  r<  rC  rD  rF  rG  rH  rL  rM  rN  rP  rQ  rR  rS  rT  rV  rX  rZ  r[  r\  r_  ra  rc  r   r   r   r   r5    s6    		3r [(3-	.r5  c                   @   r5  )DrawCircleTestzTest draw module function circle.

    This class inherits the general tests from DrawCircleMixin. It is also
    the class to add any draw.circle specific tests to.
    Nr7  r   r   r   r   rd    r8  rd  c                   @   r+  )-DrawArcMixinz^Mixin tests for drawing arcs.

    This class contains all the general arc drawing tests.
    c                 C   s,   |  tdddddd}| |tj dS )z*Ensures draw arc accepts the correct args.rc   re   r"   r"   ri   ri   r   r"   N)rX   rD   rk   rl   rE   rm   r   r   r   test_arc__args  s   zDrawArcMixin.test_arc__argsc                 C   s2   |  tddtdddd}| |tj dS )z2Ensures draw arc accepts the args without a width.rp   rq   r)   r   r  NrX   rD   rk   rE   rl   rm   r   r   r   test_arc__args_without_width  r8  z)DrawArcMixin.test_arc__args_without_widthc              	   C   sD   |  tdddddd}| |tj | |tdddd dS )z6Ensures draw arc accepts the args with negative width.rc   rf   rf   rg   rg   rf  r   r"   r.   N)rX   rD   rk   rl   rE   rw   rm   r   r   r   "test_arc__args_with_negative_width  s
   z/DrawArcMixin.test_arc__args_with_negative_widthc              	   C   st   t dd}| t dd|dd|jd d }| |t j | t dd|dd|jd d }| |t j d	S )
zdEnsures draw arc accepts the args with
        width > rect.w // 2 and width > rect.h // 2.
        r)   ry   rc   rj  r   r]  ri   r"   N)rD   rE   rX   rk   r{   rl   r|   r}   r   r   r   #test_arc__args_with_width_gt_radius  s   z0DrawArcMixin.test_arc__args_with_width_gt_radiusc                 C   sh   t dt dt ddddddt d	d
ddddg}|D ]}| jdi |}| |t j q dS )zZEnsures draw arc accepts the correct kwargs
        with and without a width arg.
        ry   r   r)   rh   g      ?rd   r"   r   r5   r,   start_angle
stop_angler#   r   r   )r   r   ri   ri   r  r   r5   r,   rn  ro  Nr   )rD   rk   r   rE   rX   rl   r   r   r   r   test_arc__kwargs  s$   
	zDrawArcMixin.test_arc__kwargsc              
   C   s6   | j dddtddtddd}| |tj dS )	z2Ensures draw arc's kwargs are not order dependent.r"   r  r   rh   r   rv   )ro  rn  r5   r   r#   r,   Nrh  rm   r   r   r   "test_arc__kwargs_order_independent3  s   
	z/DrawArcMixin.test_arc__kwargs_order_independentc                 C   s4  t d}t d}t dd}| t | |||d}W d   n1 s(w   Y  | t | |||}W d   n1 sDw   Y  | t | ||}W d   n1 s_w   Y  | t | |}W d   n1 syw   Y  | t |  }W d   dS 1 sw   Y  dS )z3Ensures draw arc detects any missing required args.rs   r   r)   rp   rs  NrD   rk   r   rE   r   r   rX   r   r   r   r   test_arc__args_missing@  s$   


"z#DrawArcMixin.test_arc__args_missingc              	   C   s   t dt dt dddddd}d	D ](}t|}|| | t | jdi |}W d
   n1 s8w   Y  qd
S )z5Ensures draw arc detects any missing required kwargs.r   r   r   rp   rs  ri   r"   rm  )ro  rn  r,   r5   r   Nr   )	rD   rk   r   rE   r   r   r   r   rX   r   r   r   r   test_arc__kwargs_missingU  s   
	
z%DrawArcMixin.test_arc__kwargs_missingc              	   C   s  t d}t d}t dd}| t | |||ddd}W d   n1 s*w   Y  | t | |||ddd}W d   n1 sIw   Y  | t | |||ddd}W d   n1 shw   Y  | t | ||d	ddd}W d   n1 sw   Y  | t | |d
|ddd}W d   n1 sw   Y  | t | |||ddd}W d   dS 1 sw   Y  dS )z+Ensures draw arc detects invalid arg types.rp   r   rs   rc   r   r"   r   Nr   r   rs  r   r   r   r   test_arc__arg_invalid_typesg  s*   

"z(DrawArcMixin.test_arc__arg_invalid_typesc           	      C   s   t d}t d}t dd}d}d}t j||||dd|d	|||dd||d
||dd|||d|dd||||ddd|||||ddg}|D ]}| t | jdi |}W d   n1 scw   Y  qIdS )z-Ensures draw arc detects invalid kwarg types.rc   r   r   )rz   ri   rd   rz   r"   rm  r   r   r   r   Nr   rs  	rn   r   r5   r,   r  stopr   r   r=   r   r   r   test_arc__kwarg_invalid_types  sl   

					3z*DrawArcMixin.test_arc__kwarg_invalid_typesc           	   	   C   s   t d}t d}t dd}d}d}|||||ddd|||||dd	g}|D ]}| t | jdi |}W d
   n1 sCw   Y  q)d
S )z-Ensures draw arc detects invalid kwarg names.rv   r   r   rp   g?r   r"   )r   r5   r,   rn  ro  r#   r   )r   r5   r,   rn  ro  r   Nr   rs  rw  r   r   r   test_arc__kwarg_invalid_name  s6   


z)DrawArcMixin.test_arc__kwarg_invalid_namec           
      C   s  t d}d}t dd}d}d}d}||||||d}d	D ]l}|| d
|kr3| j|fi |}	nPd|krB| j||fi |}	nAd|krR| j|||fi |}	n1d|krc| j||||fi |}	n d|kru| j|||||fi |}	n| j||||||fi |}	| |	t j qdS )z5Ensures draw arc accepts a combination of args/kwargsr   r   r   rv   g333333?ri   r"   rm  rp  r   r5   r,   rn  ro  N)rD   rk   rE   r   rX   rl   )
rn   r   r5   r,   r  rx  r#   r   r   r=   r   r   r   test_arc__args_and_kwargs  s@   
	
z&DrawArcMixin.test_arc__args_and_kwargsc                 C   s   t d}t d}t d}t dd}| j|_|jd |jd f}|||ddd	d
}dD ]2}d| }|| ||d< |dkrF|n|}	| j	di |}
| 
|||	| | |
t j| q0d	S )z0Ensures draw arc accepts different width values.r   r   r  r)   ry   r"   r   r  Nrm  )ir   r  r  r.   r   r"   ri   rd   rf   rg   zwidth=r#   r   rD   r   rk   rE   r   r   r   r   r   rX   rw   r   rl   )rn   	arc_colorr   r   r,   r1   r   r#   r  r   r=   r   r   r   test_arc__valid_width_values  s,   


	

z)DrawArcMixin.test_arc__valid_width_valuesc           
      C   s   t d}t d}t d}t dd}| j|_|j|jd f}|||dddd	}d
D ]*}d| }|| ||d< | j	di |}	| 
|||| | |	t j| q.dS )z5Ensures draw arc accepts different stop_angle values.r   r   r  r)   ry   r"   iNrm  )r         r.   r   r"   r  rf   zstop_angle=ro  r   r|  )
rn   r   r   r   r,   r1   r   ro  r  r=   r   r   r   !test_arc__valid_stop_angle_values#  s*   


	

z.DrawArcMixin.test_arc__valid_stop_angle_valuesc           
      C   s   t d}t d}t d}t dd}| j|_|jd |jd f}|||dddd	}d
D ]*}d| }|| ||d< | j	di |}	| 
|||| | |	t j| q0dS )z6Ensures draw arc accepts different start_angle values.r   r   r  r)   ry   r"   N   rm  )g      $r  r.   r   r"   r  g      $@zstart_angle=rn  r   r|  )
rn   r   r   r   r,   r1   r   rn  r  r=   r   r   r   "test_arc__valid_start_angle_values>  s*   


	

z/DrawArcMixin.test_arc__valid_start_angle_valuesc           	      C   s   t d}t d}t d}t dd}| j|_|jd |jd f}||ddd	dd
}||j|j	f|j
|j|j|jff}|D ]#}|| ||d< | jdi |}| ||| | |t j qAdS )z0Ensures draw arc accepts different rect formats.r   r   r  r)   ry   r"   Nr   r  rm  r,   r   )rD   r   rk   rE   r   r   r   r   r
   rA   r   r    r{   r|   r   rX   rw   r   rl   )	rn   r   r   r   r,   r1   r   r   r=   r   r   r   test_arc__valid_rect_formatsY  s*   


"
z)DrawArcMixin.test_arc__valid_rect_formatsc                 C   s   t d}t d}t d}t dd}| j|_|jd |jd f}|d|dd	dd
}dd|||f}|D ]0}|	| ||d< t
|trO||}	n|}	| jdi |}
| |||	 | |
t j q9dS )z1Ensures draw arc accepts different color formats.r   r   r  r)   ry   r"   Nr   r  rm  r   r   r5   r   )rD   r   rk   rE   r   r   r   r   r   r   r   r   r   rX   rw   r   rl   )rn   r   r   r   r,   r1   r   r  r5   r   r=   r   r   r   test_arc__valid_color_formatst  s8   


	

z*DrawArcMixin.test_arc__valid_color_formatsc              	   C   s|   d}t d}|dt |ddddd}d	| fD ]#}||d
< | t | jdi |}W d   n1 s6w   Y  qdS )z9Ensures draw arc handles invalid color formats correctly.rs   r   Nrp   r   gffffff@r"   rm  r   r5   r   )rD   rk   rE   r   r   rX   r   r   r   r   test_arc__invalid_color_formats  s    

	z,DrawArcMixin.test_arc__invalid_color_formatsc           
      C   s   t d}t d}t d}|| d}d}d}d}t j|||||| t j|d d	}td
dD ]}	| 	|
||	f| q5| 	|
d| dS )z Ensure draw arc works correctly.r   r   )ro  r  )r   r   r   r   g        rJ  rd   zarc.pngr   ri   r   r)   N)rD   r   rk   r   r   rW   imagesaver'   rw   r   )
rn   r   r   r   r,   rn  ro  r#   r   r    r   r   r   test_arc  s   



zDrawArcMixin.test_arcc                 C   s6  t d}t d}d }}d }}||f||ff}t ddd}| }	|	|d d	 |d d	 }
d}ddd
dtdtj f}t|	t|
 D ]N}t	D ]I}|D ]D\}}t 
d||f}t||| dd	dd
t||fD ]'}|D ]"}|| | ||||||}t|||j}| ||d|  qrqnqRqNqJdS )zEnsures draw arc returns the correct bounding rect.

        Tests arcs on and off the surface and a range of width/thickness
        values.
        r   r   r   r  r  r   r  ri   r"   rd   r)   r  N)rD   r   rk   r   r  mathceilpir-   r  rE   r  rB   r   rX   rG   r
   rw   )rn   r}  rF   r  r  r  r   r   r   r!  r"  rn  Zstop_anglesr1   r#  r#   r%   Zarc_rectr   ro  r$  r%  r   r   r   test_arc__bounding_rect  sV   


z$DrawArcMixin.test_arc__bounding_rectc              
      s,  d } d}d}t d}t d}t | f}|| t dd}| j|_| }dD ]c}	t|D ]\}
|
|_|	d	 || | 
||||||	 t|||}|| |	| | 
||||||	 |   fd
dt|D D ]}||v r|}n|}| |||| qx|  q6q0d	S )z0Ensures draw arc respects a surface's clip area.r   rs  r   r   r   r)   r(  r   Nc                 3   r*  r   r&   r3   r+  r   r   r   -  r   z6DrawArcMixin.test_arc__surface_clip.<locals>.<genexpr>)rD   r   rk   r   rE   r   r   r  r-   r-  rX   r?   r;   r'   rw   r   r<   )rn   r.  r  r  r}  r   r   r/  r0  r   r   r1  r2  r   r   r+  r   test_arc__surface_clip	  s:   







z#DrawArcMixin.test_arc__surface_clipN)rI   rJ   rK   rL   rg  ri  rk  rl  rq  rr  rt  ru  rv  ry  rz  r{  r~  r  r  r  r  r  r  r  r  r   r   r   r   re    s.    	>%%#:re  c                   @   r5  )DrawArcTestzTest draw module function arc.

    This class inherits the general tests from DrawArcMixin. It is also the
    class to add any draw.arc specific tests to.
    Nr7  r   r   r   r   r  8  r8  r  c                   @   s    e Zd ZdZdd Zdd ZdS )DrawModuleTestzGeneral draw module tests.c           
   
      s  t d t dddd}dddt dd f}t|d	d
g }|dd |D  g d}dd tdD }tjdftj	dftj
dffD ]\}}|D ]}t t|d | t |rg| t|g| d n
| td|g|  W d   n1 s{w   Y  | t fdd|D  t t|d | t( |dd |g |dd  }	|r| t|	d n| td|	 W d   n1 sw   Y  | t fdd|D  qJqDdS )zNTest validation of multi-point drawing methods.

        See bug #521
        r   r   r   texts   bytesy      ?      ?c                 S   s   | S r   r   )r   r   r   r   r  ]  s    z:DrawModuleTest.test_path_data_validation.<locals>.<lambda>r!   r   c                 s   s    | ]}d |fV  qdS )r"   Nr   )r   vr   r   r   r   `  s    z;DrawModuleTest.test_path_data_validation.<locals>.<genexpr>)rs   r   rc   r   c                 S   r  r  r&   r3   r   r   r   r   c  r  z<DrawModuleTest.test_path_data_validation.<locals>.<listcomp>r"   TNc                 3       | ]
}  |tkV  qd S r   r   r   rw  r  r   r   r   t      ri   c                 3   r  r   r  rw  r  r   r   r     r  )rD   rk   rE   objectrv  extendr'   r   r[   r_   rQ   r,   r   r   r   r  r   all)
rn   r,   Z
bad_valuesZ
bad_pointsZ	good_pathZ	check_ptsmethodZ	is_polgonvalpathr   r  r   test_path_data_validationQ  sH   
z(DrawModuleTest.test_path_data_validationc                 C   s  t d}ddtddf}d}|D ]O}t||dd t||dd t||d	| t||d	| t||t 	d
d
dddd t
||t 	d
d
ddd t||dd t|||d
 qdt d fD ]}| t t||dd W d    n1 sw   Y  | t t||dd W d    n1 sw   Y  | t t||d	| W d    n1 sw   Y  | t t||d	| W d    n1 sw   Y  | t t||t 	d
d
dddd W d    n1 sw   Y  | t t
||t 	d
d
ddd W d    n	1 sw   Y  | t t||dd W d    n	1 s=w   Y  | t t|||d
 W d    n	1 s[w   Y  qfd S )Nr  i@ )r"   rf   ro  z#ab12dfr   )r)   rs   r   r)   rs   Tr   rd   rR  r  r   r"   r  ri   gjt?)rD   rk   r   r   rY   r]   r_   r[   rW   rE   rU   rS   rQ   r  r   r   )rn   r  colorsr  colr   r   r   test_color_validation  sN   
 z$DrawModuleTest.test_color_validationN)rI   rJ   rK   rL   r  r  r   r   r   r   r  N  s    1r  __main__)NT)6r  Zunittestsysr4  rD   r   r   Zpygame.localsr   Zpygame.testsr   Zpygame.mathr   r   r   rg  r  re  r  r(   r+   r-   r2   r?   rG   rH   ZTestCaserN   ra   rb   r6  r9  rH  r  r  r*  r,  r`  r  r  r  r  r  r  r  r  r4  r5  rd  re  r  r  rI   mainr   r   r   r   <module>   s    	
       `-    =     H   c     g
         x      8    T
b