U
‚ü^z  ã                   @   sn   d dl Zd dlm  mZ d dlZd dlZd dlZd dl	m
Z
mZmZ e
dd„ ƒZdd„ Zdd„ Zd	d
„ ZdS )é    N)ÚretryÚMaxRetriesExceptionÚMAX_RETRIESc                 C   s*   t  | d¡}tdd„ |D ƒƒs&tdƒ‚dS )z\Give a list of items pick 2 random ones,
       if both are not ints raise a ValueError
    é   c                 s   s   | ]}t |ƒtkV  qd S )N)ÚtypeÚint)Ú.0Úi© r
   ú8/home/feoh/src/personal/bitesofpy/211/test_decorators.pyÚ	<genexpr>   s     z"get_two_numbers.<locals>.<genexpr>únot all intsN)ÚrandomÚsampleÚallÚ
ValueError)ÚnumbersZchosenr
   r
   r   Úget_two_numbers   s    r   c              	   C   sò   t  t¡ tddgƒ W 5 Q R X |  ¡ d }|j}d}||ƒ}|tk}|sÞt d|fd|tf¡dt	 
¡ ksvt |¡r€t |¡ndt |¡t |¡t |¡dt	 
¡ ks°t t¡rºt t¡ndd	œ }d
d|i }tt |¡ƒ‚d  } } }}d S )NÚaÚbr   r   ©ú==)zK%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.count
}(%(py4)s)
} == %(py8)sÚoutputr   )Úpy0Úpy2Úpy4Úpy6Zpy8zassert %(py10)sZpy10)ÚpytestÚraisesr   r   Ú
readouterrÚcountr   Ú
@pytest_arÚ_call_reprcompareÚ@py_builtinsÚlocalsÚ_should_repr_global_nameÚ	_safereprÚAssertionErrorÚ_format_explanation)Úcapfdr   Ú@py_assert1Ú@py_assert3Ú@py_assert5Ú@py_assert7Z@py_format9Z@py_format11r
   r
   r   Ú'test_bad_data_max_retries_and_exception   s         x   r.   c           	      C   sÌ   t dddgƒ |  ¡ d }|j}d}||ƒ}d}||k}|s´t d|fd||f¡dt ¡ ksft |¡rpt |¡ndt |¡t |¡t |¡t |¡d	œ }d
d|i }t	t 
|¡ƒ‚d  } } } }}d S )Né   r   é   r   r   r   )zK%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.count
}(%(py4)s)
} == %(py9)sr   )r   r   r   r   Zpy9zassert %(py11)sZpy11)r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   )	r)   r   r*   r+   r,   Z@py_assert8r-   Z@py_format10Z@py_format12r
   r
   r   Ú(test_good_data_no_retry_and_no_exception   s          ^   r1   c                 C   s.  t j}d }||k	}|svt d|fd||f¡dt ¡ ks@t |¡rJt |¡ndt |¡dœ }dd|i }tt 	|¡ƒ‚d  }}d}d}t
j}|› d	|› }|||ƒ}	|	sd
dt ¡ ksÂt t
¡rÌt t
¡ndt |¡t |¡dt ¡ ksôt |¡rþt |¡ndt |	¡dœ }
tt 	|
¡ƒ‚d  } }}	d S )N)úis not)z%(py0)s is not %(py3)sÚ	docstring)r   Zpy3zassert %(py5)sÚpy5z(Give a list of items pick 2 random ones,z'if both are not ints raise a ValueErrorz\s+zQassert %(py7)s
{%(py7)s = %(py2)s
{%(py2)s = %(py0)s.search
}(%(py4)s, %(py5)s)
}Úre)r   r   r   r4   Zpy7)r   Ú__doc__r!   r"   r#   r$   r%   r&   r'   r(   r5   Úsearch)r)   r3   Z@py_assert2r*   Z@py_format4Z@py_format6Zline1Zline2r+   Z@py_assert6Z@py_format8r
   r
   r   Ú+test_decorated_function_preserves_docstring"   s"       F     
  f  r8   )Úbuiltinsr#   Ú_pytest.assertion.rewriteÚ	assertionÚrewriter!   r   r5   r   Z
decoratorsr   r   r   r   r.   r1   r8   r
   r
   r
   r   Ú<module>   s     
	